Trying to turn off lights when no motion detected between certain times but failing

I have 2 lights and a motion sensor in my living room. I created a rule that when notion motion is detected for 15 minutes between 10.30pm to 3am, to turn both lights off.

Some background: we're usually in the living room so this rule is to keep the lights on if we have guests over. We used to have a rule to turn lights off at 10.30pm regardless, so this new rule created would avoid that if the house was still active. We also have a rule to turn on a living room light at sunset, so this rule (to turn off) would be helpful to turn off that light if we're away on vacation.

I was playing around with Basic Rules but for some reason the rule to turn off the lights after some time of inactivity is not working.

Here's the settings for this Basic Rule:

Let me know if you need more information.

Any idea what I could be doing wrong :blush:?

I remember when I started my HA journey with just my Hue bridge and lights, and was amazed that the only option was that during a defined period of the day a scene could be turned on.... I don't know about anyone else, but "night time" is not the same any two nights in a row.... Anyway.... moving on... :slight_smile:

I feel like what you need is a manual override, which may require RM rather than something simpler... RM certainly provides the option of a predicate where you can define a condition for the trigger being acted upon. So you could define your rule as you want it for a "normal" day, but also include a virtual device that indicates you have guests and use that in a predicate for the rule, essentially disabling it on those evenings. This same Virtual device could be used across multiple rules if you need.

The setting of this virtual device (I would recommend a switch) could be driven off a one of a couple of calendar drivers to detect when you have visitors scheduled to appear at your house. Admittedly requires a level of planning.... Up to you whether this suits...

1 Like

Thanks for the quick reply! I did look at RM but felt too overwhelmed with all the settings.

I actually came over from SmartThings, after my v1 hub was decommissioned. I had a similar rule with SmartThings and wanted to replicated. However, when I first looked at BR, I don't think it had that function so I had the lights go off at a specific time each night. A recent check showed me the variables I could play around with and I thought all was good, until the rules did not fire off.

Interestingly, all the other rules I have with BR seem to work just fine, although they are also a lot simpler (turn on lights at sunset, turn off at sunrise, turn off lights after an hour, those kind of things). This is my most complicated BR rule admittedly, but I'm hoping we can figure it out.

I feel like it may be more useful to provide a screenshot of the screen where you setup the rule in BR, rather than the settings screen you have included in the original post....

Sure thing, here's the settings page:

That looks OK to me... It isn't exactly jumping out to me what the issue is.

Unless the time restriction does not like crossing the midnight barrier?

1 Like

Look like you have logging enabled. Any clues in "Logs"?

1 Like

Not sure I follow, but I think I would attack the living room lights a little differently. Instead of telling them to go off at a certain time, I tell mine to stay on if there is activity using Simple Automation Rules. Then they just go off if there is none.

That's not what he is doing. He is doing it with motion, but only during certain hours of the day.

I may not be explaining myself properly. I have mine on motion as well, when the motion stops, i.e. no one is in the living room the lights will go off the prescribe amount of time thats on my simple automation rule. From his original post it sounded like he wanted the lights to go off when there is no motion.

He does, but only between 10:15pm and 3am. The rest of the time he doesn't want the rule turning the lights off when motion is inactive.

I just tested this real fast, and my rule worked as expected - so still not sure what's going on. I'll try again with a time restriction that passes midnight.

EDIT: Nope, still works as expected. I'm stumped.

When it is WORKING you should see something like this in the logs:

When it is outside of the allowed time you will not see any logs from the basic rule at all (but may still see device events). Sort of like this:

I was wondering if that could be an issue. Will try keeping it on the same day and see if that helps.

Not sure how to read the logs, but here they are:

Ahhh got it, yes, slightly different scenario then mine. Activity keeps mine on, and actually stays on if you set the timer out far enough until no one is in the room for that amount of time. It's all in the details.

1 Like

I see once in your logs, 11:09:28.922 PM, when it should have turned them off. (There don't appear to be any other times when it stayed inactive long enough.) Did this not happen? If so, do the lights respond fine to On/Off commands you send from their device pages?

We don't know how Basic Rule is written, but it's unlikely that it would log this message without actually sending the command to the devices (this is how Rule Machine logs work). This means it's like a device issue. You could test by adding a virtual switch or something to the list of lights in your rule, where you can more easily observe its behavior (shouldn't be any problems with a virtual devices--they just do what you say!), and perhaps use a shorter wait time for testing while you're getting things figured out.

It's also possible there's an issue with Basic Rule, but I'd (no pun intended...) rule this much out first.

1 Like

Thank you @JasonJoelOld, @chad.andrews, @bertabcd1234, and @sburke781 for the feedback and comments. I believe I've found the culprit. The problem is with the motion sensor requirement: Motion has stopped and stayed inactive.

Because of this, there is a need for the motion sensor to sense a motion for the rule to start.

In my case, there was no motion, and thus it did not start. So even though the lights were on and it was during the time period, because no motion was sensed, the lights remained on.

I tested this earlier with a similar rule (that I cloned) and noticed it wasn't working either. So I walked past the motion and waited and this time it worked.

So good news is that now I know how to use this better. The bad news is now I have to figure out how I would program so that the lights would either turn off at a specific time if no motion (when no one is home, because I still want the lights on) OR turn off if no motion after a period of time during a period of time.


So how I handle this is have the normal motion lighting app do everything. There is one option to not turn off if a switch is on, shown below. I call it an override.

The "double tap override" is a Zwave switch that can interpret double/triple taps. Those taps are in reality a button press. But a dedicated button (like a Pico or Zen34) or even a voice command would work here. Use your imagination as to what you might turn on or use differently and use that, maybe even a smart outlet or a certain light.

This is the Simple Automation Rule that goes into action for when you double tap the up button, and there is a very similar one for when you turn the switch off to disable the override.

This button press via the rule above turns on and off a virtual switch, which is the one you use to "disable off if on" in the Motion Lighting app.


  • Switch and Motion lighting work completely normal most of the time.
  • Double tap this switch, which sets a virtual switch to on.
  • Motion Lighting sees this virtual switch on, and prevents turning off.
  • Press the off button (or turn the light switch off) and the virtual switch goes to off, which allows Motion Lighting to return to normal function.

I know this old, but just in case anyone else is looking for a similar solution. You probably need 2 rules for turning off the lights and keeping track of motion. I'd have a variable to keep track of the last time there was motion. One rule would run at 10:30pm and would turn off the lights if the variable shows there hasn't been motion. The other rule, would check for no motion for 15 minutes and would either turn off the lights (10:30pm-3am) or set the variable to the current time. Before the first use, you'd have to initialize the variable. Here's what I'd do in pseudo-code:

set a variable:

Create 3 rules:

trigger: sunset OR motion
turn on lights

trigger: motion has stopped and stayed inactive 15 minutes
if time between 22:30 and 3:00
then turn off lights
else motionTime=Now

trigger: 22:30
if motionTime<=22:30
then turn off lights

Download the Hubitat app