Is there an easy way to do a wait until time passes an exact time?
Eg, I want the behavior of elapsed time but rather than specify a relative number of minutes for time to elapsed I want to see if there is an easy way to calculate number of minutes until a specific time.
My use case is my towel warmer. I have a motion detector in the hallway. Once motion is detected between 5 am and 10 am I want my towel warmer to be started for 1 hour. But as time gets past 9 am I don't want to run it past 10 am.
The logic I would like is something like this
iF motion in bedroom hallway AND time between 5am and 10am THEN
Turn on bathroom towel warmer
IF time between 9 am and 10 am THEN
Wait until time is 10 am
ELSE
wait 60 minutes
END-IF
END-IF
I tried to find a way to calculate minutes until 10 am and input that into the wait for event elapsed time but I could not see a way to do it.
Any ideas? Right now I'm basically just running the towel rack up to an extra hour which is working. I could make another rule that just fires once a day at 10 am and turna off the towel heater, but I like to keep rules together for was of debugging and avoiding cross dependencies of behaviors in loosely related rules.
Thoughts?
What you want sounds like it's possible: under "Wait for Event," there is "Certain Time" as an option that you can use:
When completed, it could look like this:
However, there is another consideration: how do you want to trigger this rule? Motion, it seems, but keep in mind that any event matching a trigger will cause the rule actions to begin running again from the beginning, and it will also cancel any in-progress "Wait"s. So, effectively, you'd be starting that 1-hour or until-10-AM timer over again each time motion goes active. An easy way to avoid this, at the small expense of another rule, is to create a virtual motion sensor triggered by the first motion event in this area between, say, 5 and 10 AM. Keep that motion sensor "active" until (at least) 10 AM, then reset either then or sometime early in the morning to make it good to go for the next morning again. That rule might look like:
Trigger: Bedroom hallway motion active
Actions:
IF (Time between 5 AM and 10 AM) THEN
Cancel Delayed Actions
active() on virtual motion sensor
Delay 6:00:00 (cancelable)
inactive() on virtual motion sensor
END-IF
(This is a bit kludgy: it waits 6 hours after the last "active" event from the sensor to reset the virtual sensor, which given your interval and time of day should always be after the 5-10 AM timeframe and before you care about it the next day...but it should work. There may be something more elegant, but a "Wait" for a specific time outside of this IF
is the only thing I can think of, and then you're setting it inactive--generally harmless, but not necessary--even if this rule didn't make it active in the first place. This also doesn't really need to be a motion sensor: a virtual switch would do, or even a virtual button if you use a private boolean or something in the rule to track whether it's already been activated for the day. Also, this assumes you're using the built-in virtual motion sensor driver or any other that won't generate an event if you call the custom active()
command while the sensor is already active.)
Then, use this virtual sensor becoming active to trigger your rule, where it sounds like you've got the right idea. You'll just need an "Off" action for the warmer before your last END-IF
(and after the second-to-last one).
Thanks! I didn't look carefully for the certain time.
I'm less worried about firing the rule a lot. My motion sensors changes state every thirty seconds so at most I will get this event twice a minute for such minutes. I got to imagine that processing an event, cancelling a timer and setting a switch that is already on (or maybe I'll test before set) isn't that expensive to process even on a tiny embedded micro processor.
Thanks for pointing it out to me, much. Much appreciated!