Restore Automation on system restart or power fail

hi…
the HA is amazing…i can’t live without her…
but i have a problem with automation…
i have automation like this :

- id: Grass_Garden_Watering
  alias: Grass Garden Watering
  trigger:
  - at: 04:00
    platform: time
  condition:
  - condition: time
    weekday:
    - mon
    - wed
  action:
  - data:
      entity_id: switch.water_main_ac_power
    service: switch.turn_on
  - delay: '00:00:05'
  - data:
      entity_id: switch.grass_1
    service: switch.turn_on
  - delay: '00:20:00'
  - data:
      entity_id: switch.grass_1
    service: switch.turn_off
  - delay: '00:00:10'
  - data:
      entity_id: switch.grass_2
    service: switch.turn_on
  - delay: '00:20:00'
  - data:
      entity_id: switch.grass_2
    service: switch.turn_off
  - data:
      entity_id: switch.water_main_ac_power
    service: switch.turn_off

so now the automation is start and let say after 10 min the power fail and the system is restart from the failer , the automation never contiune from where he stop…

i think this is a BIGGG ISSUE for all of us…
does it must work like this ?.???

there is antbody that found a way to fix it ?

thanks to all…

To get a more robust automation you could split up the whole automation into multiple smaller ones. It would be interesting to know if the delays you have inserted are necessary for all of this working properly.

A simple approach would be to remove the turn_off part in your existing automation and do that in a separate automation. That separate automation would use the trigger “if switch.grass_1 was on for 20 minutes” and then turn everything off. By doing this the first automation would get everything started. If HASS crashed, the watering would continue (can’t do anything about that when there’s no power). However, when HASS comes back online, it would see that the switches are still turned on, and therefore turn them off 20 minutes after it came bock online.

In my opinion it is mostly the better approach to keep automations small and simple. You can use helpers such as timers, booleans or even the state of groups to make complex things happen with small automations. It also makes you more flexible. If for example you always do the watering at the same time, but in the winter for a shorter duration, the turn-on-automation would stay the same, but the turn-off-automation could be a separate one that depends on something else.