Best practice for automations with long delays?

i have a couple automations that (for example) trigger if a switch has been on for a certain amount of time. like this one for my dumb coffee maker:

- alias: auto turn off coffee maker
    platform: state
    entity_id: switch.coffee_maker
    to: 'on'
      minutes: 90
      seconds: 0
    service: switch.turn_off
    entity_id: switch.coffee_maker

the main problem i have with this is that it will never trigger if there’s a crash/reboot.

i figure for this one i could store when it turns ‘on’ as an input_number or input_datetime and check when greater than 90 minutes have passed. but i’m curious what others have done and if there are any clever ways that i’m missing.

may be also trigger event homeassistant start (in case crash/reboot) for 90 minutes. also trigger state switch.coffee_maker to on for 90 minutes.

add condition switch.coffee_maker is on.

action will only happen when switch.coffe_marker is on to turn off the switch.coffee_maker

1 Like

You could add the persistence package

And set it up to keep track of your switch across reboots.