All Projects → SmartThingsCommunity → smartapp-sdk-java

SmartThingsCommunity / smartapp-sdk-java

Licence: Apache-2.0 License
A collection of consumer-oriented Java (JVM) libraries for creating SmartApps and using the public API

Programming Languages

java
68154 projects - #9 most used programming language
groovy
2714 projects

Projects that are alternatives of or similar to smartapp-sdk-java

SmartThings-VirtualThermostat-WithDTH
Virtual Thermostat Device with Device Type Hander to create a proper thermostat device (Works With Google Home and Alexa)
Stars: ✭ 33 (-21.43%)
Mutual labels:  smartthings, smartapp
gosmart
A Go (golang) library to interface with the Samsung SmartThings API.
Stars: ✭ 14 (-66.67%)
Mutual labels:  smartthings, smartthings-api
Smartthingspublic
SmartThings open-source DeviceTypeHandlers and SmartApps code
Stars: ✭ 2,201 (+5140.48%)
Mutual labels:  smartthings, smartapp
APSoft-Web-Scanner-v2
Powerful dork searcher and vulnerability scanner for windows platform
Stars: ✭ 96 (+128.57%)
Mutual labels:  smartthings
Smartthings
Custom DTHs for Smartthings
Stars: ✭ 44 (+4.76%)
Mutual labels:  smartthings
SmartThings
No description or website provided.
Stars: ✭ 29 (-30.95%)
Mutual labels:  smartthings
SmartLEDLamp
A smart, web-enabled floor lamp with nice visual effects based on IKEA Vidja powered by ESP8266 and WS2801.
Stars: ✭ 22 (-47.62%)
Mutual labels:  smartthings
cbj smart-home
🏡 If you are searching for an easy way to connect all your smart home devices with one app CyBear Jinni 🦾🐼🧞‍♂️ is here for you. Join the community and make your home smarter than yesterday.
Stars: ✭ 40 (-4.76%)
Mutual labels:  smartthings
IoTBench-test-suite
A micro-benchmark suite to assess the effectiveness of tools designed for IoT apps
Stars: ✭ 59 (+40.48%)
Mutual labels:  smartthings
OmniLinkBridge
MQTT bridge, web service API, time sync, and logging for HAI/Leviton OmniPro II controllers
Stars: ✭ 34 (-19.05%)
Mutual labels:  smartthings
ha-samsungtv-smart
📺 Home Assistant SamsungTV Smart Component with simplified SmartThings API Support configurable from User Interface.
Stars: ✭ 240 (+471.43%)
Mutual labels:  smartthings
device-type.myneurio
SmartThings-Neurio integration
Stars: ✭ 17 (-59.52%)
Mutual labels:  smartthings
node-red-contrib-smartthings
Allows you to control your devices and get their status using NodeRed
Stars: ✭ 30 (-28.57%)
Mutual labels:  smartthings
DSC-Integration-with-Arduino-Mega-Shield-RS-232
DSC - Integration with SmartThings (RS232)
Stars: ✭ 17 (-59.52%)
Mutual labels:  smartthings
RyobiGDO
Device Type Handler and Node.js Proxy Service for Smartthings
Stars: ✭ 17 (-59.52%)
Mutual labels:  smartthings

Archived

This SDK is no longer being maintained and should not be chosen for new projects.

SmartThings SmartApp SDK Java (Preview) SmartThings Java

Known Vulnerabilities

Welcome! This SDK is currently in preview and is not recommended for use in production applications at this time. We welcome your bug reports, feature requests, and contributions.

Getting Started

This SDK includes a set of JVM libraries for building Webhook and AWS Lambda SmartApps, and interacting with the public SmartThings API.

Prerequisites

  • Java 1.8+
  • A Samsung account

What is a SmartApp?

SmartApps are custom applications that execute outside of the SmartThings Platform. All of the SmartApp execution will happen on the server or Lambda that you control. The complexity of execution and the number of expected users will need to be examined to understand the hardware or execution requirements your app needs to handle. Your application will respond to lifecycle events sent from SmartThings to perform actions on behalf of your users and will execute any scheduled tasks that you have created in the SmartApp. Creating a SmartApp allows you to control and get status notifications from SmartThings devices using the SmartThings API.

Visit the SmartThings developer documentation to earn more about SmartApps.

Hosting Your SmartApp

There are two distinct options for hosting your SmartApp: AWS Lambda and Webhook.

Webhook SmartApps are any publicly-accessible web server that will receive a POST request payload.

AWS Lambda SmartApps are hosted in the Amazon Web Services cloud and are invoked by ARN instead of a public-DNS address.

The best hosting option for your Automation depends on a number of factors, both objective and subjective.

To learn more about SmartApps, including choosing the best hosting option for your SmartApp, visit the SmartThings developer documentation.

Declaring Your SmartApp

Take a quick look at how SmartApps are declared in various languages.

Kotlin
package app

val smartApp: SmartApp = SmartApp.of { spec ->
    spec
        .configuration(Configuration())
        .install {
            Response.ok(InstallResponseData())
        }
        .update {
            Response.ok(UpdateResponseData())
        }
        .event {
            Response.ok(EventResponseData())
        }
        .uninstall {
            Response.ok(UninstallResponseData())
        }
}

fun Application.main() {
    install(Routing) {
        post("/smartapp") {
            call.respond(smartApp.execute(call.receive()))
        }
    }
}
Groovy
    SmartApp smartApp = SmartApp.of { spec ->
        spec
            .install({ req ->
                // create subscriptions
                Response.ok()
            })
            .update({ req ->
                // delete subscriptions
                // create subscriptions
                Response.ok()
            })
            .configuration({ req ->
                ConfigurationResponseData data = ...// build config
                Response.ok(data)
            })
            .event(EventHandler.of { eventSpec ->
                eventSpec
                    .onSubscription("switch", { event ->
                       // do something
                    })
                    .onSchedule("nightly", { event ->
                       // do something
                    })
                    .onEvent(
                        { event ->
                            // test event
                            true
                        },
                        { event ->
                            // do something
                        }
                    )
            })
    }
Java
    private final SmartApp smartApp = SmartApp.of(spec ->
        spec
            .install(request -> {
                return Response.ok();
            })
            .update(request -> {
                return Response.ok(UpdateResponseData.newInstance());
            })
            .configuration(request -> {
                return Response.ok(ConfigurationReponseData.newInstance());
            })
            .event(request -> {
                EventData eventData = request.getEventData();
                EventHandler.of(eventSpec ->
                        eventSpec
                                .onEvent(event -> {
                                    // when this predicate is true...
                                    return true;
                                }, event -> {
                                    // ...do something with event
                                })
                                .onSchedule("nightly", event -> {
                                    // do something
                                })
                                .onSubscription("switch", event -> {
                                    // do something
                                })
                );
                return Response.ok(EventResponseData.newInstance());
            })
        );

Modules and Extension Libraries

Modules

  • The smartapp-core module provides the core SmartApp framework, enabling you to define a SmartApp that can be used in many different environments including AWS Lambda, Dropwizard, Ratpack, and more.

  • The smartthings-client module is an API library that provides useful utilities for working with the Subscription, Schedules, and Device APIs.

Extension Libraries

Adding the SDK to your build

Several artifacts are published to the Maven central repository under the com.smartthings.sdk group.

  • smartapp-core - Core SmartApp Framework
    • smartapp-guice - Extension library for use with Google Guice
    • smartapp-spring - Extension library for use with Spring Dependency Injection
    • smartapp-contextstore-dynamodb - Extension library to use DynamoDB to store installed application context data.
  • smartthings-client - Library for working with SmartThings APIs

Import the library dependencies as needed:

Apache Maven
<dependency>
  <groupId>com.smartthings.sdk</groupId>
  <artifactId>smartapp-core</artifactId>
  <version>0.0.4-PREVIEW</version>
  <type>pom</type>
</dependency>
Gradle Groovy DSL
implementation 'com.smartthings.sdk:smartapp-core:0.0.4-PREVIEW'

If you prefer, the artifacts can be downloaded directly from Maven Central.

Examples

Several simple, runnable examples of using the SDK are included in the examples directory.

kotlin-smartapp (Documentation) kotlin-logo ktor-logo

This Kotlin example implements the Java smartapp-core library with a simple Ktor server.

java-ratpack-guice-smartapp (Documentation) java-logo ratpack-logo

This Java example implements the Java smartapp-core library with a Ratpack server and uses Guice for dependency management.

java-springboot-smartapp (Documentation) java-logo spring-logo

This Java example implements the Java smartapp-core library using Spring Boot.

java-lambda-smartapp (Documentation) java-logo aws-logo

This Java example implements the Java smartapp-core library as an AWS Lambda.

More about SmartThings

Check out our complete developer documentation here.

To create and manage your services and devices on SmartThings, create an account in the developer workspace.

The SmartThings Community is a good place share and ask questions.

There is also a SmartThings reddit community where you can read and share information.

License and Copyright

Licensed under the Apache License, Version 2.0

Copyright 2019 SmartThings, Inc.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].