Alarm sound loop. Data template not working

Hi everyone,

Would be really grateful if someone can point me in the right direction, been struggling with the most simple template in my scripts.yaml.
Alarm_sound_loop is called as an action when my alarm control panel is triggered. As long as my alarm is in pending state it needs to loop a beeping sound, once triggered it needs to loop the burglar sound.
The script fully works without the data template, so something must be wrong there. Also cannot seem to get the template for the delay to work, that is now commented.

Anybody any input?


alarm_sound_loop:
  alias: Alarm Triggered Sound Loop
  sequence:
    - condition: or
      conditions:
        - condition: state
          entity_id: alarm_control_panel.security_system
          state: 'triggered'
        - condition: state
          entity_id: alarm_control_panel.security_system
          state: 'pending'
    - service: script.turn_on
      entity_id: script.alarm_sound
alarm_sound:
  alias: Alarm Triggered Sound
  sequence:
    - service: media_player.volume_set
      data:
        entity_id: media_player.sonos_beam
        volume_level: 0.2
    - service: media_player.play_media
      data_template:
        entity_id: media_player.sonos_beam
        media_content_type: "music"
        media_content_id: >
          {% if is_state('alarm_control_panel.security_system','pending') %}
            !secret pending_beep_url
          {% else %}
            !secret burglar_alarm_sound_url
          {% endif %}
    - delay: "00:00:05" #>
#        {% if is_state('alarm_control_panel.security_system','pending') %}
#          "00:00:01"
#        {% elif is_state('alarm_control_panel.security_system','triggered') %}
#          "00:00:20"
#        {% else %}
#          "00:00:05"
#        {% endif %}
    - service: script.turn_on
      entity_id: script.alarm_sound_loop

Thanks a lot!

You can’t call a script from within itself.
Call another script which just calls the original.

It’s a different script. alarm_sound_loop calls alarm_sound, which will call alarm_sound_loop again.

Seem to have fixed it now. Apparently you can’t call secrets file from within template. Delay function also now working using seconds instead of the string input.


alarm_sound_loop:
  alias: Alarm Triggered Sound Loop
  sequence:
    - condition: or
      conditions:
        - condition: state
          entity_id: alarm_control_panel.security_system
          state: 'triggered'
        - condition: state
          entity_id: alarm_control_panel.security_system
          state: 'pending'
    - service: script.turn_on
      entity_id: script.alarm_sound
alarm_sound:
  alias: Alarm Triggered Sound
  sequence:
    - service: media_player.volume_set
      data:
        entity_id: media_player.sonos_beam
        volume_level: 0.2
    - service: media_player.play_media
      data:
        entity_id: media_player.sonos_beam
        media_content_type: "music"
      data_template:
        media_content_id: >
          {% if is_state('alarm_control_panel.security_system','pending') %}
            http://192.168.1.3:8123/local/pending_beep.wav
          {% elif is_state('alarm_control_panel.security_system','triggered') %}
            http://192.168.1.3:8123/local/burglar_alarm_sound.mp3
          {% endif %}
    - delay:
        seconds: >
          {% if is_state('alarm_control_panel.security_system','pending') %}
            1
          {% elif is_state('alarm_control_panel.security_system','triggered') %}
            20
          {% endif %}
    - service: script.turn_on 
      entity_id: script.alarm_sound_loop

1 Like