Repeat alarm sound untill alrm is disarmed

Hey!

Today I was trying to set up the alarm from the home assistant. I was able to play the alarm sound which was stored in my local folder, but for one or another reason i am not able to play the alarm sound in a repeat mode until the alarm is disarmed. Does anyone see what is wrong with the underlying code:

id: '1629637997072'
alias: 'Alarm triggered: armed_away'
description: ''
trigger:
  - type: opened
    platform: device
    device_id: 247bc206bbcbe88081f7fad00e8bcbcf
    entity_id: binary_sensor.window_door_sensor_front_door
    domain: binary_sensor
condition:
  - condition: state
    entity_id: alarm_control_panel.home_alarm
    state: armed_away
action:
  - service: notify.mobile_app_le2113
    data:
      message: 'Alarm on: intruder detected'
      title: Alarm
  - service: media_player.volume_set
    target:
      entity_id: media_player.living_room
    data:
      volume_level: 0.28
  - repeat:
      until:
        - condition: state
          entity_id: alarm_control_panel.home_alarm
          state: disarm
      sequence:
        - service: media_player.play_media
          target:
            entity_id: media_player.living_room
          data:
            media_content_id: http://192.168.68.110:8123/local/alarmsound.mp3
            media_content_type: music
mode: single

Thanks in advance:

This

Should be:

  - repeat:
      until:
        - condition: state
          entity_id: alarm_control_panel.home_alarm
          state: disarmed

Look here for the states of your entities:

Open your Home Assistant instance and show your state developer tools.

Thank you but still no luck. I can play the file via call service, but one I add repeat (independent of whether it is for the alarm being disarmed or just a count (like 100 times) it does not work.

You probably need to wait until your file stops playing before playing it again:

  - repeat:
      until:
        - condition: state
          entity_id: alarm_control_panel.home_alarm
          state: disarmed
      sequence:
        - service: media_player.play_media
          target:
            entity_id: media_player.living_room
          data:
            media_content_id: http://192.168.68.110:8123/local/alarmsound.mp3
            media_content_type: music
        - wait_template: "{{ is_state('media_player.living_room', 'idle') }}"

You can trace out what is happening by clicking the clock icon to the right of your automation in the list here:

Open your Home Assistant instance and show your automations.

1 Like

Thanks again for the fast response. I will try that.

Might have something to do with the setup of my HA. I run the HA in a container via docker. The host is a mac book air (i guess from around 2015) with ubuntu installed on it. When I activate the automation, this happens:

When I disarm, the CPU goes back to more normal levels (+/- 15%) (i disarmed around 11:39 - no idea what the drop is around 11:37).

Yeah, try it with the wait template. It would be absolutely spamming your media player with play requests without some sort of delay.

I ended up creating a new alarm sound file with all the previous alarm sounded pasted after each other. Now the file is 30 minutes long. That should in principle suffice for my police-loving neighbors to inform the police if something would be wrong. I also created a second automation to end the alarm if it would be playing at the moment the alarm is disarmed. My cpu is now at normal levels.

Thanks anyway for the help. Guess the repeat function will reveal itself another time :wink:

I was hoping you would find the answer with a wait or delay. Guess I will go extend my sound files. dang.

There is an answer above: