I am new to Hubitat and evaluating it as a replacement for my current hub. But, with my current hub, rules are written with code, so they are very flexible, and I am wondering if anyone can help me to replicate my lighting rules in Hubitat.
All of my lighting rules are mainly controlled by motion sensors, but don't have a fixed timeout. The way I have it setup is that the rule for the motion detected turns on the light if off, and sets an "Off Time" variable. Then a separate rule runs every minute and checks all light "Off Time" variables, and if any have expired, and the light in on, and the motion sensor(s) in the room are inactive, the light is turned off. So the motion detected rule does not have a timer and does not turn off the light ever. The motion sensor(s) going to inactive is completely ignored. Most of the time the motion just puts 1 to 10 minutes to the Off Time Variable depending on the room.
The advantage to this setup is that I don't have just the fixed timer for how long the light stays on. Other sources can set longer times to the Off Time Variable. So for example since I have have HomeSeer switches, I can use those to set longer timeouts. For example a single tap up can set 1 hour, 2 taps up 2 hours, 3 taps up 3 hours, and so on up to 5 taps. So I am not always dependent on the motion sensors detecting motion in low motion rooms like the office, or TV room. I can also set different timeouts by scene. For example if I had a "Movie Night" scene. When that scene is triggered the family room lights cold lower to a very low level and the Off Time set to 3 hours since I will likely not be moving much for at least a couple of hours.
Setting up the rules on motion trigger is simple, but:
Where do I store the time that I want the light to turn off?
Can Hubitat do date/time comparisons? For example, if the movie night scene set the off time 3 hours in the future, the motion rule should not reduce that to 5 minutes.
How do I setup a rule to run every minute? Or run when the time matches or is greater than one of these Off Time Variables?
Can this be done with the existing tools in Hubitat, or will I need to write my own Application to make some or all of this work?
It's difficult to say for certain, but I think you should be able to do everything you want using Rule Machine.
Personally I use it for everything and keep away from Simple Lighting.
You can use modes for movie night etc.
Thanks for the optimistic reply, but I am past theory at this point. I have my Hubitat, and several devices moved to it. I'm now looking for specifics to implement this strategy.
Update: This feature described to set a delay based on a variable is not in the released platform, but in our upcoming 2.1.0 release. This should be out within a few days.
Using RM, you can use a Global Variable to hold the time off duration value. One of the delay actions, called Delay Actions, will take a GV as a duration specified in seconds. That same action, when used in a Rule can be canceled upon a change of rule truth, if that is of value. For example, a typical motion lighting rule would turn on the light from motion active, and then turn it off from motion inactive after some delay, with cancel on truth change. So if motion goes active again before it turns off the light, it starts the timer over, thus keeping the light on until there is no motion for the entire timer duration. By using Delay Actions set by a GV, that whole process could be controlled as you describe.
RM does not do date/time comparisons directly. This is possible to do in custom apps.
For a rule to run every minute, one simple way to do that is to use a Trigger with Periodic as the Trigger Event. Periodic allows basically everything in a cron string to be used to cause periodic actions. RM also supports one rule causing another rule to do something.
Let us know how your project proceeds. For something as customized as what you're doing, RM is probably the best answer. Motion Lighting has a lot of options for motion controlled lighting, so you should check those out. It is possible to crudely control Motion Lighting from RM (enable, disable), but not to do things like variable off delays.
Thanks Bruce, that is exactly the tips I needed. I'm now curious for what this new feature is before I go setting up all of these rules. I had not found the Trigger event of "Periodic" That is the key to #3.