Automation - trigger on event and repeat until done

I’m looking for a solution for a reminder automation that I’m trying to isolate into a single automation and also without having to create any external boolean.

This is the use-case:
Whenever switch.test is changed to on, a reminder shall be sent out (using the notify service) at the event and then every 30 minute until switch.test has been turned off.

The constraints are:
a) Only using one Automation, since creating a second automation (e.g. for the second reminders) will clutter the HA environment.
b) Not using any “external” boolean, once again since this will clutter the HA environment
c) The trigger shall not leave any traces in the history if the switch is turned of. I.E. only execute as long as the switch is not turned off, then just rest

I guess there are two programmatic schematic solutions for this and booth are recursive, something I guess automation does not support. Anyone that has a better idea or if it would be worth requesting recursive automations

  1. Recursive calls to the automation: The automation will trigger on the state change, but then the automation will call itself with a 30 minute delay until the switch has been turned of. From the GUI I can trigger the automation manually, but is that possible from within an automation action?

  2. Recursively calling an action: Something like below, but with the actions executed recurvsivly

automation:
  - alias: "Turn off reminder"
    trigger:
      - platform: state
        entity_id: switch.test
        to: 'on'
    action:
      - service: notify.notify
        data:
          title: "Reminder"
          message: "Please turn off the switch"
      - delay:
          minutes: 30
      - condition: state
        entity_id: switch.test
        state: 'on'
      - action:
        - service: notify.notify
          data:
            title: "Reminder"
            message: "Please turn off the switch"
        - delay:
            minutes: 30
        - condition: state
          entity_id: switch.test
          state: 'on'
        - action:
          ...

This may not be exactly what you are asking for, but have you considered the Alert integration?

1 Like

Alert looks promising, thanks a lot.

I also turned to chatGPT and finally got this this suggestion that looks promising after a very long chat:-). I will test both.

automation:
  - alias: "Turn off reminder"
    trigger:
      - platform: state
        entity_id: switch.test
        to: 'on'
    action:
      - service: notify.notify
        data:
          title: "Reminder"
          message: "Please turn off the switch"
      - repeat:
        - delay:
            minutes: 30
        - condition: state
          entity_id: switch.test
          state: 'on'
        - service: notify.notify
          data:
            title: "Reminder"
            message: "Please turn off the switch"


There are several kinds of repeat and ChatGPT gave you an example of none of them.

Reference: Repeat a group of actions

1 Like

:slight_smile: Yes i noticed that. I better not trust it in the feature. ChatGPT is kind of always trying to find an answer and doesn’t care if it’s right or not. Kind of good at guessing I would say.

Thanks for the link the the repeat definition

ChatGPT formulates its response based on a statistical analysis of information that is related to your request. So far, the answers it produces for questions involving Home Assistant’s scripting language are quite consistently incorrect. On the surface the answer appear to be legitimate but on closer inspection it’s usually nonsense.

1 Like

Hi,
i’m trying to done the same ,
but with start time info, or delay from start time
, i didn’t achive to find the way
end of the automation …(you will constat i m not very aware…)

repeat:
  while:
    - condition: state
      entity_id: switch.0x9035eafffefd8df2
      state: "on"
      for:
        hours: 0
        minutes: 0
        seconds: 0
  sequence:
    - variables: {% set t = strptime(states('sensor.time'), '%H:%M') %}  
    - service: notify.mobile_app_xxx
      data:
        message: Attention Arrosage a commencer a {{ t.hour }} H {{ t.minute }} mn
    - service: notify.mobile_app_yyyy
      data:
        message: Attention Arrosage a commencer a {{ t.hour }} H {{ t.minute }} mn
      enabled: false
    - delay:
        hours: 0
        minutes: 1
        seconds: 0
        milliseconds: 0
      enabled: true