This is lambda SmartApp controls Sleep IQ bed to achive atomation. It uses Amazon Cognito as ouath2 server and the README file explains how to set it up There is also a local version for debugging purposes
- Sleeping sensor - the bed knows when you sleep or not, how we can get it in real time
- Alternative UI - i tried several options, for some reason it does not work
- Timer for heater (not super needed, never changed it)
- An AWS account (free tier is fine).
- A Samsung account and the SmartThings mobile application.
- A Developer Workspace account.
- A SleepIQ bed and account
- 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.
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.
Clone or download this repository and follow the desired option.
-
Install the dependencies for this app:
npm install
. -
Follow the instructions to setup AWS credentials for serverless.
-
Edit file my-serverless.yaml in the config directory, use .env.example as an example and add correct values
-
Deploy the Lambda function:
serverless deploy
. -
Navigate to the AWS Lambda dashboard (https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html) make sure all 6 config variables are set.
-
Follow the steps to grant SmartThings permission to execute your Lambda function. This is required for successful registration.
I'm using AWS Cognito as ouath2 provider. Free tier will be enough
- Configure user pool (I'm using name and email)
- Configure app client (nothing fancy)
- In app client settings set callback url to https://c2c-us.smartthings.com/oauth/callback. Set allowed OAuth flows to authorize code grant. Set allowed ouath scope to openid
- Select your domain name
- In the Samsung Workspace set the client id and client secret to the client id and client secret you got in step 2. Set Authorization URI to https://{domain-name-from-step-4}-prod.auth.us-east-1.amazoncognito.com/oauth2/authorize. Set token URI to https://{domain-name-from-step-4}-prod.auth.us-east-1.amazoncognito.com/oauth2/token/ Most importanly setup you OAuth scope ot openid
- I creted to users in the user pool for me and my wife. The emails and names should much the email and name you have in your sleep iq app.
- Download a webtoken file from https://cognito-idp.{region}.amazonaws.com/{userPoolId}/.well-known/jwks.json and save it in config/webtooken.json
-
Create a
.env
and store your SleepIQ email/password as shown in.env.example
file. In addtion set ACCESS_TOKEN_CLIENT_ID=client id you got in Cognito CLIENT_ID=YOUR_CLIENT_ID_FRROM_DEV_WORKSPACE CLIENT_SERCRET=YOUR_CLIENT_SECRET_FROM_DEV_WORKSPACE USER_INFO_ENDPOINT=https://{cognito-domain-name}-prod.auth.{region}.amazoncognito.com/oauth2/userInfo -
Install the dependencies for this app:
npm install
. -
Start the server:
npm start
. -
Start ngrok (in another terminal window/tab):
ngrok http 3005
. Copy thehttps:
URL to your clipboard.
- Follow the instructions for registering a SmartApp with the SmartThings platform.
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.
Follow the instructions for testing a SmartApp.
- 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 WorkspaceOverview
and clickingVerify App Registration
.
- Documentation for developing SmartApps can be found on the SmartThings developer portal.
- SmartThings API reference documentation
- SmartApp API reference documentation
This app is based om the SmartThing example called weather-color-light-smartapp-nodejs