Trying to turn off a light after two motion detectors show inactive for 3 minutes


If you have two triggers in THE SAME IF, then you might experience problems.,.
several triggers with different IFs in a single piston, is a different ballgame


Yes, the standard approach is:

IF ANY OF Motion 1 or Motion 2 changes to active
    Then Turn on light

IF ALL OF Motion 1 and Motion 2 stays inactive for X
    Then Turn off light

(basically your entire piston can be reduced to just a few lines)


I tried this but it didn’t turn off the light. I don’t see how it could either, since both triggers will never be true at exactly the same time.

Are you sure we don’t need to use conditions instead?


Those are two separate IFs… Not one inside the other.
(the first IF ends before the second begins)


I tried this but it didn’t turn off the light

Please post the piston that did’n work…


edit: And from this thread

1) why use conditions, why not only use triggers?

because 2 triggers can never be simultaneously true.


That is correct.
When the first IF is true, the first block runs. When the second IF is true, then the second block runs.

Your “RD42” piston looks rock solid! It that is not working then the issue lies elsewhere.
(don’t forget your time of day restriction)


For what it’s worth, whenever I have a time spanning midnight, I code it inverted.

For example, I will never use this code:
IF Time is between sunset and sunrise

Instead, I code it like this:
IF Time is not between sunrise and sunset


I agree with @WCmore code looks great…

Just try one thing…I don’t like to use TIME as you did… I use TIME as a condition in the IF…

First trigger
Second Condition

IF sensor 5 or 9 changes to active
If time is between sunset and sunrise (or as @WCmore suggested NOT between…)
----Then white bulb
----Turn ON

IF sensor 5 or 9 stay ineactive for 3 minutes
If time is between sunset and sunrise (or as @WCmore suggested NOT between…)
----Then white bulb
----Turn OFF

this MUST work…
If not, I have to say you are having some other issues…
I use the exact code I wrote to you here, in many of my pistons…


But because of the ALL, the second IF is waiting for two triggers to be TRUE at the same time. Unless I’m really missing something here, that can’t happen.

edit: And technically, if the second block ever were to be true, the whole piston is evaluated from top to bottom.


I can say that the time restriction works, as the light is never turned on during the day. It gets turned on at sundown (and currently never turns off).


Time is between OR not between is A CONDITION not a trigger…



The triggers are in the IF with both motion sensors being inactive for 3 minutes. That IF will never be true, as triggers are instantaneous.


Trust me, this code works flawlessly:


The single trigger fires 3 minutes after the last device turns inactive.

Any movement in front of either sensor will reset the timer.

This is irrelevant because the first block will be ignored. (it will be false at that time)


Ahhhh. So even though there are multiple sensors in there, it’s technically only counted as a single trigger? I did not know that.

I still don’t understand why it’s not working. Lemme grab some logs.


Make sure you leave the room completely for at least 4-6 minutes.
Staying in the room motionless rarely works… (and don’t forget about any pets)

The reason I say 4-6 minutes instead of 3 minutes is because each device will fall back on ‘inactive’ after a different duration.


if you use ANY SENSOR, trigger will be first one that goes inactive x amount of time…
if you use ALL SENSORS, the system will wait untill ALL related sensors are inactive.


So I should have viewed the logs first. It seems that one of the motion sensors (technically a Nest Hello) would see the light turning off as motion, and turn everything right back on.

Self inflicted yet again…


I would have suggested this, but every one of your posts said that it never turned off.
(often times, the smallest detail is the most important when troubleshooting)


I actually didn’t know myself. It happened very quickly, and every time I walked by it, it was on. That’s why I mentioned that I should have actually looked at the logs. Lesson hopefully learned…