As noted, if HA isn’t up when the time trigger happens, it won’t do anything until the next one. You can create some amount of resiliency by scheduling things to happen using the trigger for when Home Assistant starts.
If you have the device’s status in HA, you could set a condition on that automation so that it only runs the actions if the device is off.
You could use a condition for the automation so that the time has to be on or after the time you wanted the device to start.
Lastly you could have an input boolean that you set to TRUE when you run the timed automation and then somehow set it to FALSE and then have a condition in the startup automation that will only run the actions if the input boolean is set to FALSE.
Schedule an automation to run more than once per day.
Then invoke the script from the automation, if it hasn’t executed in a given time window (the script hasn’t been triggered).
Note: I didn’t use the automation since that will trigger as soon as the schedule fires.
In short HA doesn’t schedule “skipped” events for you - however since you are forced to implement it yourself you have total flexibility to implement it, however you want.
So HA does not run automations at startup, correct? I would need to create a startup script to check on conditions for an item to have been turned on, if missed?
HA doesn’t (re)schedule “skipped” events for you, so it won’t run an automation tied to a skipped event.
However there are various scenarios where restarting HA can trigger some events to fire such as a device changing from unknown to a known state (on/off), if automations are tied to an event that occurs during (or immediately after) HA startup then automations may run.
There may be an on-startup event, however I am not sure of the details on that.
HA can run automations at startup, as long as HA starting up is the trigger.
triggers:
- trigger: homeassistant
event: start
From here, you can use conditional logic to check when things were last triggered. For example, my roomba has a last mission start time sensor. So if HA is down and it doesn’t occur during it’s scheduled routine, I use a condition like this -
condition: template
value_template: >
{{ not
(as_timestamp(states('sensor.roomba_1_last_mission_start_time'),
0) >= as_timestamp(now().replace(hour=0, minute=0, second=0,
microsecond=0)) and
as_timestamp(states('sensor.roomba_1_last_mission_start_time'),
0) < as_timestamp(now().replace(hour=9, minute=0, second=0,
microsecond=0)) and now().weekday() in [0, 2, 4]) }}
This will check if the roomba was ran at a certain time in the day and if it wasn’t, then the action will commence.
Does the switch.surfside_pool device have a diagnostic sensor with the value of when it was last triggered? No?
Does the switch.surfside_pool device have an attribute that shows when it was last triggered? No?
Create a template sensor or an input_text sensor that prints the last time the switch was turned on.
Use the homeassistant start trigger with a trigger id of ha_start, add a third choose block with the triggered by condition, then add the action. The action you can use is “if-then-else”. The if should be a condition with appropriate logic, basically, it needs to check if the switch was on anytime after 12PM. If the switch was off, the conditional logic should evaluate as true, which would then proceed to the “then” being an action of starting the switch, but if the condition values to false, it will proceed to “else” where you add a Stop action, which stops the sequence.
Here is a simple version that just runs every hour when: minutes = 0:
trigger:
- platform: time_pattern
minutes: 0 # runs at the top of every hour
action:
- choose:
# Between 12:00 and 20:59 → Turn ON
- conditions:
- condition: time
after: "12:00:00"
before: "21:00:00"
sequence:
- action: switch.turn_on
target:
entity_id: switch.surfside_pool
# Between 21:00 and 11:59 → Turn OFF
- conditions:
- condition: time
after: "21:00:00"
before: "12:00:00"
sequence:
- action: switch.turn_off
target:
entity_id: switch.surfside_pool
Most likely HA won’t do anything if you turn on a switch that is already on, but you can add extra checks if its a problem.
The idea here is the pool will at most be off for 1 hour after power is restored.
Depending on how the pool works you might not need to keep turning it off (i.e. if it doesn’t remember it was on before the power outage).
I think we missed the easiest solution to all of this?
Get a cheap UPS and forget about power outages!
edit:
Just re-read your original post and realized — you apparently live in an area where you have power outages that take ages to be fixed?
So I guess my proposed solution wouldn´t work for you, because (depending what you hook up to the UPS) the max. this will run your server is probably an hour or so.
I am not sure how a UPS would solve the problem, even if the outages were shorter.
Since it wouldn’t be sufficient to put the HA server on UPS power, you would also need the pool system on UPS - otherwise when power returns you still need rules to send commands to turn on the pool system - hence you are no better off than letting HA restart and sending the commands when its back online.
HA servers (by itself) are generally low-power, so using (or making ) a decent ups with hours of uptime isn’t too hard. If running on Pi simple 12V 12AH battery will last long time. You don’t have to go “12V → 230V → 5V”, just “12V → 5V” will do. Just one of options is THIS. It’s what i use, together with step-up module to 19V (my Intel nuc wants 19V). It’s even easier if you buy mini PC which runs on 12V
Having “only HA” on UPS can help, since you can create automations in a way that HA knows that power is out and it delays automation until power restores.
Other option is to create “input boolean” helper which automation will set when start, say, Roomba. Then another automation resets it, say, at midnight. By checking this input boolean you’ll know if Roomba has been running today or not.
Agreed. I didn’t come across one which wouldn’t work without ground. Not that’s a good idea, but it’s not that it wouldn’t work. Honestly, i really don’t see why… ground is for protection only.
True, if you have power outages that last minutes or even hours.
I live in a part of the world, where we had 5 or 6 power outages in the last 25 years.
All except one (which took about 1.5 h) only lasted a max. of 5 seconds.
So I guess you could be unlucky, that the automation would be started exactly in those 5 seconds - but that’s like winning the lottery isn’t it?
But as I said - not a solution if you have a grid that goes for such a long time.
But even under those circumstances it may still make sense to use a UPS, to avoid an uncontrolled stop of the HA server when the power goes?