Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 33 additions & 22 deletions dim-with-me.app.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*
******************************************************************************
Expand All @@ -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()
Expand Down