Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SmartApp_securityStateSubscription
'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