Skip to content

chrisbohn1984/weather-color-light-smartapp-nodejs

 
 

Repository files navigation

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.

Setup instructions

Prerequisites

  • 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.

Steps

  1. Clone or download this repository.

  2. Create an API key at Open Weather Map (free tier is fine).

  3. Create a .env and store your API key as shown in .env.example file.

  4. Install the dependencies for this app: npm install.

  5. Start the server: npm start.

  6. Start ngrok (in another terminal window/tab): ngrok http 3005. Copy the https: URL to your clipboard.

  7. At the Developer Workspace create an Automation project.

    • Register your Automation SmartApp as a WebHook with the https: previously copied.
    • From the scopes list, select the next ones:
      • r:devices:*
      • x:devices:*
      • i:deviceprofiles:*
      • r:locations:*
    • Click SAVE AND NEXT.
    • In the next screen you will be presented with the Public Key.
  8. Copy this public key and replace the contents of the file config/smartthings_rsa.pub with it.

  9. Click CONFIRM to register your automation in self-publishing mode.

  10. Install the SmartApp in the SmartThings mobile app (If you're using Classic app: go to Marketplace->SmartApps->My Apps->Example Weather Color Light).

  11. Enter all required inputs on the configuration screens.

  12. 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.

Troubleshooting

  • 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

Credits

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:

About

Source code for an example automation SmartApp used for demos, written in Node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%