You develop a SmartThings SmartApp either to integrate a third-party Cloud-to-Cloud device into the SmartThings cloud, or to create an automation. You can combine both the automation and the device integration in a single SmartApp, or you can create them in separate SmartApps.
The basic concept of a SmartApp is as follows:
- The SmartApp can either be an AWS Lambda function, or a webhook with a RESTful API interface.
- A webhook in this context is a web services application, that is, an API endpoint on the internet, which can receive incoming HTTP POST requests. You can write and host your application / API endpoint using the language and the tools of your choice.
- To publish your application, you must register your webhook or Lambda function on the SmartThings development portal.
- Next you will need to implement lifecycle event handlers in your webhook or Lambda function to complete the integration. And you will also need to implement the event handlers for the device events from the device cloud.
- When the integration is complete, your SmartApp will begin a lifecycle, and will interact with the SmartThings cloud on a lifecycle phase-basis.
A SmartApp comes to exist when it is successfully registered in the SmartThings cloud, and continues its life until it is uninstalled by the end-user. Throughout its lifecycle, the SmartApp is called by the SmartThings cloud during specific lifecycle phases. The SmartApp, in turn, can call into the SmartThings RESTful API.
For example, consider an automation SmartApp. When the end-user configures the automation to monitor an open/close sensor, the automation subscribes to open/close sensor events. The SmartThings cloud waits on these open/close sensor events. Anytime an open/close event occurs, it is first noticed by the SmartThings cloud, which then calls back the automation SmartApp.
In this way, the SmartThings cloud is constantly listening to the automation-specific lifecycle events generated in the SmartThings cloud, and is making RESTful calls to the automation, always associating each call with a particular lifecycle phase.
Similarly, consider a Cloud-to-Cloud device integration, for example, for a LIFX bulb. With this integration the LIFX bulb will appear in the end-user’s Samsung Connect app / SmartThings mobile app. The end-user can then view and actuate this LIFX bulb from an Automation within the Samsung Connect app / SmartThings mobile app. For example, when the end-user turns on the LIFX bulb in the mobile app, the SmartThings cloud notices this device command, and calls the SmartApp with the device command. The SmartApp then relays this device command to the LIFX cloud, which then sends the
on command to the LIFX bulb, and the user’s mobile app is updated.
In addition to the lifecycle event handlers for the SmartThings cloud, a SmartApp can contain other functionality. For example it can interface with a third-party service, or it can define its own user interface.