Repeat Trigger UNTIL runs only once and stops

I am trying to repeat below trigger with until condition but when I turn on trigger_test off to on and leave it in that state, loop only runs once and stops. Currently I am on version 0.117.6, appreciate your help:

<automation.yaml>

.........
# Test Trigger
- id: My_Loop_Test_Trigger
  alias: 'My_Loop_Test_Trigger'
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: input_boolean.trigger_test
    to: 'on'
  action:
    - service: persistent_notification.create
      data:
        message: 'My Loop Test Triggered'
        notification_id: '01000'
        title: 'Test'
    - alias: 'Repeat Office Table Lamp UNTIL trigger_test on'
      repeat:
        sequence:
          - service: light.turn_on
            data:
              entity_id:  'light.hue_color_lamp_6'         
              color_name: 'blue'
              brightness: '255'
          - delay: '00:00:01'
          - service: light.turn_on
            data:
              entity_id:  'light.hue_color_lamp_6'         
              color_name: 'red'
              brightness: '255'
          - delay: '00:00:01'
          - service: counter.increment
            entity_id: counter.office_light_on_ctr
          - service: persistent_notification.create
            data:
              message: " My counter is {{  states('counter.office_light_on_ctr') }}"
              notification_id: '01001'
              title: 'Ctr'
        until:
          - condition: state
            entity_id: input_boolean.trigger_test
            state: 'on'

<input_boolean.yaml>

....
  trigger_test:
    name: 'Trigger Test'
    initial: off
    icon: mdi:pistol

Thats because the “until” condition is the trigger_test being on.

If you leave it on then the until condition is met and the repeat stops

Use a different until condition that is not true and it will repeat until it is true.

I changed the until condition to off and it went into loop and working perfectly.

        until:
          - condition: state
            entity_id: input_boolean.trigger_test
            state: 'off'

Thank you for your prompt reply. It fixed my issue.
One more question I have about the syntax immediately after action: the alignment of - service should begin with two spacing or can align to action? All my old automation scripts are working without any issue with alignment to action: as below but documentation shows with two spacing at the beginning. Above test trigger worked with two spacing, I am trying to understand which one is right?

......
  action:
  - service: persistent_notification.create
    data:
      message: 'My Loop Test Triggered'
      notification_id: '01000'
      title: 'Test'
  - alias: 'Repeat Office Table Lamp UNTIL trigger_test on'
    repeat:
      sequence:
.....

you can do it both ways as long as you maintain consistency with all of the code.

I personally prefer to keep everything indented as per the docs example because it keeps everything more human readable friendly.

Thank you for your guidance, it really helps.

1 Like