Skip to main content

SmartApp SDK - Java (Preview)

caution

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.

tip

Find the SmartApp SDK - Java in the SmartThings GitHub repository.

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.

To learn more about SmartApps, visit the SmartApp developer documentation section.

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.

Learn more about choosing the best hosting option for your SmartApp here.

Declaring Your SmartApp#

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

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()))
}
}
}

Modules and Extension Libraries#

The SmartApp SDK includes a number of modules and extension libraries to enable and enhance functionality.

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:

<dependency>
<groupId>com.smartthings.sdk</groupId>
<artifactId>smartapp-core</artifactId>
<version>0.0.4-PREVIEW</version>
<type>pom</type>
</dependency>

The artifacts can also be downloaded directly from Maven Central.

Examples#

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

  • kotlin-smartapp: this Kotlin example implements the Java smartapp-core library with a simple Ktor server.
  • java-ratpack-guice-smartapp: this Java example implements the Java smartapp-core library with a Ratpack server and uses Guice for dependency management.
  • java-springboot-smartapp: this Java example implements the Java smartapp-core library using Spring Boot.
  • java-lambda-smartapp: this Java example implements the Java smartapp-core library as an AWS Lambda.