Getting notifications for something that is not happening


#1

I have this piston which sets my hub’s status to Away when there’s no one home (this depends on my phone’s location and on a switch status), and to Home whenever I’m home or the switch is on. Or both. This part (lines 17 to 25) took me some time but it’s working fine now.

In the same piston, there are actions that are specific for each device (the actions based on the hub’s Home/Away status are on another piston).

I want to get a notification on my phone whenever Switch 9 is on or off, and also set a light to flash for a specific amount of time every on/off. I’m sending “Gente ON” and “Gente OFF” (People ON/OFF). This is in lines 26 to 46.

The weird thing is that today I left home and I got a “Gente OFF” notification. My Hub’s status turned to Away (as expected). I checked on ST app activity and there’s no mention of the Gente switch turning on or off. Then I arrived and I got the notification “Gente ON”. Again, that switch was untouched (both physically and in the app activity).

I checked other pistons to make sure the notification wasn’t being sent from another place, but nope.

As it doesn’t make any sense to me, I’m suspecting it’s related to lines 18 and 20 being set as “Suscription Method: Always”

Any ideas?
Thanks!


#2

There are a couple contributing factors:

  • Each trigger causes the piston to run thru the entire code, from top to bottom. (in your case, presence changing to anything, as well as Switch 9 turning on/off will run the piston top to bottom)
  • ELSE can be a very powerful command, and should be used very sparingly, especially for newbies.
    (the only time I might use an ELSE is when there is only one trigger)

What happened is you left the house with Switch 9 off, so lines 17-25 worked perfectly.

…but the piston won’t stop until it has reached the last line of code…

Meaning, on line 27, it checked the status of Switch 9, which was off, so it pushed the ELSE block at lines 37-46… (toggled White Bulb 1, and sent “Gente OFF” notification)


My recommendation? Use only one trigger (lightning bolt) per piston, and avoid using ELSE for now.


#3

Alright, so this was what was happening with all my other home/away pistons probably!

I started joining actions together in one piston trying to avoid using many global variables, and also because it was much easier to have all the tasks combined into a single piston, but I didn’t know that the whole piston would run until the end with every trigger.

So the solution would be to never use Else in these “compound” pistons, right? I really prefer (for now) having all the actions grouped by some kind of logic, so there’s a piston that defines home/away, another that reacts to home/away, anoter one for all the buttons in one remote cotrol, etc.

Thanks for your help!


#4
  • Avoid using ELSE for now
  • Limit each piston to one trigger (lightning bolt), or less
  • You can have as many conditional IFs as you want

IE:

IF Device changes to X  (Trigger)
Then
    IF condition is Y
        Then do something
    END IF
    IF condition is Z
        Then do something else
    END IF
END IF

#5

Also, keep in mind if you change the “Subscription Method” on a condition to “Always”,
IE: temp
then you are effectively making it a trigger… and as a trigger, you are back to square one with each trigger event running the code top to bottom.