Random delay with days... set the next startpoint instantly

I’m trying to setup some kind of weird randomized delay, it’s breaking my head …

When automation.alpha hasn’t run in 2 days I’m activating input_boolean.bravo. So far so good.

When input_boolean.bravo is activated, I want a random delay from 1-5 days. The random day it’s getting on will be used to activate automation.alpha again at 08.00am.

But if my HA-instance reboots, then there will be no new day appointed (the automation is running/counting down…) to activate automation.alpha again. Setting this up together with an google-calendar would probably tick off all my boxes, but it seems a lot of work for something simple.

Here’s a technique that uses a Time Trigger in order to survive restarting Home Assistant and reloading automations.

When the input_boolean is enabled, set an input_datetime to a date 1-5 days in the future and time at 08:00:00.

alias: example 1
trigger:
  - platform: state
    entity_id: input_boolean.bravo
    to: 'on'
action:
  - service:  input_datetime.set_datetime
    target:
      entity_id: input_datetime.future
    data:
      datetime: "{{ (now() + timedelta(days = range(1,6) | random)).replace(hour=8, minute=0, second=0, microsecond=0).timestamp() | timestamp_local }}"

Use an automation with a Time Trigger that references the input_datetime.

alias: Example 2
trigger:
  - platform: time
    at: input_datetime.future
action:
   ... etc ...

Thank you, way more easy as expected!