diff --git a/dim-with-me.app.groovy b/dim-with-me.app.groovy index 5d254ee..f59a24c 100644 --- a/dim-with-me.app.groovy +++ b/dim-with-me.app.groovy @@ -12,7 +12,7 @@ * twack@wackware.net * Date: 2013-11-12 * Version: 0.2 - * + * * Use this program with a virtual dimmer as the master for best results. * * This app lets the user select from a list of dimmers to act as a triggering @@ -31,10 +31,14 @@ * added subscription to switch.level event. Shouldn't change much * but some devices only sending level event and not setLevel. * + * Change 3: 2017-11-16 (chalford) + * Added subscription to "level" event, as that is the attribute + * name of the Switch Level Capability. Also reorganised subscriptions. + * ****************************************************************************** - + Other Info: Special thanks to Danny Kleinman at ST for helping me get the - state stuff figured out. The Android state filtering had me + state stuff figured out. The Android state filtering had me stumped. * ****************************************************************************** @@ -53,49 +57,56 @@ definition( ) preferences { - section("When this...") { - input "masters", "capability.switchLevel", - multiple: false, - title: "Master Dimmer Switch...", + section("When this...") { + input "masters", "capability.switchLevel", + multiple: false, + title: "Master Dimmer Switch...", required: true } section("Then these will follow with on/off...") { - input "slaves2", "capability.switch", - multiple: true, - title: "Slave On/Off Switch(es)...", + input "slaves2", "capability.switch", + multiple: true, + title: "Slave On/Off Switch(es)...", required: false } - + section("And these will follow with dimming level...") { - input "slaves", "capability.switchLevel", - multiple: true, - title: "Slave Dimmer Switch(es)...", + input "slaves", "capability.switchLevel", + multiple: true, + title: "Slave Dimmer Switch(es)...", required: true } } def installed() { - subscribe(masters, "switch.on", switchOnHandler) - subscribe(masters, "switch.off", switchOffHandler) - subscribe(masters, "switch.setLevel", switchSetLevelHandler) - subscribe(masters, "switch", switchSetLevelHandler) + initializeSubscriptions() } def updated() { unsubscribe() + initializeSubscriptions() +} + +def uninstalled() +{ + unsubscribe() +} + +def initializeSubscriptions() +{ subscribe(masters, "switch.on", switchOnHandler) subscribe(masters, "switch.off", switchOffHandler) subscribe(masters, "switch.setLevel", switchSetLevelHandler) - subscribe(masters, "switch", switchSetLevelHandler) - log.info "subscribed to all of switches events" + subscribe(masters, "level", switchSetLevelHandler) + log.info "subscribed to switch events" } def switchSetLevelHandler(evt) -{ - +{ + if ((evt.value == "on") || (evt.value == "off" )) return def level = evt.value.toFloat()