Repeat script while condition is valid - strange behaviour

Hi,

I am about to realize an alarm siren via alexa echo dot. For now, this script is supposed to be triggered manually only.

script_sound_alarm:
  alias: Script - Sound Alarm
  sequence:
  - service: media_player.volume_set
    target:
      entity_id: media_player.echo_dot_1
    data:
      volume_level: 1
  - repeat:
      count: '5'
      sequence:
      - service: media_player.play_media
        data:
          media_content_id: amzn_sfx_scifi_alarm_04
          media_content_type: sound
        target:
          entity_id: media_player.echo_dot_1
  mode: single

This has been set up via HA UI. First thing I realized is, that there is no unique id anymore like all my other scripts still have.
Is this a bug or a feature?

triggering this script does work and the alarm sound is being repeated 5 times (5 seconds per run - total of 20 seconds).
However, during run time, I can’t stop this script via script.turn_off.
Is this a desired behaviour?

In order to have the siren running as long as I stop it, I created a boolean as a condition.

script_sound_alarm:
  alias: Script - Sound Alarm
  sequence:
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.arm_alarm_siren
  - service: media_player.volume_set
    target:
      entity_id: media_player.echo_dot_1
    data:
      volume_level: 1
  - repeat:
      while:
      - condition: state
        entity_id: input_boolean.arm_alarm_siren
        state: 'on'
      sequence:
      - service: media_player.play_media
        data:
          media_content_id: amzn_sfx_scifi_alarm_04
          media_content_type: sound
        target:
          entity_id: media_player.echo_dot_1
  mode: single

When starting this script manually, it starts and also stops based on this boolean according to my logbook but no sound is being played and there’s no error message in my log.
What’s wrong with this configuration?

Best

Just in case someone stumbles over the same issue.
After some testing I figured out, that for the while loop (as well as until loop) one has to add a delay after the first action which is a little longer than the sound file. Then it repeats the sound as long as the boolean is on.

Ah yes, I’ve made that mistake with a Zigbee RGB strip, I wanted to change it to a random colour in a loop. Unfortunately I forgot to add a delay. And the Zigbee light crashed, because it couldn’t cope with thousands of instructions to change the colour of the light every second.

that’s bad. :slight_smile:

the interesting part her for me is, that if you use count instead of a while or until loop the command apparently waits until the sound file is being fully played and only then starts the the next round. Even without adding a delay.