Giter VIP home page Giter VIP logo

weather-color-light-smartapp-nodejs's Introduction

Set the color of a light based on the weather.

This example Lambda SmartApp demonstrates the use of SmartThings APIs via the SmartApp NodeJS SDK to achieve an Automation.

It showcases:

  • App installation and configuration flow.
  • Integrating with a third-party API (OpenWeather).
  • Actuating devices using the SmartThings API.
  • Creating schedules and handling scheduled executions.

Setup instructions

Prerequisites

  • An AWS account (free tier is fine).
  • An OpenWeather account (free tier is fine).
  • A Samsung account and the SmartThings mobile application.
  • A Developer Workspace account.
  • A SmartThings compatible color bulb, such as SYLVANIA Smart RGBW, LIFX, or Phillips Hue.

If testing locally (using provided webserver)

  • Node.js and npm installed (verified with npm version 6.14.8 and Node 12.19.0).
  • ngrok installed to create a secure tunnel and create a globally available URL for fast testing.

Start

We've provided two options: the intended deployment platform for this automation (AWS Lambda) and a simple web server that can be used to run and test locally. In either case, first create an API key at OpenWeather. We will use this in both options below.

Clone or download this repository and follow the desired option.

Lambda

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

  2. Follow the instructions to setup AWS credentials for serverless.

  3. Deploy the Lambda function: serverless deploy.

  4. Navigate to the AWS Lambda dashboard to add an env var with the key WEATHER_API_KEY and the value as the API key you created at OpenWeather.

  5. Follow the steps to grant SmartThings permission to execute your Lambda function. This is required for successful registration.

Local

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

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

  3. Start the server: npm start.

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

Register

Follow the instructions for registering a SmartApp with the SmartThings platform.

  • The following OAuth2 scopes are required.
    • r:devices:*
    • x:devices:*

Local Only

A CONFIRMATION request log should show in the log output of the local server once registered. Navigate to this link to verify your domain ownership and enable the app to receive events. This is required for successful installation.

Test

Follow the instructions for testing a SmartApp.

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 forecast at the interval set during installation.

Troubleshooting

Local

  • When installing 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 navigate to the confirmation link as specified above. If this is the case, then in the npm server terminal you will also see an error. Make sure you navigate to the URL sent with the CONFIRMATION request to the npm server. This can be resent by navigating to Developer Workspace Overview and clicking Verify App Registration.

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 in the past, including:

weather-color-light-smartapp-nodejs's People

Contributors

bflorian avatar chetstone avatar dependabot[bot] avatar erickvneri avatar erodewald avatar jimmyjames avatar jodyalbritton avatar john-u avatar mrobinet avatar rossiam avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.