Repeat Security alarm Automation until disarmed

Hi there,

I’m after some help with this automation below

- alias: Warning There Is A Security Breach 1
  trigger:
    platform: state
    entity_id: alarm_control_panel.intruder_alarm
    to: 'triggered'
  action:
    - service: media_player.volume_set
      data_template:
        entity_id: 
          - media_player.family_room_speaker
        volume_level: 1
    - service: media_player.play_media
      data_template:
        entity_id: media_player.family_room_speaker
        media_content_id: https://mobcup.net/d/onnookjc/mp3
        media_content_type: 'audio/mp3'
    - delay:
        seconds: 10
    -  service: tts.google_say
       entity_id: 
          - media_player.family_room_speaker
       data:
        message: 'Warning There Is A Security Breach'

the above works but does not repeat i need to add the a repeat code I attempted below but doesn’t work

  - repeat:
        sequence:
    - service: media_player.play_media
      data_template:
        entity_id: media_player.family_room_speaker
        media_content_id: https://mobcup.net/d/onnookjc/mp3
        media_content_type: 'audio/mp3'
    - delay:
        seconds: 10
    -  service: tts.google_say
       entity_id: 
          - media_player.family_room_speaker
       data:
        message: 'Warning There Is A Security Breach'   
            until:
          - condition: state
            entity_id: alarm_control_panel.intruder_alarm
            state:  'diasrmed'        
        

please save me I just need this automation to keep repeating until

entity_id: alarm_control_panel.intruder_alarm
            state:  'diasrmed'    

any help will be so muchly appreciated

Can you try this? Please be careful with the indentation, do it like this:


Then, copy everything the YAML below this-

alias: New Automation
description: ''
mode: single
trigger:
  - platform: state
    entity_id: 'alarm_control_panel.intruder_alarm'
    to: 'triggered'
    
condition: []

action:
  - repeat:
      until:
        - condition: state
          entity_id: 'alarm_control_panel.intruder_alarm'
          state: 'disarmed'
      sequence:
        - service: media_player.play_media
          data:
            entity_id: media_player.family_room_speaker
            media_content_id: https://mobcup.net/d/onnookjc/mp3
            media_content_type: music
        - delay:
             seconds: 10
        - service: tts.google_say
          data:
            entity_id: media_player.family_room_speaker
            message: 'Warning There Is A Security Breach' 
  1. Can you tell me what error shows up in the log?
  2. Can you try to download the mp3 file and store it locally in your HA folder?

Hi thanks for your help much appreciate your time.
I will at some point move audio files to my server I guess they would go into a www folder or something .
Anyway added code below as per your suggestion.


- alias: Security New Automation
  description: '' 
  mode: single
  trigger:
    - platform: state
      entity_id: 'alarm_control_panel.intruder_alarm'
      to: 'triggered'
  condition: []
  action:
    - repeat:
        until:
          - condition: state
            entity_id: 'alarm_control_panel.intruder_alarm'
            state: 'disarmed'
        sequence:
          - service: media_player.media_play
            data:
              entity_id: media_player.family_room_speaker
              media_content_id: https://mobcup.net/d/onnookjc/mp3
              media_content_type: music
          - delay:
               seconds: 10
          - service: tts.google_say
            data:
              entity_id: media_player.family_room_speaker
              message: 'Warning There Is A Security Breach' 

I get error in log when alarm is triggered

2021-07-18 18:47:19 ERROR (MainThread) [homeassistant.components.automation.security_new_automation] Security New Automation: Repeat at step 1: Error executing script. Invalid data for call_service at pos 1: extra keys not allowed @ data['media_content_id']

2021-07-18 18:47:19 ERROR (MainThread) [homeassistant.components.automation.security_new_automation] Security New Automation: Error executing script. Invalid data for repeat at pos 1: extra keys not allowed @ data['media_content_id']

2021-07-18 18:47:19 ERROR (MainThread) [homeassistant.components.automation.security_new_automation] Error while executing automation automation.security_new_automation: extra keys not allowed @ data['media_content_id']

Hope this looks ok as using my phone :smiley:

Sorry, the service should be:

service: media_player.play_media

not service: media_player.media_play

Lol :rofl: just fixed that easy mistake, when run I get no errors in log and google speakers beeps then after some delay says
Warning There Is A Security Breach

Then after some time it started working, playing mp3 link and message but with delays .
I’ll have a bit more of a play with it and maybe I’ll try moving the audio files onto my server hopefully that fixes any delays . But seems like it’s basically there .
Thank you very much

Yes, you should consider storing the .mp3 file locally in /config/www. The reason is because if the website is down and HA cannot retriever the file, it will prevent the automation to continue the repeat function.

After moving it to /config/www, change media_content_id to this-
media_content_id: http://HAIP:8123/local/xxx.mp3

wow thank you so so much made my life so much easer and i learnt some stuff too.
it now works perfectly no lag and repeats until disarming system incase some one in future needs it here’s the working code all thanks too ardysusilo

- alias: Security New Automation
  description: '' 
  mode: single
  trigger:
    - platform: state
      entity_id: 'alarm_control_panel.intruder_alarm'
      to: 'triggered'
  condition: []
  action:
    - repeat:
        until:
          - condition: state
            entity_id: 'alarm_control_panel.intruder_alarm'
            state: 'disarmed'
        sequence:
          - service: media_player.play_media
            data:
              entity_id: media_player.family_room_speaker
              media_content_id: http://0.0.0.0:8123/local/SecurityAlarm.mp3
              media_content_type: music
          - delay:
               seconds: 10
          - service: tts.google_say
            data:
              entity_id: media_player.family_room_speaker
              message: 'Warning There Is A Security Breach'
1 Like

Suggestion:

Given that this automation involves the security of your home, consider making it slightly more robust by eliminating its reliance on repeatedly translating the warning message (each execution of tts.google_say depends on a functional Internet connection).

The Google Translate app allows you to download a spoken phrase. You can store the media file locally and then play it in the same way the automation currently plays SecurityAlarm.mp3.

2 Likes

Cool definitely be doing that I have default paradox :rotating_light: programed at a 1 minutes delay so if after that time the big horrible sounders kick in. Thank you for you suggestion much appreciated