Turning Lights Off Based On Inactive Motion

New Hubitat user here. Just finished adding about 50 various z-wave devices and letting my z-wave mesh settle for the 3 or 4 days as recommended. I am now getting into creating some of my first automation's.

I'm starting off with just some basic automation's to turn lights off that my kids leave on frequently. I have been doing a lot of reading and it seems the general recommendation is to use an app like Motion Lighting vs using RM 4.0.

I do already have a grasp on building out rules in RM based on development experience so I went ahead and built out what I believe is a pretty basic RM rule that meets my need just to play around and test with.

Upon testing of the above rule in RM, it seems to always turn the light off after 1 minute of motion inactivity, no matter how the light was turned on.

I have taken a look at the Motion Lighting app to see if I can convert my RM rule over, but what I don't see accounted for, at least after reading the motion lighting documentation and playing around with it a bit, is handling situation where the light may be manually turned on via a google home device, via the Hubitat dashboard or some other means that may not trigger the motion status change. In this situation, I still want it to hit against the rule and shut the light off after 1 minute of no motion like the RM rule does.

I do see an option in Motion Lighting called "Switches to turn on lights" but there isn't a subsequent explanation of this option within the documentation. The documentation seems to go from the "Button to enable turning on/off" setting, skipping over the "Switches to turn on lights" setting and just goes to "Enable on/off at Time". Maybe this "Switches to turn on lights" setting is what I need to be using?

If my rule is possible within the the Motion Lighting app, just some brief help with how I would achieve it would be greatly appreciated.

Otherwise let me know if I should just stick with RM.

Thanks in advance!

You basically did answer your own question in that you do need to use the switches to turn on lights option to always trigger the ML rule even if the light is turned on not via motion.

Also the the reason your rule turned the light off is that you need to delay the lights turning off.
The delay you have before that is working like a pause of 1 minute and if cancelled will then turn the light off.

And the fact that he's not turning the lights ON with the rule.

Don't use RM here as you haven't quite got the understanding yet and Motion lighting is much better for use cases like this.

Yes. But need to clarify exactly what you want and what will happen.

So motion lighting is designed so the ON options are correctly separated from the OFF. Because of this if you turn the lights on by any other means the OFF will still happen as that part can still run. The issue is ensuring that the app knows that you have manually triggered it.

There were some changes at one point and I'm not sure if now by standard the app subscribes to all events @bravenel may need to confirm. In the past if you wanted to control it externally and the off to happen you would fill in the alexa/ GH box at the bottom and you would expose that device to GH and the app could follow it.
In my setup I don't need that because when I manually turn ON the lights I want them to stay ON until I turn them OFF manually. But if Auto ON then Auto OFF. If this is set up the app is already following the switch state of the light.

The key thing in your case is this, when you turn ON the light will the detector see movement at some point? Because if the motion is inactive and doesn't go active it can't then go inactive to send a off, does that make sense?


I use motion sensor dimmers in the bathrooms, which is a very similar concept to what you're trying to do. The only real difference is that the lights stay on for a different period of time depending on mode (time of day) and I have set different dimmer levels so in the middle of the night, they don't blind anyone going into the washroom.

I watched one of the Hubitat videos on coding practices, and as opposed to IF-THEN-ELSE, one recommendation was to insert a wait condition instead. Here's what I generated using the motion lighting app and it seems to work. I've also replicated this to turn off hallway lights that are frequently left on...

Thanks for the reply's gentlemen, but it seems I didn't explain properly in my original post.

The outcome that I'm getting from my posted RM rule is the outcome that I want.

The only thing I was wondering is if I could/should transfer that rule into the Motion Lighting app. Like I tried to state in my original post, there is a missing description for the "Switch to turn lights on option" in the documentation for the Motion Lighting app, so I was trying to confirm what this option was for and if this was the option I needed to use in my situation before I invested a bunch of time creating all the other rules I want/need.

I have a different rule that deals with turning the lights on based on motion and LUX. This auto on rule also checks to see if the garage doors are opening or closing when the motion state is changed. I am doing this because I don't want the lights turning on due to the motion caused by the garage doors moving up and down since these can be triggered remotely. This is something I'm pretty sure I can't do with the Motion Lighting app, so my garage lights auto on rule will just stay in RM.

I didn't post my auto on rule because that's working and I didn't have any questions about it. I also don't do the auto on and auto off in the same rule so that I can pause them independently of each other if needed.

I'm pretty sure I have a decent understanding of RM, I just didn't convey in my original post what my actual question was as well as I thought I did when I originally wrote it, so apologies for that.

That's what I want my rule to help solve for. If the light is turned ON by something other than motion (that is the garage lights on trigger in this rule) and then motion does not occur within the 1 minute delay, I want the lights to turn off because if no one is actually in the garage (motion inactive), that likely means it was turned on by accident and needs to be shut off. If motion is detected within the minute delay (that is the motion sensor state change trigger in this rule) then cancel the delay and keep the lights on regardless of how it was turned on (my auto on rule or manually).

I will essentially be using a version of this same auto off rule for most of the other rooms in the house because all lights can be turned on via voice through google assistant, a Hubitat dashboard, manually via the wall switch or automatically via motion and I want to make sure that if something gets turned ON by accident that the rules will handle turning it back OFF when there's no motion after a delay regardless of how it was turned on.

1 Like

Thanks for the reply, the one question I have for you with your Motion Lighting app rule, what happens if the lights get turned on by something other than motion. e.g if the lights are turned on via a hubitat dashboard or a voice command (if your using either of those) and no motion actually occurs in the bathroom?

Do the lights still turn off or do they stay on?

At this point, they will remain on. I'm the only person with access to the Hubitat dashboard. We have Amazon Echo devices all through the house, but only use them to turn on and off lights, devices or routines that aren't controlled by motion or events such as sunrise/sunset. My thought was to only trigger on a room light if someone is there. We've tried to adopt a "hands-off" approach to daily activities. This would not work well for places such as bedrooms though. The exception to this is when our smoke detectors go off, at which time all the lights in the house are turned on.

I would love to try and get my family to take a more 'hands off' approach but I have a 2 year old, 5 year old and a 12 year old who are the farthest from hands off as you can possibly be. We also have two wall mounted tablets where access to the dashboards for controlling Sonos, viewing security cameras and everything else is provided.

My goal is to try and start getting them familiar with this "hands off" mindset from a lighting perspective using these first rules, but I am going to still need to account for times when they forget and go "hands on" for now.

Eventually I may be able to rework the rules to not have to account for this.

With that said, would the only change to your rule for my situation be to add the bathroom light switch itself under the switches to turn lights off option and switches to turn lights off option?

If I'm understanding correctly, you mean adding the bathroom light switch itself under the switches to turn lights "on" and switches to turn lights off option...

If so, there is the ability to use a switch option instead of dimmer. My dimmers have the integrated motion sensor, but as far as Hubitat sees them, they are a separate device.

Yep you are understanding correctly. I don't have dimmers in my bathrooms so there just switches and I'm using zooz 4-1 sensors for motion temp humidity etc.

I'll just have to play with the Motion Lighting stuff and see what happens.

Thanks again.

1 Like

No worries. I think you have a need for something a little more complex than I do. I wasn't exactly sure what you needed to accomplish so I thought I'd throw out what I'm doing just in case it may offer some assistance. There is a lot of great people and resources here so I'm sure it will get solved.

1 Like

No worries :+1:, its always better to give us the full story and rules then we can see what your trying to do and assist better. Your rule on its on looked way off :crazy_face::rofl:.

I think I have a solution for you (similar to my set up, I use a mix of both), but I have just got in from work and need to re-read the posts and have a good think to be sure :+1:. I'll get back to you on that.

1 Like

If it helps, here is the auto ON rule I have for the Garage to go with the auto OFF rule I posted before.

Garage Auto On

Just to try to restate, my main goal for the auto OFF rule is for it to handle turning the light off after a delay if the motion sensor is inactive regardless of whether the light was originally turned on by the auto ON rule OR some other manual means (voice control, dashboard, etc.).

they should be PIRs (passive infrared) so this shouldn't set them off, I would test, but i have allowed for this too just encase.

I haven't enabled this in my motion app just for testing but it will work as i use it else where.

we can we just need both.

Motion rule add any extras you need but these bits are needed.

Door rule with local variable and connector to Motion app

switch off rule

sorry i swapped test devices after the post



Thank you for this!

I have been playing around with what you proposed here and doing own testing. Couple of quick questions for you to make sure I'm understanding everything properly in my head.

In the motion lighting app rule, I see the delay of 2 minutes and then in the switch off rule, a delay of 1 minute. Does the cancel delay actions line of the switch off rule, cancel the delay put in place by the motion lighting app or just the delay it started within itself? I only ask this because it was my understanding that delays were local to the rule they were initiated by, but maybe the motion lighting app works differently so wanting to confirm.

If the switch off rule delay cancellation doesn't interact with the motion lighting app delay (which is my assumption), is it the correct understanding that its important to always have a shorter delay in the switch off rule than whats set in the motion lighting app so that the two rules aren't overlapping each other when trying to turn things off?

And along the same lines, would I need to add the switch that's being turned off to the motion lighting app rule so that if its shut off by the switch off rule, it cancels out the motion lighting app rule?

I have tested this out quite a bit before adding that to my rule originally and you are right, its not the doors actually moving that causes the motion state change because they move about 1-2 feet before the motion is detected. I believe what is happening is that when the doors open, the infrared signature of the areas my motion sensors are watching changes due to increased infrared beginning to enter the garage and increasing as the door opens and the sensors detect it as motion. I even double checked again yesterday and confirmed that the process of opening and closing the garage doors definitely cause a motion state change, so thanks for including that so that this can be ignored.

Again thanks a lot for the help!

1 Like

That's just to show you that you can have what ever time outs you want one does not effect the other :grinning:.

So no the rule does not cancel the motion.

This is correct.

Not necessarily, because the rule is A just a off and B only runs if the motion hasn't. I also added a extra bit that will cancel the off if it gets manually turned ON but you then walk in and trigger the motion sensor before the off is called. That should cover you for all your cases.

Not sure I understand you here?

From my examples the lights that you are controling need to be in both things. This is so that the rule can monitor the switch state, the additional light (which is actually just acting as a bool variable) needs to turn ON at the same time as the actual light so that the rule knows it was automatically controlled.

It must be hot or cold where you are and the garage the opposite, that's what causes it (heat movement).

1 Like

@earoberts1520 my advice would be to copy my rules and app exactly with your devices. Give me a shout if you have any questions along the way, then once you have it you can see the logs and work out how it's working together. Once that's done you can then add to it and chop it to however you want. The bits I have done are the "core" but I wanted you to do it like this because it will allow you to do it to each of your rooms if needed and most importantly it makes the motion part really simple to add all the extra functions like lux or different mode delays.

1 Like

@BorrisTheCat your advice was great!

I did a lot of testing with different ways to set up these rules and it seems like creating them using your advice was the best way as far as hub resources/speed. All rules and automations seem to be really quick and responsive

I finished up all of the room automation's tonight using versions of your rules, slightly edited for the use case of each room, and everything seems to be working properly so far. I'll let the family test it all out over the next couple days and make tweaks as the complain about something :rofl:

Thanks again for you help, I may finally be able to get some good sleep tonight now that my brain isn't actively working to solve all of this.

1 Like