One stop shop for all things Node.js related work...
Details are missing, but the project should be self-explanatory (under-work). 😶
SmartThings (SmartApp)
At the very least this is to help give more examples on how to use the SmartThings ecosystem.
- Create your environment variables in
environment.json
- This file is ignored by git to protect secrets
- In
configuration/
, copy the fileenvironment.example.json
and rename toenvironment.json
- Shell command:
cp configuration/environment.example.json environment.json
- Shell command:
- MongoDB
- Install MongoDB globally
- macOS:
brew install mongodb
- macOS:
- Remember: you can run the database with the
npm
script:npm run start-db
- Install MongoDB globally
- Ngrok
- Enter your auth token to allow custom domains. If you have Ngrok installed and configured, you may find the auth token in your configuration file at
~/.ngrok2/ngrok.yml
- Ensure no other instances are running - see potential startup issues
- Enter your auth token to allow custom domains. If you have Ngrok installed and configured, you may find the auth token in your configuration file at
- OpenWeatherMap
- Add your API key to
configuration/environment.json
~ST.WEATHER_API_KEY
- Add your API key to
- SmartThings Developer Workspace
- Create an Automation
- Apply appropriate permission scopes
- NOTE: if you have ran this application prior to December 2018, you will need to remove references to deprecated permissions, such as
schedules
, which are no longer required. Automation apps created after this period will not be allowed to use those scopes but your code may still reference it.
- NOTE: if you have ran this application prior to December 2018, you will need to remove references to deprecated permissions, such as
- Enter your webhook URL from the console output (should end with path
/st
so thePOST
requests can be routed to the SmartThings request handler) - Before saving, run the app (see Run below) so the app can respond to PING lifecycle requests.
- Upon successful saving, copy and paste the values into your app:
- Public key ->
controllers/st/data/smartthings_rsa.pub
- Client ID ->
configuration/environment.json
~ST.CLIENT_ID
- Client Secret ->
configuration/environment.json
~ST.CLIENT_SECRET
- Public key ->
- Apply appropriate permission scopes
- Create an Automation
- Ensure your MongoDB instance is running
- Dev:
npm run start-db
- Dev:
- Start the application
- Dev:
node server.js
, ornpm start
- Daemon:
pm2 start ./pm2.config.js
- Dev:
./controllers/st/*
- Weather Light Indicator:
./controllers/st/weatherlight.js
- Security System (self-monitored by email/text ssmtp) ):
./controllers/st/security.js
- Logger (store device states to MongoDB):
./controllers/st/logger.js
- Changes (armed/disarmed de/activations):
./controllers/st/changes.js
You may already have an instance of Ngrok running somewhere else. This error will happen because each instance starts a web inspector at localhost:4040
. You can A) shut down that instance, or B), disable the inspector by configuring the option in code:
server.js
:
ngrok.connect({ inspect: false })
Using the Developer Workspace tool Live Logging, you can see all events flowing into your instance -- including errors that are never bubbled up to the mobile app's user interface.
NOTE: You will only be able to see your own account's events for security purposes
Example event including a potential error:
INSTALLED_APP_LIFECYCLE_EVENT
{"eventTime":1547063745012,"eventType":"INSTALLED_APP_LIFECYCLE_EVENT","installedAppLifecycleEvent":{"locationId":"SOMEUUID","installedAppId":"SOMEUUID","appId":"SOMEUUID","lifecycle":"OTHER","other":{},"error":{"code":"ConstraintViolationError","message":"The request is malformed.","target":"","details":[{"code":"UnsupportedPermissionRequestedError","message":"The requested permission is not supported by the backing App's OAuth Client.","target":"config.app.configEntry.permissionConfig.permission(r:schedules)","details":[]},{"code":"UnsupportedPermissionRequestedError","message":"The requested permission is not supported by the backing App's OAuth Client.","target":"config.app.configEntry.permissionConfig.permission(w:schedules)","details":[]}]}}}
Use Amazon Alexa to setup and run routines such as "Alexa, security disable" (when arrive home turns on configured switch) or "Alexa, security enable" (when leaving to turn off switch)