Can I use a button to toggle a device on and off? Can I use conditions in scenes?

Following on from this ‘desire’ to fix toggle actions, I found this thread with some custom ‘Smart App’ code.

The code as presented in that thread wouldn’t save but once I added ‘author’ and some icon url statements, I got it to save. But when I try to run (use, configure to a light) that SmartApp, it asks me for the ‘button’, and I choose my “Aeon Wallmote”, but it doesn’t ask me which button within the wallmote to use. Using a built-in SmartApp, I am asked to choose the button and when I select the WallMote, it then asks me for the specific button number. I would have thought that part would be outside of my responsibility (to realize this is a multi-button device and thus to ask for specific button).

Any thoughts on what I need to do to fix this? The code looks like this currently (borrowed heavily from the version in the referenced post):

(how do I paste in code? :slight_smile: … I’m familiar with using tags in other forum tools but I don’t see an equivalent here) - GOT IT - just use the good old fashioned ‘code’ tags even though there’s no button at the top for it :slight_smile:

definition(
    name: "Toggle Light Button",
    namespace: "personal",
    description: "This app create a toggle button for light switch",  
    category: "Convenience",
    author: "(me)",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
    iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png"
    )

preferences {
    section("The button that will toggle the light") {
        input "toggleButton", "capability.button", title: "Select", required: true
    }

    section("The switch to be controlled") {
        input "controlledSwitch", "capability.switch", title: "Select", required: true 
    }
}

def installed(){
    subscribe(toggleButton, "button", toggleHandler, [filterEvents: false])
}

def updated(){
    unsubscribe()
    subscribe(toggleButton, "button", toggleHandler, [filterEvents: false])
}

def toggleHandler(evt) {
    if (evt.name == 'button' && evt.value) {
        if (controlledSwitch.latestState("switch").value == "off") {
           controlledSwitch.on()
        } else {
           controlledSwitch.off()
        }
    }
}