Automations - Add timeout feature to action type - repeat, repeat type options

Would like a timeout option added to Automations GUI editor action type - repeat, repeat type options. E.G repeat “Flash lights” until motion detected (this works) but there are scenarios where there will never be motion detected during certain time periods and a timeout for the repeat would solve this problem of lights flashing for too long.

Similar to the wait timeout option but integrated in the repeat routine. Perhaps there is another way of doing this (please let me know if I have missed anything obvious) but would be nice to have this as an option in the editor GUI for Automations (repeat routine). Thanks!

There is a repeat.index variable. You can do something like this:

- repeat:
    sequence:
      - ...
    until: "{{ is_state('binary_sensor.motion', 'on') or repeat.index == 10 }}"

Not exactly time based, but it’s available today.

You could also do it with a timer:

- service: timer.start
  entity_id: timer.flash
- repeat:
    sequence:
      - ...
    until: >
      {{ is_state('binary_sensor.motion', 'on') or
         is_state('timer.flash', 'idle') }}

Not built-in, but it’s available today.

3 Likes

Thank you for helping. I tried the repeat.index way and it works however when I re-edit my config in the automations GUI it adds the action type template(value template) and the repeat.index setting no longer works.

This works:

- repeat:
      until:
      - condition: or
        conditions:
        - type: is_open
          condition: device
          entity_id: binary_sensor.contact_sensor
          domain: binary_sensor
        - type: is_motion
          condition: device
          entity_id: binary_sensor.motion_sensor1
          domain: binary_sensor
        - type: is_motion
          condition: device
          entity_id: binary_sensor.motion_sensor2
          domain: binary_sensor
        - '{{ repeat.index == 500 }}'

This breaks it after GUI adds “template” action type:

- repeat:
      until:
      - condition: or
        conditions:
        - type: is_open
          condition: device
          entity_id: binary_sensor.contact_sensor
          domain: binary_sensor
        - type: is_motion
          condition: device
          entity_id: binary_sensor.motion_sensor1
          domain: binary_sensor
        - type: is_motion
          condition: device
          entity_id: binary_sensor.motion_sensor2
          domain: binary_sensor
        - condition: template
          value_template: '{{ repeat.index == 500 }}'

I’ll set it using VS editor and not re-edit in automations GUI. 500 = 21 flashes of the lights. So I guess the feature request still stands but have a workable solution for the time being.

Thanks for your time.

1 Like

I don’t see how that could have broken it. One is just a shorthand version of the other.

This is what I thought and I stand corrected, checked it today and it is working fine with the long hand as below, doing the same thing, edit using GUI, save, then restart the automation service, must have been one of those days:

- condition: template
          value_template: '{{ repeat.index == 500 }}'

Thanks again!!

1 Like