I’m trying to write an app so that a light switch already in the “off” position will trigger a different event if the “off” button is pressed again. Having the ability to toggle on / off is fine, but the added value of having an button press “on” when already in an on state - or “off” when already in an off state would greatly extend the usefulness of these switches.
…and it seems the log.debug is only returning toggled values (meaning it won’t print “off” if the light is already off). Is this a hardware limitation? Does my standard Jasco switch not send that additional event? Is this a limitation in the ST implementation? Or am I totally messing something up here?
If you wanted to create you own event types, you could create you own device type with your own “off” or “on” handler code that creates it’s own event types. Something like:
I think I spoke too soon. I’m subscribing to a standard switch. As I want to trigger events when an “off” command is sent to a switch already in the “off” position, I’ve used the filterEvents: false flag. Everything appeared fine at first.
However, after a few minutes, the light starts toggling on and off. It seems this triggered with no interaction from the switch. I suppose it’s being polled or something - and the filterEvents is falsely indicating it as an event. Very strange - and with the lack of documentation, a bit frustrating.
This is the distillation of the code being used:
preferences {
section("Turn on with which switch?") {
input "wallSwitch", "capability.switch"
}
}
def installed() {
subscribe(wallSwitch, "switch", changeLights, [filterEvents: false])
}
def changeLights(evt) {
log.debug(evt.value)
}
Leaving the app editor open with a console, I see a report of “debug: off”, even though the switch was not touched.
These are the events that have fired without interaction in my last bit of testing:
9:08:26 PM: info Toggle lights off
9:03:08 PM: info Toggle lights on
8:58:03 PM: info Toggle lights off
8:53:32 PM: info Toggle lights on
8:48:10 PM: info Toggle lights off
Looks like a cadence of 5 minutes +/- a few seconds, so it seems there’s something polling that fires the event if filterEvents: false is set. Sure hoping there’s another value one can set the filterEvents flag to that ignores those polls. Having a hard time figuring out how to get around it for my use-case as I cannot differentiate these garbage events from real ones.
Your code will pick up on “poll” and “refresh”, not just on “on” or “off”.
is this what you’re looking for something to do?
preferences {
section("Turn on with which switch(es)?") {
input "masters", "capability.switch"
}
}
def installed()
{
subscribe(masters, "switch.on", switchHandler) //I wanna know when master goes on
subscribe(masters, "switch.off", switchHandler) //and I wanna know when master goes on
}
def updated()
{
unsubscribe()
subscribe(masters, "switch.on", switchHandler) //I wanna know when master goes on
subscribe(masters, "switch.off", switchHandler) //and I wanna know when master goes on
}
def switchHandler(evt) {
log.info "switchHandler Event Value: ${evt.value}" // which event fired is here
log.info "switchHandler Event Name: ${evt.name}" // name of device firing it here
}
I still need the filterEvents: false, as I’m listening to an “off” event when the switch is already in an “off” state - but I think the filter of switch.off might be working (leaving lamp on to see if it decides to start toggling with poll events). Updating the github repo if you’re curious.
…and it looks like this is still firing the poll events: subscribe(wallSwitch, "switch.off", doubleSwitch, [filterEvents: false])
Thinking this may not be doable.
My understanding of double tap is that it’s two similar commands in quick succession (“off, wait a second, off again”). What I’m trying to do is basically the same minus the requirement of the quick succession.
The use case is having a switch that is at the convergence of a hallway and living room. I want the one switch to control both the hall lights and the living room lights. If I turn the switch on - both sets of lights turn on. Turn it off, both sets of lights turn off. The part I’m trying to add now is that if the light is off, I’d like to be able - at any time - to click “off” (when the light is already off) and have it toggle only the living room light.
look at the double tap app code that is on the IDE already. See how it is checking for the event to be from the physical device? It does check to see if the tap was recent though. You just need to remove the check for being a recent evt.
Aha! I think that might have done it. I didn’t realize there was a “isPhysical()” method on events. I’ve had my lamp running for maybe 30 minutes without issue. Here’s hoping that solved it. I’ve updated the github code to reflect the changes. I’ll probably add a counter-action for clicking “on” when already “on”.
The event documentation found at: https://graph.api.smartthings.com/ide/doc/event is pretty good. If you’re pretty new to programming it might be somewhat obtuse without good sample applications/usage cases. You might try making a copy of a simple app that works and just test all of the different commands/methods by writing their returns out to a log.
Anyway, glad you’re making progress on your app.
Twack