Need help making piston more efficient


#1

1) Give a description of the problem
Im worried that my statement saying if motion stays in active for 120 seconds is inefficient. Im wondering if there is any room for improvement in this entire piston
2) What is the expected behaviour?
If the door opens or the motion sensor is active, or a button is pressed, the light goes on. If the door contact closes, or there is no motion for 120 seconds (whether or not there was any motion to begin with), or a button is pressed, the light goes off. the last statement says if someone turn on the light from a different switch and there is no motion for 120 seconds (whether or not there was any motion to begin with), the light turns off 2 minutes later.
3) What is happening/not happening?
Piston is working, just wondering if there are best practices im not following.

**4) Post a Green Snapshot of the piston!


#2

I would highly recommend avoiding this logic:

IF Something happens
    Then change Switch 2
END IF

IF Switch 2 changes
    Then change Switch 2
END IF

One event (execution) will trigger another event (execution) which will trigger yet another…


Changing Switch 2 (on line 44) to a condition prevents this…

IE: IF Switch 2’s switch is on


#3

There are a lot of triggers here. I understand how the first two if blocks can work since all the triggers are or’d. I don’t see how the last if block can work reliably, however, since I don’t see how those two triggers can be active simultaneously (or it would at least be difficult).

In this piston, the motion 1 trigger enters in 3 places and two of them are identical. Might be better if you can rearrange the logic so no two triggers are the same (and maybe change some to conditions?). Not sure how to do it at the moment.


#4

The last if block is there to address if someone approaches the door and its already open and they turn the switch on and dont go down another hallway further into a room never setting the motion sensor off, then go back through the original door and doesnt shut it, the light will go out after 2 minutes. In my mind, that is how it would be possible for someone to physically turn the light on AND for the motion sensor to stay inactive for 2 minutes.


#5

I understand the purpose but I believe if no one ever sets off the motion sensor then the 2 minute no motion trigger is long past and will not coincide with the switch changes to on trigger. Seems like what you really want is to start a timer when the switch is turned on and then turn it off if no motion is detected in that time but not sure the best way to implement. As @WCmore pointed out, this if gets checked immediately when you turn the switch on in the first if block but notice the third block wouldn’t turn off the switch. (Note that most device handlers do not differentiate between physical and programmatic turn on/off).


#6

Thanks. Do you know I can identify whether smartthings see the light being turned on programatically or physically?


#7

Most devices handlers do not distinguish between the two,
but you can test using a single piston (with 2 blocks):

IF Switch2 physically changes
    Then log = "Physical"
END IF

IF Switch2 programmatically changes
    Then log = "Program"
END IF

Test by flipping the switch manually, and then reading the logs (set to Full)
That should give you enough info, but you can also test a programmatic toggle as well…