This library provides fuctionality for integrating a variety of IoT devices with Dialogflow.
- Nest Camera
- Samsung Smarthings Hub
- Samsung Smarthings Power Outlet
- Silvania Smart Bulb
- Sonos (using Spotify)
- Yale Lock
- Obtain your Personal Access Token (
token
) from https://account.smartthings.com/tokens. - Set the environment variable in your
.env
file for your deployment:smartthings_token="TOKEN"
- Collect the necessary Device Ids (
devices
) from https://api.smartthings.com/v1/devices (called with headerAuthorization: Bearer: token
) and updatesmartthings.js
- Update
colors.js
with your desired color map if you are using the lightbulb
- Obtain the snapshot URL following https://github.com/DecodedCo/decoding-jarvis/blob/webapp/documentation/nest.md
- Set the environment variable in your
.env
file for e.g. camera A:nest_a_uri=""
- Set the environment variables in your
.env
file:spotify_id=""
- Update
spotify.js
with thesid
andsn
intercepted by querying the Sonos device through the smartthings API as it is playing a track from the app.
Some services (Microsoft) cache URLs for their services - they only check the URL once, rather than checking to see if the contents have changed.
To overcome this limitation, you can generate unique URLs that do not affect the underlying request, but do "trick" the API into reloading the contents.
- Make sure you have imported the utilities first:
const utils = require('./utils.js');
- Use the following code for your final response, updating
IMAGEURL
with your image url:
utils.uniqueUrl(IMAGEURL)
e.g.
requestAPI(utils.uniqueUrl("https://URL/"))
Get status and switch on or off:
smartthings.light("switch","status").then(result => {
agent.add(result);
});
smartthings.light("switch","off").then(result => { // or on
agent.add(result);
});
Get current brightness and set the brightness (0-100):
smartthings.light("switchLevel","status").then(result => { // 0-100
agent.add(result);
});
smartthings.light("switchLevel",100).then(result => { // 0-100
agent.add(result);
});
Get current hue and saturation, and set the color based on the mapping in colors.js
:
smartthings.light("colorControl","status").then(result => {
agent.add(result);
});
smartthings.light("colorControl","red").then(result => { // defined in colors.js
agent.add(result);
});
Check the lock status and lock/unlock:
smartthings.lock("status").then(result => {
agent.add(result);
});
smartthings.lock("lock").then(result => { // or unlock
agent.add(result);
});
Check what's currently playing:
smartthings.sonos("status").then(result => {
agent.add(result);
});
Play/pause the current track:
smartthings.sonos("pause").then(result => { // or play
agent.add(result);
});
Set the volume (0-100):
smartthings.sonos("setLevel",60).then(result => { // 0-100
agent.add(result);
});
You can search for a track, artist or album, and pass the result onto Sonos:
spotify.searchv2("The Beatles").then(result => {
smartthings.sonos("playTrack",result).then(result => {
agent.add(result);
});
}).catch( error => {
agent.add(`Whoops - ${error}`);
});
Check status and switch on/off:
smartthings.outlet("status").then(result => {
agent.add(result);
});
smartthings.outlet("off").then(result => { // or on
agent.add(result);
});
Returns URL for most recent image from e.g. camera A:
agent.add(new Image(nest.camera("a")));