Turn off lights after fives minutes with no motion

Initally this sounded like a perfect candidate for the "Motion and Mode Lighting" app so I went ahead and impleted it this way which works great with with one exception (below):


The problem here is the motion sensor must go to active state (detect motion) and then go back to inactive (no motion) for the countdown to start meaning the light will stay on forever if motion not detected after the light it is turned on. ​

For example:

The garage lights automatically turns on when the garage door or the laundry door (leading to the garage) are opened. Someone may open one of these doors and immediatelly close them back, never enteering the garage and therefore never triggering the motion sensor.

I was hopping there I can overcome this somehow by using RM instead of the Motion Light app. Any suggestions?

You could certainly use a rule for that purpose, but I think it might be easier to virtually "convert" the contact events into motion events so you can use them with standard/purpose-built apps like this. Here's one way to do so:

If you've never installed a custom app before, it's not too bad--just copy and paste the code (from the "Raw" link/button on that page) into Apps Code > New App, then install an instance of the app as normal from the "Apps" page (except it's a user app and not a built-in app). Then, use the virtual motion sensor this app creates instead of your real contact sensor in the Motion Lighting app.


You could do this with multiple rules.

Rule one, if contact sensors open turn lights on, then turn off after X mins

Rule 2, if motion reports active, turn on lights, cancel rule timers from rule 1

Rule 3, if motion reports inactive turn off light in X mins

This would turn on lights from any scenario, but keep them on if someone is moving around in the garage. It may not be as elegant as 1 rule, but I find multiple rules a little easier on the sanity checks.


In your screenshot above, I don't see where you are using contact sensors at all. But you want to?

  • Do you want to turn on with motion sensor and/or contact sensor?
  • Then you want to also turn off with motion sensor and/or contact sensor?
  • Would you mind if the contact sensor immediately turned off the light?

You can use contact sensors directly in Motion Lighting, but they aren't exactly the same. They can turn off the switch, but I believe it is immediate, not on the delay. But this is an easy workaround.

The small "converter" app that bertabcd1234 posted above can make the contact act almost exactly like a motion sensor. From my memory, the contact sensor closes and it immediately makes it motion stopped where with a real sensor there is typically a small delay. But that won't make much difference if you have your timeout timer set correctly.


Here is my Garage Lights RM 5 rule that I recently rewrote and it works very well for my needs. Basically, if any of the doors to the garage are open, or there is motion in the garage, then the lights stay on. Else, they turn off after 5 minutes of no motion and all doors closed (i.e. nobody is in the garage.) Hope this helps!


Thanks guys. It is interesting how complicated these little things can get.

To answer @neonturbo questions and provide a few more details:

  • Garage has two doors, the actual garage door and a back door that leads to the laundry.
  • It is possible to open and close the laundry door without trigger the motion sensor (if you don't actually go inside the garage).
  • I do want the contact sensors to turn on the lights, not the motion sensor. This way when you step your foot inside the garage the lights are already on.

I had a RM turning the lights on based on the contact sensors, reason you don't see anything on the "Motion and Mode Lighting" screenshot I provided.

It looks interesting but here is what I think is going to happen:

  1. Trigger: Start to open the laundry door - turn on the lights
  2. Before I step into the garage there is no motion so it will pass through the wait condition.
  3. I close the door behind me so all doors are closed, it will pass through the next condition.
  4. It will wait 5 minutes with me inside the garage and then turn off the light, leaving me in the dark.

The way that I handle situations like this is to simply put another motion sensor in the laundry room and use the motion aggregation app.

If there is motion in either the garage or the laundry room the garage light will turn on until their is no motion in either room with an adjustable delay to turn off.

For example, we have a walk-in closet and the potty room off the master bathroom. Motion in any of the three areas keeps all three areas illuminated. I also vary the illumination per mode so trips to the bathroom at night are more of a nightlight experience.

1 Like

Take a look at the first WAIT condition, as it relies on No Motion - AND - All Doors being closed, before proceeding.

Give it a try... It works as expected due to the fact that RM cancels any existing WAITs if the rule is retriggered. As long the rule is retriggered by motion in the garage, between the time the door is closed and the five minute wait expires, the lights will stay on.

1 Like

I didn't know one rule could cancel the other like that.
Learning something new every day.

You just gave me another grate idea for an automation :+1:

Interesting concept and a great tool to have available for whatever challenge comes next.
I will give it a try.

So first time the light is turned on by by a contact sensor, it skips the wait for inactive because it is already inactive, now it is stuck in the wait for all doors to close.

If I close the door without never stepping into the room it goes into the 5 minutes timer and turn off the lights.

But if I do step into the room I will trigger the motion sensor.

Are you saying at this point RM will cancel the running instance (the one waiting for the door to close or for a 5 mins timer) and start over? In which case it will stop in the wait for inactive event?

If this is the case it should work but it raises another issue?
Isn't it bad (for performance reasons) to have it triggered every 2 minutes for as long as I'm in the room? Because that is how often the motion sensor will be sending an "active" event.

1 Like


Yes... But to be clear, it is a Wait for ALL of the conditions (motion and contact sensors), not just motion inactive.

Not at all, as Hubitat basically ignores duplicate, successive 'active' status updates from a physical device. In fact, most motion sensors don't send duplicate events like that, they only send data when the status changes (YMMV, of course, based on the specific hardware device!) In any event, Hubitat de-duplicates the incoming status updates and only creates an Event when the status changes.


Now I get it. I create a rule that looks exactly like yours, did some testing and so far it is working the way I expect it to.


Not OP. This is very close to the scenario/rule i was trying to build, something i can closely model. My mind was working on a much more complicated rule. Thanks!

1 Like

Recommendations on this one? Once I close the door, the lights are going off pretty quick, I'm hoping they'd stay on for 4 min, or at least until my motion catches me again to reset the off condition.

Try making a small tweak to the "Wait for Conditions" to change the "any closed" to "all closed".

1 Like

One additional question, how would I change the dimmer in this one by tod, btw two times to be lower (ie between 2-6:30 am) where dimmer would be 30?

Edit: hmm, thinking of tying this to a mode.

Please help me know what I am missing.

I understand the logic but cant see how to add the AND / OR operatives to the rules.

Your time and insight are appreciated.

Welcome to the Hubitat forums!

Where in the rule do you want to add these? Triggers? Actions? The process is different for each.

Have you seen the Rule Machine documentation Rule-5.1 - Hubitat Documentation , or the videos that show how use Rule Machine How to Use Rule Machine Vol. 1: Simple Conditional Rules - YouTube or Rule Machine 2: Advance Conditional Rules - YouTube ?

Also I would consider using Basic Rules if at all possible, they are much easier to use. How to Use Basic Rules in Hubitat Elevation Tutorial - YouTube

TY for the quick response. I will review the docs and video you referenced.


If you are still stuck, please feel free to post again. We can work our way through your specific rule using screenshots of your rule.

Download the Hubitat app