modifyConfigParamsSmartApp
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
//Function called when the command of the Custom Capability is executed (from the app, API or SmartApp) | |
def setAttr(String arg){ | |
log.trace("attr ${arg}") | |
sendEvent(name:"attr",value:arg) | |
state.configValue = 0 | |
switch(arg){ | |
case 'option1': | |
state.configValue= 20 | |
break; | |
case 'option2': | |
state.configValue= 30 | |
break; | |
case 'option3': | |
state.configValue= 40 | |
break; | |
} | |
} | |
//Send the config parameter in the wakeUp notification because sleepy devices don't receive them unless they're awake | |
def zwaveEvent(physicalgraph.zwave.commands.wakeupv2.WakeUpNotification cmd) { | |
log.trace("WakeUpNotification") | |
def cmds = [] | |
//... | |
if(state.configValue!=0){ | |
//this parameter is for the clear motion time (unit:seconds) | |
cmds += secure(zwave.configurationV1.configurationSet(parameterNumber: 2, size: 2, scaledConfigurationValue: state.configValue)) | |
} | |
cmds += secure(zwave.wakeUpV2.wakeUpNoMoreInformation()) | |
[result, response(cmds)] | |
} |
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 */ | |
app.enableEventLogging(2) // Log and pretty-print all lifecycle events and responses | |
.configureI18n() // Use files from locales directory for configuration page localization | |
.page('mainPage', (context, page, configData) => { | |
page.section('sensors',section => { | |
section.deviceSetting('switchd').capabilities(['switch']).permissions(['r','w','x']).required(false); | |
section.deviceSetting('sensor').capabilities(['motionSensor']).permissions(['r','w','x']).required(false); | |
}) | |
}) | |
.updated(async (context, updateData) => { | |
await context.api.subscriptions.unsubscribeAll(); | |
return Promise.all([ | |
context.api.subscriptions.subscribeToDevices(context.config.switchd, 'switch', 'switch.on', 'openDeviceEventHandler') | |
]) | |
}) | |
.subscribedEventHandler('openDeviceEventHandler', (context, deviceEvent) => { | |
let commandP = { | |
capability: "xxx.listExample", | |
command: "setAttr", | |
arguments: ["option1"], | |
} | |
return context.api.devices.sendCommands(context.config.sensor, [commandP]); | |
}); | |
/* 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