Most efficient way to turn off lights when no motion?

Hello,

This is my first venture with Hubitat, and I found that the Motion lighting rule wasn't working for me as I'd hope, as I was explicitly looking to have a light turn off (that wasn't previously activated via motion) if there is no motion activity. I crafted the following with a bit of poking around on the support site, but I'm curious to know if this is the most efficient RM configuration?

**Select Trigger Events**
Garage Light(off) turns on
OR
Motion Sensor *changed*

**Select Actions to Run** 
IF (Motion Sensor active(F)  AND 
Garage Light(off) is on(F) [FALSE]) THEN
	Cancel Delayed Actions
ELSE
	IF (Garage Light(off) is on(F)  AND 
	Motion Sensor inactive(T) [FALSE]) THEN
		Off: Garage Light --> delayed: 0:01:00 (cancelable)

Technically, I was seeking to prevent the RM from being triggered every time the motion sensor was activated, and only when the garage light was turned on, but I didn't see how this was possible to set an AND conditional trigger event (Garage light on AND motion sensor activity).

The result is that this RM runs all the time. Is it possible to create a RM rule that can do the above without the motion sensor being a trigger event? The rule does exactly what I what (resets the 1 minutes delay whenever there is motion detected), I just don't care to have the rule executing all the time via motion events, even when the garage light is turned off. Removing the motion sensor from the trigger list seemed to prevent the Rule for looking at any new changed state of the sensor after the delay was set.

Is is possible to set a wait for event during the 1 minute delay and reset the delay if there is motion, or does it still need the motion trigger to be defined for that?

Thanks!

Motion Lighting can actually do what you're looking for. The option is called "Additional switches to turn off when turned off."

Regarding Rule Machine, if you want to keep going down this path instead, I'd recommend reading The Rule 4.0 docs, which contain a basic motion lighting example that will show you the general format recommended for this kind of rule, which you can modify as needed.

Regarding your specific questions, you cannot "AND" triggers because it doesn't really make sense to do this considering what they are--they are events, effectively momentary and durationless. If an event happens that matches any of your triggers (this is why RM hints at an "OR" between them all if you have multiple), the "Actions" section runs. If you want to check for two (or more--or fewer) conditions being true (or not) before doing something, then this is the place where you can do that. This is what you are already doing with your IF THEN/ELSE (or at least the outer one). There are some additional problems, like the fact that nothing in your rule will actually turn the lights on (there is no action for that anywhere) and nothing will really turn them off either since your last (inner) IF will only turn off the lights if they are already off (perhaps just a typo for "on" in your conditional?). In any case, the examples in the docs should provide inspiration if you do want to go down this path; otherwise Motion Lighting is a lot simpler and can handle this case. Good luck with whichever option, and feel free to ask if you have any more questions!

EDIT: Sorry, I missed the fact that you wanted to turn off with possibly no motion at any point!

2 Likes

I would do this

Triggers: Motion changed light changed

Actions:
If light ON and Motion Inactive, THEN
OFF: light delayed for 1 min cancelable
Else
Cancel delay action

1 Like

Thanks for the feedback, much appreciated, I did try that particular Motion Lighting option, but this would only activate if there was motion to begin with. If the motion sensor was never activated (light turned on but never actually entered the room, or triggered remotely by mistake) then this is not working for me, and why I ventured down the RM path. I think someone else had the same problem in in the past, which is what led me in that direction.

I'm fine with going down the more complex Rule Machine path, as it is educational as I begin experimenting with Hubitat.

I appreciate the clarification on the triggers. It makes more sense why there are no AND evaluations for a trigger.

With regards to my logic, the goal is only to turn off manually activated lights, so that portion was intentional, and in part why the Motion Lighting is not a 100% solution for me.

It does however turn the lights off as expected, as the logs show.

ev:692020-03-02 11:41:29.541 pm infoGarage Light switch is off
app:752020-03-02 11:41:29.391 pm infoDelay Over: Off: Garage Light --> delayed: 0:01:00 (cancelable)
app:752020-03-02 11:40:29.221 pm infoAction: Off: Garage Light --> delayed: 0:01:00 (cancelable)
app:752020-03-02 11:40:29.213 pm infoAction: IF (Garage Light(on) is on(T) AND Motion Sensor inactive(T) [TRUE]) THEN
app:752020-03-02 11:40:29.153 pm infoAction: ELSE (do actions)
app:752020-03-02 11:40:29.148 pm infoAction: Cancel Delayed Actions (skipped)
app:752020-03-02 11:40:29.144 pm infoAction: IF (Motion Sensor active(F) AND Garage Light(on) is on(T) [FALSE]) THEN (skipping)
app:752020-03-02 11:40:29.025 pm infoAuto Turn Off garage lights Triggered
app:752020-03-02 11:40:28.999 pm infoAuto Turn Off garage lights: Garage Light switch on
dev:692020-03-02 11:40:28.790 pm infoGarage Light switch is on

I guess I'm just looking for a clean solution where the Rule won't be processed every time there is motion in the room, but will only run after the Garage light on event is trigger and monitors for motion activity during the defined delay period, resetting, and continuing to monitor until the light is turned off again.

Thanks

Thanks. this is definitely more concise than my lame and needlessly complex version, and definitely still works. It just still gets evaluated every time the motion sensor is activated even when the light is not on, which seemed too busy and doing stuff that was unnecessary.

I'm trying to think about a lot of things happening on this little unit, and my thoughts are that this trigger activated method might just get a bit busy. Perhaps the unit can handle high volumes of this continually trigger activated method of resetting the timer, even when the light is off?

I guess I will need to read the 4.0 doc further to see if there are for or while loop equivalents that don't require a trigger to reevaluate the state of the the motion sensor.

I haven’t read the whole docs but I think if you put a device in a trigger, it will always be evaluated in order to fire up your automation.

1 Like

It has to evaluate every time motion occurs or it won't be able to trigger when you want it to. It's a pifling overhead on the hub. Don't worry about it.

1 Like

There is something called a Private Boolean which is a local variable intrinsic to RM 4 rules that you can set and test for as part of your conditions.

Another thing you could do is have 2 rules that alternately disable/enable each other depending upon conditions. I use this for temporarily disabling my closet motion rules when a switch is physically turned on for example (turning off sets motion rules back on).

Anyway like @Angus_M mentioned I don't think you have to worry about additional event firings - I think they are relatively inexpensive processing wise.

Why do you need an else? If the motion sensor is seeing motion, it's going to cancel the turn off time anyway. Same thing if it starts counting down, if it sees motion, it resets the countdown.

Yes, I"m coming to that conclusion. this is just not worth the extra effort, and I should just aim for simplicity.

How would it cancel the delay?
I don't have any action that is actually turning the light on with a motion event, as I am only turning the light on manually. So I only have an action to turn it off (with delay) with lack of motion. Without the ELSE, it will always turn it off after the initial delay, even if there is motion detected afterwards.

At least, using the more simplified code reommendation provided by EijiS

In your example posted at the top of this thread, the delayed off is cancelled if motion occurs again during the delay period. This approach is standard practice for motion lighting set-ups. I noticed the delay is 1 minute which may not be enough depending on your motion sensor and/or activity. My Iris sensors refresh every 30 seconds, so that would allow a further 30 seconds to retrigger otherwise the lights will go off. That may not be enough depending on what's happening in the room. I normally set the delay to 3 or so minutes. My Xiaomi motion sensors refresh again only 60 seconds after triggering. So it's necessary with those to definitely have more than a 1 minute delay to work reliably.

Hope it helps! :smiley:

Why turn the light on manually? If you are going to set up a motion sensor to turn the lights off it’s just as easy to have it turn on. By only having it turn on manually you seem to just be making things harder for yourself. Simple is always the way to go.

Can be a very simple set up under Motion Lighting Apps.
Choose motion sensors, chose Lights to turn on, set delay to turn off. As long as the motion sensors are seeing motion, the lights stay on and the timer only starts when motion stops. If before the timer is up they detect motion again, the timer resets.

You need an else there because you want any motion to cancel the delayed action, which is turning off the lights. If your motion is active, it will skip the if-then part and go to else, which is the cancellation of delayed action. Now, when you leave and the motion turns to inactive, it will trigger the rule. The light is on and it is inactive so it will turn the light off in 1 min. If motion is detected again, the rule will fire up and we will be back at one.

If you want to also automatically turn the light on with motion, just add the simple condition,
“IF light is off, Turn light ON”
or this statement if it is outside
“IF light is off AND time is between sunset to sunrise, THEN
Turn light ON
End-IF”
After canceled delayed action

My daughter has a walk in closet that is motion light activated like you describe. I also added separate rule that if the physical switch is turned on the motion rule pauses for an hour. When physically turned off or time expires the motion rule is resumed. Nice to be able to disable the motion rule on command sometimes.

This is what I use. If the motion stops and then it sees motion again it resets the timer.

1 Like

I have no idea where the OP is and I may be wrong but I read somewhere that in Europe you can't sell an occupancy switch. They must be vacancy switches, where you must explicitly turn the lights on when walking into a room with the motion sensor turning the lights off. It is easy enough to get used to doing vacancy with switches and thinking that way when making rules. The above may totally not apply in this situation.

Oh I see. It is pretty much the same thing as my simple rule. The moment the motion stops (Motion becomes Inactive). The timer, which is 1 min, will start then turn the light off (delayed action). Once the motion becomes active, it will cancel the timer (delayed action) and wait for it to go inactive to start the timer again. I'm new to hubitat so I don't know about this app yet.