Skip to content

A SmartThings SmartApp based on NodeJS. This SmartApp Adjusts lighting based on cloudiness and time of day.

Notifications You must be signed in to change notification settings

ndiesslin/Environment-Sensitive-Lighting

Repository files navigation

Environment Sensitive Lighting - Lights that adjust based on cloudiness.

The purpose of this repository is to demo the making of a SmartThings SmartApp. The demo will adjust lighting brightness based on the cloudiness outside and the time of day. The user will be able to determine the greatest brightness level.

Use cases

  • Hallway lighting.
  • Kitchen lighting.
  • Outdoor lighting.
  • Adjust the lighting for seasonal affective disorder.

Setup

Prerequisites

  • A SmartThings compatible color light.
  • An OpenWeather account. The free tier will be enough.
  • A Samsung account
  • The SmartThings mobile application, Android or iOS.
  • A SmartThings Developer Workspace account. You can use your Samsung account login for the Developer Workspace.
  • A Heroku account if you want to host this project.
  • Node.js installed.
  • npm installed.
  • ngrok installed. Ngrok will create a secure tunnel to the local node server.

Getting started

Local setup

  • Get an API key from your OpenWeather account.
  • Copy the .env.example file to .env in this project's root directory. You can use this command in the root directory of this project: cp .env.example .env. Replace YOUR_API_KEY_HERE with your open weather API key.
  • Run npm install to install the project dependencies.
  • Start the Node.js server npm run start.
  • Start ngrok ngrok http 3000. Once started, copy and save the "Forwarding" HTTPS URL. This is the URL used in the Developer Workspace.

SmartApp creation

  • Log in to the Developer Workspace.
  • In the Developer Workspace, create a new project.
  • Select "Automation for the SmartThings App" as the project type.
  • Give the project the desired name.
  • Select "Register App" in the created project.
  • Choose "WebHook Endpoint" and enter your ngrok HTTPS URL.
  • Give your SmartApp a name and description.
  • Enable the following OAuth2 scopes under "Permissions required by your connector app."
    • r:devices:*
    • x:devices:*
  • Save the APP.
  • You will not need the Client ID or Secret for this, but you can save it anyways.
  • Click on "VERIFY APP REGISTRATION"; this will send a post to your application with a URL in your logs. Copy this URL and visit it in your browser to verify the connection.
  • After you have verified your app registration, then click on the "Deploy to Test" button.

More information on:

Testing SmartApp on your phone

  • Sign in to the SmartThings app on your smartphone.
  • Make sure you have a SmartLight added in the SmartThings app.
  • IMPORTANT: Enable developer mode in the SmartThings app. Go to the settings menu and hold down on "About SmartThings" for five seconds. After this, you should see an option to enable developer mode. The SmartThings app will need to restart.
  • Open the menu in the SmartThings app and go to SmartApps. Click on the plus sign to add a new SmartApp. If you scroll to the bottom, you should see this app listed under the "Custom" section.
  • Fill in the information in the prompt, then click "done > allow" and you should be able to see this project in action.

More information on:

Deploying as a service

  • Heroku can host this project.
  • Make sure you add the environment variable for the weather API key.
  • Use the URL in your Heroku app for your SmartThings SmartApp. The URL is in the Heroku app settings.
  • To verify your SmartThings SmartApp with Heroku, follow the logs heroku logs --tail.

More information on:

Inspiration

This SmartApp got inspiration from weather-color-light-smartapp-nodejs. A fantastic SmartApp that adjusts lighting color based on the current weather.

About

A SmartThings SmartApp based on NodeJS. This SmartApp Adjusts lighting based on cloudiness and time of day.

Resources

Stars

Watchers

Forks

Packages

No packages published