Help: Don't Turn Off Lights after Closing Door if Motion is detected

So, I am new to rule machine, and I thought I had a basic understanding after going through the wiki. Apparently not. ;D

I am trying to simply not turn off my lights in the garage workshop when I close the door if I am in there (motion active). This is what I did, but it seems it turns off the light no matter what. Do I not understand the exit rule command correctly? Any help is appreciated

That should more or less work, but it should be noted that it checks the state of the motion sensor 1 minute after the contact sensor closes (not when it closes) and some motion sensors may have a quick enough "reset" time that they go inactive in less than a minute if you're just standing in the room, maybe even moving a little bit, depending on how sensitive they are. You can see from the time you took your screenshot that motion was inactive at that time (or at least when the page was loaded; this may not be a surprise given when you probably took the screenshot).

There are a couple things you could try: one is to decrease the delay in your rule or see if your motion sensor allows you to increase the motion inactive timer (many Z-Wave ones do; I haven't seen as many Zigbee ones that do), assuming neither of these would be a problem for your rule or other things that use the device.

Another option is to replace that "IF" line with something like "Wait for expression: Garage motion inactive and stays that way for 0:01:00" or similar. This will wait for the sensor to become inactive if it already isn't (and then stay that way for the specified amount of time), or continue right away with the countdown (the specified amount of time) if it already is. You may need to think through the logic and possible interactions with other things that turn the lights off (sounds like you might have some other motion-based automation?), or perhaps combine them both into this rule or something like it, but that's the general idea.

Yet another is to use an app that can track motion and contact on its own (without having to recreate such logic in a rule) and optionally include delays for each. I believe Motion Lighting can do this, and Room Lighting almost certainly could, though some users don't find it quite as easy to set up.

Finally, you could consider turning on logging for your rule and checking Logs after something unexpected happens. This will show you what the rule is doing when and could be helpful in case the problem is none of the above.

Thanks for the reply. The thought with the delay was to give enough time for the zigbee motion sensor to change state from active to inactive before running the rest of the rule, which is of course to turn off the lights if the motion sensor is inactive.

If the motion sensor is active still after a minute, I am still in there and therefore the rule should exit and therefore keep the lights on.


I will read through your reply again, but wondering if my more thorough explanation changes your advise. Thanks!

HAHA, realized I overcomplicated this whole thing. I used to not have a garage motion sensor, but did have a contact sensor on the door. So when I closed the door while in the garage I was often in the dark and had to find the garage light switch. I added the motion sensor and thought I would do what I tried above. Instead, I should have just changed it to have the lights trigger off when motion is not detected for 2 minutes. Simpler is better.

I still however, would like to know why my rule as originally planned did not work, only for the education and future rule building.

There's no reason it shouldn't work if motion was inactive exactly one minute after the sensor closed, but whether that would actually happen depends on, among other things, the inactivity timer of your sensor. Enabling all logging for the rule and then consulting Logs to see what happens when is the best step you can take when a rule doesn't seem to be working as intended.

But that will keep.light on after motion stops .

Assuming that is the only door you would be ok.

I think room lighting will cover this. I use event engine for my similar rule.

1 Like