Lights not turning off after set period of time


#1

1) Give a description of the problem
I’m trying to create a piston that will turn lights on based on motions, and then turn off after x number of minutes as long as a different light is not on. I can get the piston to turn the lights on based on motion, but the lights do not turn off

2) What is the expected behavior?
When motion is sensed in my bathroom I want the lights to turn on and stay on for 8 minutes unless there is motion unless the shower light is on. Basically if I’m in the shower, I won’t want the bathroom lights to turn off.

3) What is happening/not happening?
Lights are coming on, but do not turn off.

**4) Post a Green Snapshot of the piston

Thank you in advance.


#2

Motion sensors are an interesting thing to program against as there are many options available with them. For starters, usually you can configure the “timeout” value on them which determines how long before they go from “active” to “inactive”. So you have to take that into consideration in the overall design.

However, the reason why your lights are not turning off is that you cannot nest those IF statements like that. If the Motions sensor IS ACTIVE it can never stay away from Active. Those two things are mutually exclusive and the nested IF will never ever run as it relies on the first IF being false.

Personally I like to construct motion based pistons with the following two event triggers:

IF sensor changes to active

and

IF sensor changes to inactive

You also have to put them at the top level of the piston, not nested within each other. They are distinct events, so you have to account for them independently.

So one IF block like this:
image

And one like this:
image

The rest of what you have seems to look fine, just un-nest that second IF block and move it out to the “root” level of the piston.

Technically you could move your second IF into the ELSE section of the piston as well. Personally I like to know what event triggered the piston though, so that’s why I do mine the way I do. Just a design choice, not an absolute requirement.


#3

Thank you for the help, I didn’t realize I had that nested. So I pretty much blew away the other piston and tried to start from scratch. Unfortunately it’s still not working, and ideas what I did wrong this time?


#4

Your 2nd IF is still nested inside your first (under THEN).

Drag it out so it’s independent of the first and you should be all set.


#5

Man, I feel silly. Finally got them unnested and both use cases work. Thanks @michicago for the help.