Created
December 8, 2020 14:38
-
-
Save nayelyzarazua-bluetrail/eb6a3a61daabc374144a9caded6fc3c8 to your computer and use it in GitHub Desktop.
SmartApp_securityStateSubscription
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const SmartApp = require('@smartthings/smartapp'); | |
require('dotenv').config(); | |
const server = module.exports = express(); | |
server.use(bodyParser.json()); | |
const app = new SmartApp() | |
/* Handles lifecycle events from SmartThings */ | |
server.post('/', async (req, res) => { | |
app.handleHttpCallback(req, res); | |
}); | |
/* Defines the SmartApp .enableEventLogging() */ | |
app.enableEventLogging() | |
.appId("location-security") | |
.permissions([ | |
"r:locations:*", | |
"r:devices:*", | |
"x:devices:*", | |
"r:security:locations:*:armstate" | |
]) | |
.page('mainPage', (context, page, configData) => { | |
page.section('sensors', section => { | |
//... | |
}); | |
}) | |
.updated(async (context, updateData) => { | |
await context.api.subscriptions.unsubscribeAll(); | |
return Promise.all([ | |
context.api.subscriptions.subscribeToSecuritySystem('securityStateHandler') | |
]) | |
}) | |
.subscribedSecurityArmStateEventHandler('securityStateHandler', (context, secEvent) => { | |
console.log('security event',secEvent) | |
}) | |
/* Starts the server */ | |
let port = process.env.PORT; | |
server.listen(port); | |
console.log(`Open: http://127.0.0.1:${port}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment