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


#1

1) Give a description of the problem
I have a piston that turns a light on and off when motion is detected. The ‘off’ portion is not working properly.

2) What is the expected behavior?
Light should turn off after both motion detectors show inactive for three minutes.

3) What is happening/not happening?
Light stays on

4) Post a Green Snapshot of the pistonimage


#2

Hi @flyize
It’s very simple…let me share my piston here…
You can add your TIME restriction AFTER the motion changes to active…

(don’t mind line #20 - that was just for testing purposes and I forgot to take it off:)))))


#3

In all of my testing, the command “did not change in the last X” does not work as expected.

Ike’s suggestion to use “motion stays inactive for X” is the way to go.

If you are wanting both motions to be inactive, that line would be
IF ALL OF Motion 1 & 2 stays inactive for X


#4

That will actually work? I thought that wouldn’t work if they both were triggers and not conditions.


#5

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


#6

Yes, the standard approach is:

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

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

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


#7

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?


#8

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


#9

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

Please post the piston that did’n work…


#10

edit: And from this thread

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

because 2 triggers can never be simultaneously true.


#11

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)


#12

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


#13

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


#14

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.


#15

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


#16

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


#17

Correct.

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.


#18

Trust me, this code works flawlessly:

temp

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)


#19

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.


#20

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.