# Rule Machine logic confirmation

I have a number of motion rules to turn on lights and then turn them off after a set time. I am realizing that the off command only works if motion turns the light on. I think I need to set a separate rule to turn off the light x minutes after it comes on.

Just looking for a little confirmation before reworking all my rules.

You can use simple Lighting or motion lighting to turn it off after X minutes.

Actually, the off command only works after motion becomes inactive. So if you turn the light on some other way, and expect it turn off after x minutes irrespective of motion, then yes, you'd need a rule or Simple Lighting rule to do that. However, if you use both they will be in conflict. Suppose you have a rule to turn off a light 5 minutes after it is turned on. After 4 minutes someone walks into the room, triggering the motion sensor. One minute later the timer on the first rule is going to run out and turn the light off irrespective of the state of the motion rule. It is possible to get more complicated so that the motion rule overrules the timer rule.

So, I think you haven't really explained what it is you want to have happen. Describe the exact scenario you have in mind.

I have a closet light that is turned on by motion but is also in a group that I turn on/off with Alexa. I've noticed that the closet light sometimes stays on and assumed it was bc of the "off after a certain amount of time" rule is only in the motion trigger.

Do you mean that if you turn it on with Alexa, it doesn't turn off? It won't turn off from the motion rule unless there was motion. It doesn't matter how it's turned on, but it will only turn off from motion becoming inactive, not being inactive. Rules (both in Rule Machine and Simple Lighting) are fired by events. Your motion rule needs a motion active event to turn on and a motion inactive event to turn off. Turning the light on some other way won't cause those events.

And thatās why Iām think of creating 2 rules one for motion on and a second for off after a set amount of time

See above about how the two will conflict with each other.

Sorry, I am not communicating clearly here and haven't had a chance to sit down and dig into this.

What I was thinking was to change the motion rule to only turn on the lights and then have a second rule triggered by the light turning on that would turn it off after ten minutes.

Is there a way in rule machine to reset the delay on the off rule if there is continued motion?

Yes, use Turn on or off these switches, pending cancellation. This will only work for a rule, not for a trigger (has to have both true and false parts).

It would be easy to have your cake and eat it too, with two rules. The motion on / off rule, and a second trigger that turns the light off after x minutes, but not if there is still motion in the room.

In the first rule, in the part where it turns the light on from motion, set the Private Boolean of the second trigger to false, and in the false part where it turns the light off after motion stops, set the Private Boolean of the second trigger to true. Then, in the second trigger, under Restrictions, select Disable with Private Boolean.

This will stop the timer from turning off the lights when it expires IF there is still motion in the room.

I'm now using this method and it works for my situation. I use a Simple Lighting app to turn on my hall light based on Sunset with an offset and motion, until 1am. The light is allowed to stay on for 4 minutes after motion stops.

That same bulb is paired with a Lutron Connected Bulb Remote and that's where I had issue trying to control it with a single rule before. Anytime anyone turned the light on via the Connected Bulb Remote, it just wouldn't turn off. Now that I'm using Simple Lighting for the motion timeout and the rule to shutoff the light if it's ON, but there is no motion after 10 minutes, everything works as expected.

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.