Can someone help me a bit with my alarm script (siren not repeating for some reason)

Hello all,

I’m hoping someone can give me some guidance on the script below. For some reason, the audio doesn’t seem to be repeating. This is being played on my “everywhere” chromecast group when my alarm is triggered. If possible, it would be nice if someone could review the whole script for junk because I’ll be honest, I don’t really know what I’m doing just yet and pretty much just doing my best with my current abilities.

The lights seem like they are turning red and repeating until I stop them but the audio seems like it stops after 1 cycle. I honestly don’t know if I am using the wait template properly, nor do I know if it is in the correct position. I put 2 seperate “repeat” blocks because the lights default flash time is different than my audio clip so I think this is probably necessary.

Thank you all again for your guidance.

  notification_security_alarm_audio:
    sequence:
      - service: media_player.volume_set
        data_template:
          entity_id: media_player.everywhere_inside_except_tvs
          volume_level: |
            {{ states('input_number.alarm_siren_volume') | float }}
      - repeat:
          until:
            - condition: state
              entity_id: alarm_control_panel.alarmo
              state: disarmed
          sequence:
            - service: light.turn_on
              data:
                rgb_color:
                  - 255
                  - 0
                  - 0
              target:
                entity_id:
                  - light.couch_lamp
                  - light.chair_lamp
                  - light.entry_lamp
            - service: light.turn_on
              data:
                brightness_pct: 100
                flash: long
              target:
                entity_id:
                  - light.chair_lamp
                  - light.couch_lamp
                  - light.entry_lamp
      - repeat:
          until:
            - condition: state
              entity_id: alarm_control_panel.alarmo
              state: disarmed
          sequence:
            - service: media_player.play_media
              data:
                media_content_id: media-source://media_source/sounds/siren.mp3
                media_content_type: music
              target:
                entity_id: media_player.everywhere_inside_except_tvs
            - wait_template: '      - wait_template: ''{{ is_state("media_player.everywhere_inside_except_tvs", "idle") or is_state("media_player.everywhere_inside_except_tvs", "off") or is_state("media_player.everywhere_inside_except_tvs", "paused") }}'''
              continue_on_timeout: true
    mode: single

what does the debugging tell you?

This doesn’t look right !!

Yeah, no doubt. That could’ve been what was causing it. I’m going to give it another test just in a few. Thank you for catching that!

@rossk @nickrout

So I have dumbed this down to the below at this point and it still doesn’t seem to be repeating for some reason. I will post the debugging very shortly.

Thank you all for any guidance you can give me. I am very new to all of this and it’s kicking my butt.

alias: '#TestingAlarmResponse'
sequence:
  - repeat:
      until:
        - condition: state
          entity_id: alarm_control_panel.alarmo
          state: disarmed
      sequence:
        - wait_template: >-
            "{{ is_state("media_player.everywhere_inside_except_tvs", "idle") or is_state("media_player.everywhere_inside_except_tvs", "off") or is_state("media_player.everywhere_inside_except_tvs", "paused") }}"
        - service: media_player.play_media
          data:
            media_content_id: media-source://media_source/sounds/siren.mp3
            media_content_type: music
          target:
            entity_id: media_player.everywhere_inside_except_tvs
mode: single

Try putting a short delay after the playing.

Thank you for your reply. Let me try right quick.
This is driving me bonkers

Also, what is the difference in > and >- when templating?

Don’t know.

Should I get rid of the wait template and just use the delay?

Delay causes it to play for 5 seconds and then it restarts.

So it is fixed?

No, it now restarts after 5 seconds. The audio clip is around 50 seconds.

Should my wait template be a condition?-- No nevermind, that would be stupid.

EDIT:

The below fixed it. In the wait template, I didn’t have it evaluating for a condition. Now I have “==true” and all is well. Thank you all for lending me a hand.

alias: '#TestingAlarmResponse'
sequence:
  - repeat:
      until:
        - condition: state
          entity_id: alarm_control_panel.alarmo
          state: disarmed
      sequence:
        - service: media_player.play_media
          data:
            media_content_id: media-source://media_source/sounds/siren.mp3
            media_content_type: music
          target:
            entity_id: media_player.everywhere_inside_except_tvs
        - wait_template: >-
            {{ is_state("media_player.everywhere_inside_except_tvs", "idle") or 
                is_state("media_player.everywhere_inside_except_tvs", "off") or 
                is_state("media_player.everywhere_inside_except_tvs", "paused")== 'true' }}
mode: single

The last part doesn’t make sense and will not evaluate properly.
is_state is the same as states('xyz') == 'blah'

If you’re looking for it to be ‘paused’ remove the == 'true'

Thank you for responding because I’ll be honest, I have no clue what I’m doing, I would like it to wait if any of those 3 evaluate to true, could you show me how to do that?

Also, this is a random question but if you make a change to a script in the GUI. Do you still have to go and reload the scripts within developer tools? Or does this happen automatically?–> this could’ve been my issue if it doesn’t happen automatically.

Also, I made the change you proposed and all is working perfectly Danny!! Thank you so much!!

Coud you elaborate on the bold paragraph above, I’m really wandering if that was my issue all along.

        - wait_template: >-
            {{ is_state("media_player.everywhere_inside_except_tvs", "idle") or 
                is_state("media_player.everywhere_inside_except_tvs", "off") or 
                is_state("media_player.everywhere_inside_except_tvs", "paused") }}
alias: '#TestingAlarmResponse'
sequence:
  - repeat:
      until:
        - condition: state
          entity_id: alarm_control_panel.alarmo
          state: disarmed
      sequence:
        - service: media_player.play_media
          data:
            media_content_id: media-source://media_source/sounds/siren.mp3
            media_content_type: music
          target:
            entity_id: media_player.everywhere_inside_except_tvs
        - wait_template: |-
            {{ is_state("media_player.everywhere_inside_except_tvs", "idle") or 
                is_state("media_player.everywhere_inside_except_tvs", "off") or 
                is_state("media_player.everywhere_inside_except_tvs", "paused")  }}
mode: single

On your first post. The only thing that stands out is your use of double quotes both outside and inside the template. It let you save like that?

It’s one or the other.

'{{ states(''xyz'')}}' 

or

"{{ states('xyz') }}"

When you click save on the GUI it will reload the scripts for you.

If you notice besides this
- wait_template: ' - wait_template:
You ended your template with 3 quotes.
"paused") }}''' in this case if the wait template syntax was correct it should have been a single quote at the beginning and end of template because you used a double quotes inside the template. " not sure how it let you save with any of these syntax issues.

Thank you for this.

Ok, I thought thats how it was supposed to work but I think I had so many issues with my code was the real problem.

Could you tell me what the difference is between using “| >” or “| >-” or “| -” or even just “|” at the beginning of a template?

What I finally ended up with is below. It seems like it is working properly. But you seem very knowledgeable. Would you review this version please-- it looks like I don’t have any quotes outside of the template but I’m still pretty sure it is working properly.

  notification_security_alarm_audio:
    sequence:
      - service: media_player.volume_set
        data_template:
          entity_id: media_player.everywhere_inside_except_tvs
          volume_level: |
            {{ states('input_number.alarm_siren_volume') | float }}
      - repeat:
          until:
            - condition: state
              entity_id: alarm_control_panel.alarmo
              state: disarmed
          sequence:
            - service: light.turn_on
              data:
                rgb_color:
                  - 255
                  - 0
                  - 0
                flash: long
              target:
                entity_id: light.living_room_lamps
            - delay:
                hours: 0
                minutes: 0
                seconds: 10
                milliseconds: 0
      - repeat:
          until:
            - condition: state
              entity_id: alarm_control_panel.alarmo
              state: disarmed
          sequence:
            - service: media_player.play_media
              data:
                media_content_id: media-source://media_source/sounds/siren.mp3
                media_content_type: music
              target:
                entity_id: media_player.everywhere_inside_except_tvs
            - wait_template: |-
                {{ is_state("media_player.everywhere_inside_except_tvs", "idle") or 
                    is_state("media_player.everywhere_inside_except_tvs", "off") or 
                    is_state("media_player.everywhere_inside_except_tvs", "paused") }}
    mode: single

>

>-
Multi line Jinja template. It tells home assistant there is more than 1 line to be read.

In essence it affects how home assistant reads what’s below it.

I couldn’t tell you yet the difference between | and |- other than I use it as well lol.

You can read more here and ask on discord in templates and a Jinja wizard can answer that. I’m not a Jinja wizard and learned everything from there.

https://yaml.org/spec/1.2.2/#812-literal-style

No problem. Thank you so much for your replies. I am very appreciative of you helping me get that running.

I may drop a message over there and see what they say.

Thank you so much again for being helpful!!

1 Like