SmartThings SmartApp: Set the color of a light based on the weather.
This sample WebHook SmartApp demonstrates the use of the new SmartThings API for Automation.
This WebHook SmartApp showcases:
- App installation and configuration flow.
- HTTP Signature verification to ensure that the incoming requests are from SmartThings.
- Integrating with a third-party API (Weather API in this case).
- Actuating devices using the SmartThings API.
- Creating schedules and handling scheduled executions.
- Node.js and npm installed (verified with npm version 4.0.5 and Node 7.4.0).
- ngrok installed to create a secure tunnel to create a globally available URL for fast testing.
- A Samsung account and the SmartThings mobile application.
- A SmartThings-compatible color bulb, such as SYLVANIA Smart RGBW or LIFX, or Phillips Hue.
- Make sure you open an account (it is free) on Developer Workspace.
Clone or download this repository.
Create an API key with Open Weather Map (free tier is fine), and store it in an environment variable named
Install the dependencies for this app:
Start the server:
Start ngrok (in another terminal window/tab):
ngrok http 3005. Copy the
https:URL to your clipboard.
Go to the Automation section of the Developer Workspace and create an Automation.
- For the SmartApp Type select WebHook endpoint and enter the https URL you copied from the above step.
- For the Scope, click on Settings and select the following scopes:
- Click SAVE AND NEXT.
- In the next screen you will be presented with the Public Key.
Copy this public key and replace the contents of the file
Click CONFIRM to register your automation in self-publishing mode.
Install the SmartApp in the SmartThings mobile app (go to Marketplace->SmartApps->My Apps->Example Weather Color Light.
Enter all required inputs on the configuration screens.
Once installed, the configured bulb will turn on and its color will either be purple (if precipitation is in the forecast), orange (if the forecast calls for temperatures above 80 degrees Fahrenheit), blue (if the forecast calls for temperatures below 50 degrees Fahrenheit), or white (if no precipitation and temperature between 50 and 80 degrees Fahrenheit). It will check the current weather at the interval set during installation.
- When you try to install the SmartApp in the SmartThings mobile app if you get an error Something went wrong. Please try to install the SmartApp again, then it is possible that you did not restart the npm server as specified in Step 10 above. If this is the case, then in the npm server terminal you will also see this error:
forbidden - failed verifySignature. Make sure you restart the npm server by doing Step 10 above.
- Documentation for developing SmartApps can be found on the new SmartThings developer portal.
- SmartThings API reference documentation
The concept of a SmartThings-connected color bulb that changes its color based upon weather or other environmental data is not new or original to this example. The SmartThings Community has created several similar solutions, including: