Simple Virtual Switch App

I'm just starting out with some virtual switches and trying to learn about them in a very simple app. I have created two of them and at this point, simply want to read event details when they are pressed. After loading and running the following app code, I open "Devices", choose one of the virtual switches listed and press its On button- no event is registered. What concept am I missing?

definition(
    name: "Simple App Example",
    namespace: "anonymous",
    author: "anonymous",
    description: "Whatever",
    category: "Convenience",
    iconUrl: "",
    iconX2Url: "",
    iconX3Url: "")

preferences
{
    section
    {
        input "switchOne", "capability.switch", multiple: false, required: true
        input "switchTwo", "capability.switch", multiple: false, required: true
    }
}

void installed()
{
    updated()
}

void updated()
{
    unsubscribe()
    subscribe(switchOne, "switch.on", oneHandler)
    subscribe(switchTwo, "switch.on", twoHandler)
}

void uninstalled()
{
    unsubscribe()
}

void oneHandler(evt)
{
    log.debug "oneHandler event name is ${evt.name}"
}

void twoHandler(evt)
{
    log.debug "twoHandler event name is ${evt.name}"
}

I don't see anything in your code that looks wrong, and I just installed a copy to test, which also worked for me.

I'd make sure you hit "Done" inside your app (that is when the updated() will run, which is where your subscriptions get created). And while you probably thought of this, I'd also make sure you either didn't choose any mode restrictions (this gets automatically added to single-page apps) or that whatever you've chosen is not in effect.

As one additional troubleshooting step, you can also look at the "App Status" page for your installed app instance (this is the gear-looking icon next to the app in list view or the top right insdie the app). You'll see an "Event Subscriptions" section where you should see both your switches listed with a "switch.on" event subscription--the same devices you see in the "Settings" section above (which shows you the selections from all the inputs in your app).

If this looks correct, to make extra-sure you're manipulating the right devices, you could click into their device pages from here. I'd also make sure that the devices are, in fact, generating events; a virtual device should, but if it's a "real" device, it will likely need to be responsive to network commands and report back to the hub the new state before an event gets generated.

Thanks @bertabcd1234 ! It was a mode restriction- I unwittingly selected Day. When the mode was cleared, all works perfectly.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.