Create automation after a certain time

Hi guys,
I’m wondering if it’s possible to create an automation which checks if a certain time has passed.
I’m aware of the possibility to check if the time is exactly e.g. 12 o’clock, however I want to make sure that e.g. if Home Assistant has been offline between 11am and 1pm, the automation will still be triggered.

What I got so far:

platform: time
at: "12:00:00"

Now, is there something like

platform: time
after: "12:00:00"
before: "16:00:00"

?

Use case: I’m using a controllable electric switch for my pool pump which I don’t want to be running all day just because my Home Assistant has crashed somewhere in between 11:59 and 13:01.

Thanks a lot.

Another (and I think the easiest and safest) option is to add an automation that checks the state of the pool pump at HA startup.

The best way that I can think of to do something like this is to have a datetime helper setup that you update when the thing you want to start a timer against starts.

Next, setup an automation that runs every N number of minutes or hours that then does work if thing you started is running and the difference in time is greater than some maximum amount of time. That is, both conditions should be true. If so, then stop the thing.

If you have the time pattern large, then the maximum amount of time you could have your thing running is that time span + your time maximum amount of time.

Let’s say you have your maximum amount of time be 15 minutes and your automation check interval is every 5 minutes, then you could end up running for about 20 minutes worst case.

You can flash many WiFi switches to Tasmota, then just set the switch with rules to only be able to run for an hour or 2 as a backup. You can still turn it on and off, but the most it will ever run without a trigger could be say 2 hours or you pick the time. Gives you a fail-safe mode.
This will work if HA is there or not.

1 Like

I agree with @tykeal that a datetime helper is probably your best bet, especially for this type of thing and to survive reboots or reloads. I use this method for a number of things and even wrote a script to reset the datetime helper depending on what it is I’m doing - it gives me significant flexibility and reliability with certain automations that I really need to start at a specific, but variable, time.

wouldn’t a restorable timer do well here? if home assistant crashes in the middle, the timer will get restored and triggered either at the appropriate time (if it hasan’t yet occurred) or if the timer was supposed to fire while ha is down, it’ll fire as soon as it comes up.

so i’d set a timer to turn your switch off, and start the timer whenever the switch turns on… then the only issue you have to worry about is if homeassistant is down for days… in which case, no home assistant automation is going to save you…

That’s actually a good idea. I totally forgot that that helper type has been added semi-recently!