I’m trying to make a rule for my garage lights to turn them off if I left them on after 11:30pm. This is my best guess as to the logic for this.
Garage Lights off
Everyday between 11:30pm & 6:00am
If the garage hue motion sensor has illuminance of => 60
And there is no motion for > 10 minutes
Turn off lights otherwise do nothing
The use of time range, checking the light level, and checking for motion verifies that I’m not out working late in the garage or if my boys have gone out in the garage to get some soda out of the garage fridge late at night and forget to turn off the lights.
I figure I have to use Rule Machine as all the other automation “Apps” are too limited in options for conditions other than main trigger.
I have tried the simple automation, basic rules, and room lighting but couldn’t get any of the multiple conditions as possibilities. Maybe one or two but not the Time range, lighting level, and movement for the whole rule. I tried to start in Rule Machine but just don’t know how to get the “condition” logic rules to work or perhaps I’m not understanding RMs logic sequence.
Any help would be appreciated. I might try again and maybe get a screen shot of my attempt. I “removed” my first two attempts in RM.
I agree that you're selected the most appropriate app, Rule Machine 5.1.
Dissecting piece by piece, my first input would be to relegate that time constraint to a Required Expression, since you don't even want the rule to evaluate unless it's between 11:30PM and 6:00AM.
Required Expression:
Time between 11:30 PM and 6:00 AM
Trigger Events:
Illuminance => 60
OR
Time is 11:30 PM
Actions to Run:
Wait for expression: motion sensor inactive: duration --> 0:10:00
Off: lights
If the illuminance isn't consistent you might need to add a PB to keep the rule from retriggering as it changes.
So I went to try the "ChatGPT" AI and asked it to come up with a Hubitat rule for me with the parameters I previously gave.
Here is what I "asked" the AI and the solution that it came up with.
Question to the AI:
Act as a Hubitat expert. I want to have an automation in Hubitat's rule machine app that turns off my garage light switch when the following conditions occur. The time has to be between 11:30pm and 6:00am, the light sensor needs to register 40 lux or greater, the motion sensor should not have detected movement for at least 10 minutes. Otherwise it should leave the lights on.
Solution:
Sure, I can help you create a rule in the Hubitat Rule Machine app to meet your requirements.
Here are the steps to create the rule:
Open the Hubitat Rule Machine app and click on "Create New Rule."
Name your rule and select "Triggered Rule" as the rule type.
In the "Trigger Events" section, select your motion sensor as the trigger device and choose "no motion" as the trigger event. Set the time interval to "10 minutes" to ensure that the motion sensor has not detected movement for at least 10 minutes.
In the "Conditions" section, create a new condition by clicking on "Add Condition." Choose your light sensor as the condition device and set the condition to "lux is greater than or equal to 40."
In the same "Conditions" section, create another new condition by clicking on "Add Condition." This time, choose "Time" as the condition device and set the condition to "between 11:30 PM and 6:00 AM."
In the "Actions" section, select your garage light switch as the action device and choose "Turn off" as the action to perform.
Save the rule by clicking on "Done" and activate it by clicking on "Enable Rule."
I did set the start time to 9pm for testing. It didn't work. Not sure why it says "(unused)" behind the conditions that are true. Does not make sense to me. The conditions appear to be correct. Light is above 40 lux, no motion for more than 10 minutes and is within the time frame. Not sure why it did not try to turn off the lights.
*** Update ***
One problem I see is that I was trying to "toggle" the light (from on to off). I'm using a zigbee relay to turn my garage opener lights on and off that are also tied to the garage door opener light button which is basically a momentary switch at that point. So to turn on/off the lights I send an "on" signal no matter the condition as a "toggle". I cannot "monitor" the actual status of the lights at this point. I do plan a change to a smart outlet that can be controlled and monitored as a better solution, but I have not gotten there just yet. I guess that would be the next step. But now my Hue motion sensor is not returning an update lux after resetting the lights. Ugh. I can "run actions" and it will turn the lights off but looking at the logs (I did activate all logging) there are no logs.
The conditions don't do anything unless you actually use them in the rule in an IF statement. You can see that both conditions are marked "unused."
I'd do it slightly differently than the suggestion above. Something like:
Required Expression:
Time between 11:30 PM and 6:00 AM
Trigger Events:
Motion sensor inactive and stays that way for 0:10:00
Actions:
If Illuminance => 40
Turn off lights
End-if
*** ETA ***
The reason I'd use motion as the trigger is because it will happen less frequently. Using illumination => 40 would cause the rule to run every time the illumination changes; at 40, 41, 42, 43, etc. Probably not really what you want.
What happens if the light is turned on and the motion sensor goes inactive before 11:30? Unless someone retriggers the motion sensor the light will stay on all night. If you add 11:30 as a second trigger the light will turn off immediately at 11:30 even though motion may be active.
Here's a revised RE that'll keep the rule from retriggering if illuminance keep changing => 60
Required Expression:
Time between 11:30 PM and 6:00 AM AND
( Illuminance is < 60 OR
Time between 11:30 PM and 11:30 PM
)
Trigger Events:
Illuminance => 60
OR
Time is 11:30 PM
Actions to Run:
Wait for expression: motion sensor inactive: duration --> 0:10:00
Off: lights
Within the time window, the rule can only trigger when illuminance is < 60 or if the time is 11:30 PM regardless of illuminance level.
Thank you sir for your example. After tearing my hair out trying to figure out what the heck "RE" was I spotted the "switch" for the Required Expression. I really had to tweak things and used a simple smart bulb as my rest light (in the room I'm sitting in) for simplicity. I had to tweak everything to get any kind of results. Once I did it was just fine tuning the conditions. Here is my current automation that appears to work.
I have no idea what the "Required Expression" is used for as I would think it was a trigger, but whatever, this appear to work. I will run with it for a few days and see if it continues to operate as intended.
The whole thing for this was to be able to not have to get out of bed when my wife says, "Are the garage lights off?" I could tell "Ms. A" to turn them off, but if I don't know the status of the lights, and I don't, she could wind up turn them on instead. This is what I wanted, the "system" to "see" that the lights are on, make sure that no one is out working in the garage (hence the 5 minute no movement) and then drop the hammer on the lights. Now, I will have to remember that there is a 5 minute window to keep moving in there. I do have a diode laser and have to be present when it is operating and I will spend time sitting at the computer watching YT or designing in the software for the laser and be still enough to not trigger the Hue motion sensor. I might have to set the sensitivity to "high" so all I need to do is wave a hand. I'll probably need to make an automation to turn the lights on if there is movement if the lights are off. Perhaps a simple automation or basic rule. I'll play with that.
Thanks to all. This was a great help to me as I would have gone to bed without having any success and it would cause me to lose sleep trying to figure out what I was doing wrong. I greatly appreciate everyone's help and suggestions. I do love this community.
I think you want to turn the shop lights Off instead of On?
Required Expression limits when the rule can run. If the required expression is false, the rule will not fire, even if the trigger event occurs.
The trigger is an event that determines "when" you want the rule to run. Every time the trigger event happens, the rule will run — unless it is limited in some way, like by a Required Expression.
The "Actions" are what you want to happen when the rule is triggered.
I don't think you're rule is quite done, yet. Consider the scenario when someone turns on the garage light at 10:30 PM to grab something and leaves without turning off the light. At 11:00 the illuminance is > 50. Assuming illuminace is stable (within the reporting requirement of your Hue motion sensor) there won't be an event to trigger this rule.
Remember, Hubitat is an event driven system meaning there needs to be a change in state to create an event. For example, a switch that is off is a state and a switch that is on is also a state. A switch going from off to on is an event. In the scenerio listed above, if the illuminance doesn't change there won't be an event so the rule won't trigger.
A certain time is also an event and I suggest adding it as a trigger to check the state of the motion sensor at 11:00 (Wait for Expression: motion inactive) and proceed with the Off action if the motion is inactive or wait until it is. I also suggest adding the sub-condition in the RE. The "( )" are important here as you want the rule to trigger between 11 & 6 IF illuminance < 60 OR IF the time is 11:00 PM. Yeah, you can rearrange the RE to this if it makes more sense.
Required Expression:
Time between 11:00 PM and 11:00 PM OR
( Illuminance is < 60 AND
Time between 11:00 PM and 06:00 AM
)
There are many ways to write a rule so write it to the logic you understand.
For these lights, I’m tripping a momentary relay (like a momentary switch - no real or perceived on/off position) so the signal I send could be a “toggle”, an “off”, or an “on” command, the relay doesn’t care.
I finally figured out the “Required Expression” thing, well at least the reason for it. Since I don’t do programming, understanding the logic limits of the Hubitat (the rules of which it’s logic works) will be my challenge. I guess my brain makes a lot of assumptions without even thinking about them that I do not realize need to be considered.
So two questions, why in your RE are you looking for light to be under 60 lux and the time to be exactly 11:00pm to even start this rule?
The lights, when on (which I want to verify they are and if so, between 11p & 6a, when no one moving in the garage, turn off lights). I kinda get the 11p or 11p, but not really. In my head this only will work between 11:00p and 11:01p. And as for the <60 (lux), that would be a lights off state. I did a lot of luminance testing to get the value of 70-ish lux as “lights on”.
I do appreciate this education. I hope that my questions come across as wanting to learn and not “snooty”.
The RE is between (11 & 6 and < 60) OR time is 11:00 PM, note that it is OR not AND.
Remember that the RE tell the rule when it is allowed to be triggered. By having a RE < 60 the rule will only trigger once when the illumination become greater than or equal to 60. Basically, it's going to prevent retriggering of the rule if illuminance keeps changing but is => 60. If you don't do this, the rule could retrigger within the 5 minute duration you've set for motion to be inactive. If this happens, the previous Wait will be canceled (which is actually a Scheduled Job) and a new Wait will start resulting in restarting the 5-minute timer. If this keeps happening the light will never turn off. I'll add, though, that I don't know how often the Hue reports illumination. If the minimum reporting period is greater than 5 minutes then the RE wouldn't be needed. If it can report a new lux level within 5 minutes then the RE should probably be added.
The 11:00 PM trigger is needed because of the scenario I pointed out. If the light is on at 11:00 then you're not guaranteed to get an event between 11 & 6. Illuminance at a certain level is a state and not an event and you need an event to trigger the rule. A certain time trigger is an event that'll ensure you're lights will be turned off.
The RE of OR Time between 11:00 PM and 11:00 PM allows the rule to be trigger regardless of the lux level. It make the rule triggerable between 11:00:00.999 and 11:00.59.999 so that the 11:00 PM trigger works and will turn off the light if it's already on.
Not at all taken as snooty and I'm glad to help. We've all been in learning mode.
@kahn-hubitat Assuming that you're suggesting an 11:30 only trigger, what if someone is actually in there are 11:30 and wants the light on? What about the scenario when someone goes in the garage at midnight and forgets to turn the light off?