Lights Off-Cancelable if Motion Sensor is Active

Please help. I want my lights to turn off when the motion sensor is inactive for 5 minutes, but I want the lights to stay on if the motion sensor becomes active within the 5 minutes. I have tried many different rules and can't seem to find the right combination. Please review my rule and tell me what I am doing wrong. Thanks.

Have you tried the built-in Motion Lighting app? It works well for this case.

NO I have not. I will take a look at it though. I still would like advice on my rule. Thanks.

You need to change the trigger of the rule to motion CHANGING and then you have to finish the action with adding the following:

ELSE:
     Cancel Delayed actions
END-IF

You also don't need the hall light being on....the extra off won't hurt anything.

Thanks ryan780, I'll try that. I'm not sure the motion lighting app allows for the lights staying on and restarting the lights off once the motion sensor is active again. What I want is every time the motion sensor is "active" during the "on" period, I want the lights to stay on. Once the motion sensor is inactive for 5 or more minutes, I want the lights to go off.

That can be done very easily through Motion Lighting if that's all you want to have happen.

1 Like

This is what pretty much everyone wants and is what every "lights with motion" kind of app I'm aware of does, definitely including Hubitat's stock Motion Lighting and Simple Lighting apps.

Ryan's advice above on how to fix your rule is correct. The Rule 4.0 docs contain an example exactly like what you want to do, and I'd recommend reading them before diving into Rule Machine (which I wouldn't recommend if this is all you want, but I understand wanting to learn). Good luck!

Ryan780 This is how I set up the Motion in the Motion Lighting App. Is it correct?

Thanks bert...I love Rule Machine but am still rather new, so I appreciate your advice. There are little things that I am missing where I just need a little help so thanks again!

Simple lighting does this as well

Thank you [napalmcsr] for showing me this!

First of all, you do not need to turn on the hall light and set the level to 100. You only need to set the level to 100. That will also turn the light on.

You say that your motion lighting app doesn't work correctly? What is the app doing? Do you have logs for the rule?

Ryan780 I'm having trouble with my bathroom lights. They are shutting off every time after 30 seconds. Mg hall lights are working as planned. Would you please review my bathroom lights rule and tell me what the problem is. I want to make sure I am understanding the If Then Else concept properly. Not sure why the bathroom light is shutting off after 30 seconds regardless of the three different scheduled times I have for actions.

You have too many if/then combinations. You are going to get multiple Else's firing every time. You want to change the structure to have the light level at the lowest level to be controlled by an if/then. All of the other statements are common except for the timeout.

Also, the first thing I would recommend is that you look into using Modes. HE modes will greatly simplify the setup and you'll see why in just a second.

Here's what I would use:

TRIGGER:  Bathroom Motion Changing

Action:

If Motion Active THEN
     Cancel Delayed Actions
     If Light is Off THEN
          Set dimmer by Mode:
                 Mode 1: 100%
                 Mode 2: 80%
                 Mode 3: 50%
     END-IF
ELSE
     Delay Actions per Mode:
          Mode 1: 15 minutes (cancelable)
          Mode 2: 15 Minutes (cancelable)
          Mode 3: 15 seconds (cancelable)
     Turn lights off
END-IF

So, you can see, the rule's structure becomes a lot simpler when mode is used to restrict the setting of the light level and the delay before off. However, if you don't want to use modes, this is how you would do it.

TRIGGER:  Bathroom Motion Changing

Action:

If Motion Active THEN
     Cancel Delayed Actions
     If Light is Off THEN
          If Time is A 
                 Dim lights to 100%
          ELSE IF  time is B
                 Dim lights to  80%
          ELSE IF Time is C
                 Dim lights to  50%
         End-IF
     END-IF
ELSE
     If Time is 6am to 10PM THEN
         Delay actions by  15 Minutes (cancelable)
     ELSE IF Time is 10PM to 6AM
          Delay actions by 15 seconds (cancelable)
     END-IF
     Turn lights off
END-IF

The use of ELSE-IF means that if one part is true, the subsequent parts do not get evaluated and executed. The problem you are having with your rule is that when the motion is inactive, all three ELSE statements are being executed. So, you are actually scheduling 3 delayed actions. 2 for 15 minutes and one for 15 seconds. The use of ELSE-IF limits it to one execution. Let me know if you have more questions.

Thanks for your advice. I will study what you have here and if I am still struggling, I will ask some more. Just wrapping the If then rules in my head. I understand the concepts somewhat but I have to learn how to put this all together.

This of it this way....at each if, you have to make a binary choice....True or False (yes or now). If the answer is no, then you skip anything in the then and proceed to an Else-If and evaluate that (if there is one) or to an Else. If you have an ELSE statement, it will always be executed if the IF and all the ELSE IFs are false. So, because full with it. It means that something is always going to happen.

Once you start getting into "nested statements" with one inside another, you just have to remember what level deep you are. You bring yourself back to the previous level by using an END-IF.

Once it "clicks" you'll get it. Just keep plugging away. The more rules you look at and try to write, the quicker it will come.

Ryan780

I have been studying the mode features because it makes more sense to use it but I can't seem to find where to set a mode between two times such as early morning from 6:00 am to 9:00. You have been a big help for me to understand the if then concept and the mode features. I love the trial and error and education with this. You are right, the more I play with it, the more it will make sense.

Ryan780, I think it's working this morning. The first two modes are registering just fine. I'll keep you posted. You have been great. I would never have figured this out without your help!

1 Like

My pleasure. Glad I could help.

Ryan780,

Thanks again for this "If then" explanation:

This of it this way....at each if, you have to make a binary choice....True or False (yes or now). If the answer is no, then you skip anything in the then and proceed to an Else-If and evaluate that (if there is one) or to an Else. If you have an ELSE statement, it will always be executed if the IF and all the ELSE IFs are false. So, because full with it. It means that something is always going to happen.

Once you start getting into "nested statements" with one inside another, you just have to remember what level deep you are. You bring yourself back to the previous level by using an END-IF.

Once it "clicks" you'll get it. Just keep plugging away. The more rules you look at and try to write, the quicker it will come.

All my lights are working because of your explanations and fixes on my rules. We have four teachers in the family and if you are not a teacher, then you should be. Pun intended. Thanks again!!:grin:

1 Like