Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SmartApp_DynamicInputsPersistance
'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("selectionWithConditions")
.configureI18n() // Language file in ./locales folder
.permissions([
"r:locations:*",
"r:devices:*",
"x:devices:*"
])
.page('mainPage', (context, page, configData) => {
page.section('mainSwitches', section => {
section.deviceSetting('mSwitches').capability("switch").multiple(true).submitOnChange(true);
});
if(context.config.mSwitches){
let arrayDevL=context.config.mSwitches.length
console.log("arrayDevL ",context.config.mSwitches)
for(let i=0;i<arrayDevL;i++){
let label=context.config.mSwitches[i].deviceConfig.deviceId
page.section(`switch${i}`, section => {
section.deviceSetting('childSwitches'+i).capability("switch").multiple(true).required(true).description("For device "+label)
section.booleanSetting('customBehavior'+i).defaultValue(true).required(true).description("For device "+label)
});
}
}
})
.updated(async (context, updateData) => {
});
/* 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