Want to make an automation repeat until a condition exists

Here is my automation. its based on a timer starting (which is triggered by a sensor)
I want to get this to keep doing the siren noise until the timer expires. I have tried to change this but I got a bit lost and not really sure how I can repeat this section as part of the action. Can anyone help~?

**** - service: media_player.play_media**
** target:**
** entity_id:**
** - media_player.back_bedroom**
** - media_player.front_bedroom**
** - media_player.lounge_echo**
** - media_player.mr_s_2nd_echo_dot**
** - media_player.upstairs_hall**
** data:**
** media_content_id: ‘’‘start security siren’’’**
** media_content_type: custom****

----- THE ACTUAL AUTOMATION ----

alias: ALARM_Make Noise
description: ‘’
trigger:

  • platform: state
    entity_id: timer.alarm_noise
    from: idle
    to: active
    for:
    hours: 0
    minutes: 0
    seconds: 1
    milliseconds: 0
    condition:
  • condition: state
    entity_id: alarm_control_panel.home_security_system
    state: armed_away
    for:
    hours: 0
    minutes: 0
    seconds: 1
    milliseconds: 0
    action:
  • service: notify.sms_alert
    data:
    message: Motion has been detected at home
    target: 44xxxxxxx
  • service: notify.whatsapp
    data:
    message: Motion detected at Home
  • service: notify.mobile_app_sm_n976b
    data:
    message: Motion detected at Home
    title: Home security system
  • service: notify.alexa_media_Everywhere
    data:
    message: Attention. Burglar Alarm Activated
    data:
    type: announce
    method: all
  • service: media_player.play_media
    target:
    entity_id:
    - media_player.back_bedroom
    - media_player.front_bedroom
    - media_player.lounge_echo
    - media_player.mr_s_2nd_echo_dot
    - media_player.upstairs_hall
    data:
    media_content_id: ‘’‘start security siren’’’
    media_content_type: custom
    mode: restart
    max: 20

Repeat Until Action… you will probably need to play with the delay time so the calls don’t overlap the sound playing and you may need to add a repeat.index condition. In my experience if Alexa gets too many calls for the same service in a short amount of time it gets treated like a DDOS attack and you will have to reauthorize the integration. If you have one set up, it may work better to just use the media_player.everywhere entity as your target… that has the benefit of sending fewer calls to Amazon and (usually) synced audio.


action:
  - ### Your other Actions
  - repeat:
      sequence:
        - service: media_player.play_media
          target:
            entity_id:
              - media_player.back_bedroom
              - media_player.front_bedroom
              - media_player.lounge_echo
              - media_player.mr_s_2nd_echo_dot
              - media_player.upstairs_hall
          data:
            media_content_id: "start security siren"
            media_content_type: custom
        - delay:
            seconds: 1
      until:
        - condition: state
          entity_id: timer.alarm_noise
          state: "idle"

1 Like

I’ll give this a go tomorrow I did have something similar but every time I put the sequence command it kept putting null after it.
Will let you know how I get on.

Thank You!

Just FYI, if “start security siren” is a trigger phrase for a routine you will need to modify this automation. You can’t execute Alexa routines using the “custom” command, you have to use “routine” as your media_content_type and the routine name as the media_content_id

I wrote the routine exactly how you typed it.
However I keep getting this message on HA
Message malformed: required key not provided @ data[‘action’][3][‘repeat’][‘until’][0][‘entity_id’

This is my exact code and indentation:

alias: ALARM_Make Noise V2
description: ‘’
mode: restart
trigger:

  • platform: state
    entity_id: timer.alarm_noise
    from: idle
    to: active
    for:
    hours: 0
    minutes: 0
    seconds: 1
    milliseconds: 0
    condition:

  • condition: state
    entity_id: alarm_control_panel.home_security_system
    state: armed_away
    for:
    hours: 0
    minutes: 0
    seconds: 1
    milliseconds: 0
    action:

  • service: notify.sms_alert
    data:
    message: Motion has been detected at home
    target: 44MOBILENUMBERREMOVED

  • service: notify.whatsapp
    data:
    message: Motion detected at Home

    • service: notify.mobile_app_sm_n976b
      data:
      message: Motion detected at Home
      title: Home security system
    • service: notify.alexa_media_Everywhere
      data:
      message: Attention. Burglar Alarm Activated
      data:
      type: announce
      method: all
  • Repeating actions below

  • Your other Actions

    • repeat:

      sequence:

      - service: media_player.play_media
      
        target:
      
          entity_id:
      
            - media_player.back_bedroom
      
            - media_player.front_bedroom
      
            - media_player.lounge_echo
      
            - media_player.mr_s_2nd_echo_dot
      
            - media_player.upstairs_hall
      
          data:
      
            media_content_id: "start security siren"
      
            media_content_type: custom
      
      - delay:
      
          seconds: 1
      

      until:

      - condition: state
      
        entity_id: timer.alarm_noise
      
        state: "idle"
      

      max: 20

Please correct the formatting of you post (See #11)

Visible issues:

  • Remove the “### Your other actions” placeholder note
  • Remove the “max: 20”. Are you trying to limit the number of times the action repeats? That can be done, but I don’t see anything in the docs that say you can just set a max like that.

Thank You

My final code including a bit to turn the volume up on all the echo dots was this:

Seems to work well , the issue was I needed to understand the YAML indentations

alias: ALARM_Make Noise V2
description: ''
trigger:
  - platform: state
    entity_id: timer.alarm_noise
    from: idle
    to: active
    for:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
condition:
  - condition: state
    entity_id: alarm_control_panel.home_security_system
    state: armed_away
    for:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
action:
  - service: media_player.volume_set
    data:
      volume_level: 1
    target:
      entity_id:
        - media_player.back_bedroom
        - media_player.lounge_echo
        - media_player.front_bedroom
        - media_player.upstairs_hall
        - media_player.mr_s_2nd_echo_dot
  - service: notify.sms_alert
    data:
      message: Motion has been detected at home
      target: (MOBILE NUMBER REMOVED)
  - service: notify.whatsapp
    data:
      message: Motion detected at Home
  - service: notify.mobile_app_sm_n976b
    data:
      message: Motion detected at Home
      title: Home security system
  - service: notify.alexa_media_Everywhere
    data:
      message: Attention. Burglar Alarm Activated
      data:
        type: announce
        method: all
  - service: persistent_notification.create
    data:
      message: Motion detected
      title: Home Security System
      notification_id: AlertHSS
  - repeat:
      sequence:
        - service: media_player.play_media
          target:
            entity_id:
              - media_player.back_bedroom
              - media_player.front_bedroom
              - media_player.lounge_echo
              - media_player.mr_s_2nd_echo_dot
              - media_player.upstairs_hall
          data:
            media_content_id: start security siren
            media_content_type: custom
        - delay:
            hours: 0
            minutes: 0
            seconds: 30
            milliseconds: 0
      until:
        - condition: state
          entity_id: timer.alarm_noise
          state: idle
          for:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
mode: restart