Ok so keeping in mind Iāve been up for almost 24 hours now and that there are many many many many ways to do this in rule machine I am going to share the more complex example first because if I do not scare you I do think this is the best way to set yourself up for the future.
So this is how the current sleep deprived version of me would do it to minimize unnecessary hub resources and give yourself a bunch of extra options in the futureā¦
1. Use a hub variable (Boolean with a Switch connector) to manage day and night (if itās easier, modes would also work).
Basically Iād create a virtual switch (named āvarLux1CurrentStateā in my example) so that when the switch is on, itās day time and when itās off itās night time.
While a little more work to setup initially this gives you a ton of flexibility later as you can change the start time for day or night in one rule to flip the switch and then use that switch in a bunch of other rules later if you want/need in the future.
2. Create a separate morning and night rule (modes could also be used)
While you could create one giant rule that does it all this would likely create a bunch of unnecessary trigger events constantly running to check the time and run unnecessary conditional statements. This one rule would be minor but create enough of these and youāll start to experience performance issues.
In the 6am rule example below I add a predicate that my virtual switch is āoffā meaning itās currently set to night before the single trigger at 6am. Once 6am hits, I turn the virtual switch to āonā to indicate itās daytime and tell the dimmer to turn off.
Similar for the 11pm rule below, I make sure the virtual switch is āonā meaning itās set to daytime then at 11pm I set the switch to āoffā to indicate itās now night time and turn the dimmer to 20%
Once again the advantage to this is youāre really only pinging your hub two times and not asking it to do any crazy conditional actions (just flip a switch and set a dimmer) but most of all of you use this day/night switch for other rules and decide you prefer 10:30pm instead of 11:00pmā¦ you only have to change the number in the single night rule.
3. Now that all that is setup all we have to do is write a simple motion rule (see example below)
Here we have a simple predicate so that it only runs at night (when our virtual switch is off) and it only triggers when your motion sensor detects active motion.
First thing it does is, if there is a delayed action already running in the rule it stops it. Then it sets the dimmer to 80%. As soon as your motion sensor stops detecting motion (most do this after 20-30 seconds) it tells your hub to wait 5 minutes and then turn the dimmer to 20%.
If your motion sensor goes active again anytime during that 5 minutes the rule will immediately re-run. It will cancel the previous 5 min timerā¦ set the light to 80% (which itās still at anyway) and wait for your motion sensor to go inactive before setting a new 5 minute timer.
This repeats indefinitely as long as the variable switch is off (night) and your sensor detects motion.
ā-
Thatās it, I swear! Let me know if I totally overwhelmed you and I can share something simpler to setup but just keep in mind those options will likely put some unnecessarily burden on your hubā¦ and those can really add up over time if youāre not careful.