Skip to content

Instantly share code, notes, and snippets.

@mckeed
Created January 16, 2014 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mckeed/8450055 to your computer and use it in GitHub Desktop.
Save mckeed/8450055 to your computer and use it in GitHub Desktop.
Toggle Button SmartApp to toggle a switch when you press a button on an Aeon remote control.
preferences {
section("When I push a button on this remote") {
input "button", "capability.button", title: "Button"
}
section("Which button:") {
input "whichButton", "number", defaultValue:1
}
section("Toggle these switches") {
input "switches", "capability.switch", multiple: true, required: false
}
section("Turn off these switches") {
input "offSwitches", "capability.switch", multiple: true, required: false
}
section("Turn on these switches") {
input "onSwitches", "capability.switch", multiple: true, required: false
}
}
def subscribeToEvents()
{
subscribe(button, "button.pushed", pushHandler)
}
def installed()
{
subscribeToEvents()
}
def updated()
{
unsubscribe()
subscribeToEvents()
}
def pushHandler(evt) {
if (evt.data.contains(whichButton.toString())) {
// log.debug evt.value
onSwitches?.on()
offSwitches?.off()
switches.collect{ d ->
log.debug "${d.displayName} is ${d.currentSwitch}"
if(d.currentSwitch == "on") d.off()
else d.on()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment