Evt.value limitations?


(Im Brian) #1

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.

Long story short, I’m simply doing a:

def installed() {
  subscribe(wallSwitch, "switch", changeLights)
}

def changeLights(evt) {
  log.debug(evt.value)
}

…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?

Thanks!


(Im Brian) #2

Nevermind - here’s the secret sauce if anyone else stumbles across this:

def installed() {
  subscribe(wallSwitch, "switch", changeLights, [filterEvents: false])
}

(Todd Wackford) #3

@ImBrian,

You could also do stuff like this:

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:

def myOnHandler {
  sendEvent(name: "doingMyThing", value: withThisValue)
  sendEvent(name: "switch", value: "on")

}

I hope this helps,
Twack


(Im Brian) #4

@wackware - thanks! I ended up figuring it out using the standard fare: https://github.com/imbrianj/switch_controls_outlet/blob/master/switch_controls_outlet.groovy

Thanks for the tip, I’ll keep this in mind for the future.


(Im Brian) #5

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.


(Im Brian) #6

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.


(Im Brian) #7

…and this appears to be the extent of the functionality / documentation. So, I’m guessing this is simply not possible. https://smartthings.zendesk.com/entries/21603485-Event-Subscription-Methods


(Todd Wackford) #8

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
}

HTH,
Twack


(Im Brian) #9

@wackware - thanks a bunch for the help! I forgot that we can subscribe to specific actions (switch.off vs just switch). This is what I’m trying now:

def init() {
  subscribe(wallSwitch, "switch", lightSwitch)

  if(offToggle == "Yes") {
    subscribe(wallSwitch, "switch.off", doubleSwitch, [filterEvents: false])
  }
}

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.

Thanks again!


(Im Brian) #10

…and it looks like this is still firing the poll events:
subscribe(wallSwitch, "switch.off", doubleSwitch, [filterEvents: false])
Thinking this may not be doable.


(Todd Wackford) #11

@ImBrian

Are you trying to sense a double tap? I hope you’re not using a dimmer. They suck at reporting. LOL. I’ll look at the GIT.


(Im Brian) #12

@wackware

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.


(Todd Wackford) #13

@ImBrian

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.

HTH,
Twack


(Im Brian) #14

@wackware

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”.

Thanks again for the huge help!


(Todd Wackford) #15

@ImBrian,

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