Script Repeat Until continues after condition met

I am working on setting up some scripts to repeat an announcement when the scripts are called.
I had no trouble setting up the counted repeat (ref Script Syntax - Home Assistant).

However, when I try to set up the until loop (preferred) or while loop (acceptable alternative) repeat, the loop never stops, and the announcement is continuously repeated until I restart home-assistant.

Here is a sample of my scripts.yaml:

repeat_announcement:
  alias: repeat announcement
  sequence:
  - repeat:
      until:
      - condition: state
        entity_id: input_boolean.default_debounce_10
        state: 'off'
      sequence:
      - service: tts.picotts_say
        data:
          entity_id: media_player.gstreamer
          message: Repeat
  mode: single

I’ve tried various different conditions, changing the entity, changing the state, switching the condition type to time, etc. I continue to get the same results - once I trigger the script (I’ve used the 'run script button from the GUI inside the script editor and in the script ‘list’), it continuously runs, even once the condition is met (in the case above, input_boolean.default_debounce_10 is ‘off’).

I have tested with variations of both the repeat until loop and repeat while loop syntax, as described in the script syntax documentation here: Script Syntax - Home Assistant but I’m clearly doing something wrong.

Does anyone have any suggestions or ideas on what is causing the script to continue repeating even after the condition is met, and how I might fix it?

Thanks so much!

1 Like

Are you sure it’s still repeating and not just whatever automation that is calling it is simply calling it again?

The only thing that maybe is an issue is the indentation levels? I don’t think what you have is wrong though…

repeat_announcement:
  alias: repeat announcement
  sequence:
    - repeat:
        until:
          - condition: state
            entity_id: input_boolean.default_debounce_10
            state: 'off'
        sequence:
          - service: tts.picotts_say
            data:
              entity_id: media_player.gstreamer
              # Say the loop index
              message: "Repeat {{index}}"
  mode: single

There’s no delay within the repeat’s sequence so it executes the service call repeatedly, as fast as your system hardware permits. The result is a flood of TTS messages transmitted to picotts_say. My guess (and it’s only a guess) is it buffers the numerous requests. In other words, even when repeat stops, picotts_say continues to generate the many buffered messages.

To prove/disprove my theory, add a delay of 3 seconds (sufficient time to say the word “Repeat”) to the sequence.

      sequence:
      - service: tts.picotts_say
        data:
          entity_id: media_player.gstreamer
          message: Repeat
      - delay: '00:00:03'

Thank you @jocnnor and @123 ! The lack of delay in my sequence that @123 noted was indeed the cause of the continued repetition, and adding a 2 second delay resolves the issue. Thanks so much for your help.

1 Like