###############################################################################
#   @author         :   Jeffrey Stone 
#   @date           :   03/13/2019
#   @package        :   Security
#   @description    :   Everything related to security functions. 
###############################################################################

input_boolean:
  sentry_mode:
    name: Sentry Mode
    icon: mdi:security
  vacation_mode:
    name: Vacation Mode
    icon: mdi:airplane-takeoff
  guest_mode:
    name: Guest Mode
    icon: mdi:account-multiple
  security_alarm:
    name: Security Alarm
    icon: mdi:speaker-wireless
  fire_alarm:
    name: Fire Alarm
    icon: mdi:speaker-wireless
  garage_after_dark:
    name: Garage Open After Dark
    icon: mdi:message-alert
  lockdown_issue:
    name: Lockdown Issue
    icon: mdi:lock-reset
  security_issue:
    name: Security Issue
    icon: mdi:alert-circle-outline
  dog_mode:
    name: Dog Mode
    icon: mdi:dog-side


alarm_control_panel:
  # - platform: arlo
  #   home_mode_name: home
  #   away_mode_name: armed
  - platform: aarlo
    home_mode_name: home
    away_mode_name: Armed
 

automation:
  - id: enable_vacation_mode
    alias: Enable Vacation Mode
    initial_state: true
    trigger:
    - platform: numeric_state
      entity_id: sensor.jeff_ett_home
      above: 180
    - platform: numeric_state
      entity_id: sensor.kat_ett_home
      above: 180
    condition:
    - condition: numeric_state
      entity_id: sensor.jeff_ett_home
      above: 180
    - condition: numeric_state
      entity_id: sensor.kat_ett_home
      above: 180
    action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.vacation_mode
  
  - id: morning_standby
    alias: Morning Standby
    initial_state: true
    trigger:
    - platform: time
      at: 05:30:00
    condition:
      condition: or
      conditions:
      - condition: state
        entity_id: sensor.family_status
        state: Home
      - condition: state
        entity_id: person.jeffrey
        state: home
      - condition: state
        entity_id: person.katherine
        state: home
      - condition: state
        entity_id: input_boolean.guest_mode
        state: 'on'
    action:
    - service: script.standby

  - id: nightly_lockdown
    alias: Nightly Lockdown
    initial_state: true
    trigger:
    - platform: time
      at: '23:00:00'
    condition:
    - condition: state
      entity_id: person.jeffrey
      state: home
    - condition: state
      entity_id: person.katherine
      state: home
    - condition: state
      entity_id: input_boolean.guest_mode
      state: 'off'
    - condition: state
      entity_id: input_boolean.sentry_mode
      state: 'off'
    action:
    - service: script.lockdown
    - delay:
        seconds: 2
    - service: script.security_check_failed

  - id: garage_open_sunset
    alias: Garage Open At Sunset
    initial_state: true
    trigger:
    - platform: sun
      event: sunset
    condition:
    - condition: state
      entity_id: binary_sensor.garage_door
      state: "on"
    action:
    - service: script.driveway_on
    

  - id: close_garage_lights_out
    alias: Close Garage at lights out
    initial_state: true
    trigger:
    - platform: time
      at: '22:30:00'
    condition:
    - condition: state
      entity_id: binary_sensor.garage_door
      state: "on"
    action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.garage_after_dark

  - id: door_chime
    alias: Door Chine
    trigger:
    - platform: state
      entity_id:
      - binary_sensor.front_door
      - binary_sensor.laundry_room_door
      - binary_sensor.attic_door
      - binary_sensor.back_door
      to: 'on'
    condition:
      condition: and
      conditions:
      - condition: state
        entity_id: input_boolean.audible_notifications
        state: 'on'
      - condition: state
        entity_id: input_boolean.guest_mode
        state: 'off'
      - condition: or
        conditions:
        - condition: state
          entity_id: media_player.ha_speaker
          state: 'idle'
        - condition: state
          entity_id: media_player.ha_speaker
          state: 'off'
    action:
    - service: script.door_chime
    initial_state: true

  - id: door_opened_long
    alias: Door Opened Too Long
    trigger:
    - platform: state
      entity_id:
      - binary_sensor.front_door
      - binary_sensor.laundry_room_door
      - binary_sensor.attic_door
      - binary_sensor.back_door
      from: 'off'
      to: 'on'
      for: '00:01:00'
    condition:
    - condition: state
      entity_id: input_boolean.audible_notifications
      state: 'on'
    action:
    - service: script.jarvis_voice
      data_template:
        who: '{{ states.sensor.room_audio.state }}'
        message: >
          The {{ trigger.to_state.attributes.friendly_name }}
          {{ [
          " is standing open.",
          " is open.",
          " does not close on its own.",
          " was left standing open "
          ] | random }}
          {{ [
              'Can we get any more moths in here?',
              'Can a human be so kind and close it?',
              'The air quality in this house has actually improved.',
              'Closing the door would improve the internal climate of the house.',
              'Hey. The door was just opened and this is crazy. But now you know. So close it maybe.',
              'They always say when one door closes another one opens...that must of been waht happened',
              'And the automatic door closer appears to be broken. So...'
          ] | random }}

    initial_state: true

  
  - id: motion_detected_sentry_mode
    alias: motion_detected_sentry_mode
    trigger:
    - platform: state
      entity_id:
      - binary_sensor.aarlo_motion_front_door
      - binary_sensor.aarlo_motion_driveway
      from: 'off'
      to: 'on'
    mode: single
    condition:
    - condition: state
      entity_id: input_boolean.audible_notifications
      state: 'on'
    - condition: state
      entity_id: binary_sensor.front_door
      state: 'off'
    - condition: state
      entity_id: input_boolean.sentry_mode
      state: 'on'
    action:
    - service: script.jarvis_voice
      data_template:
        who: '{{ states.sensor.room_audio.state }}'
        message: >
          {{ [
          "I have detected motion at the ",
          "Someone may be at the ",
          "There is movement at the ",
          "My sensors are picking up motion at the ",
          "We appear to have a visitor at the "
          ] | random }}
          {{ trigger.to_state.attributes.friendly_name }}.
          {{ [
              'Do you want me to send them away?',
              'I have armed the lasers. Just say the word.',
              'I was not informed there would be guests.',
              'They do not appear to have any gifts, so I suggest no opening the door.',
              'My sensors have detected a meat popsicle.',
              'I do not think they can hear me.'
            ] | random }}
    - delay:
        minutes: 2
    initial_state: true
  
  - id: garage_opened_night
    alias: Garage Opened at Night
    trigger:
    - platform: state
      entity_id: group.garage_doors
      from: 'off'
      to: 'on'
    condition:
    - condition: state
      entity_id: sun.sun
      state: below_horizon
    action:
    - service: script.driveway_on
    initial_state: true

  - id: garage_closed
    alias: Garage Opened at Night
    trigger:
    - platform: state
      entity_id: group.garage_doors
      from: 'on'
      to: 'off'
    action:
    - service: script.driveway_off
    initial_state: true

  - id: security_breach_door
    alias: Security Breach Doors
    trigger:
    - platform: state
      entity_id:
      - binary_sensor.front_door
      - binary_sensor.back_door
      - binary_sensor.side_door
      - binary_sensor.garage_door
      to: 'on'
    condition:
    - condition: state
      entity_id: input_boolean.sentry_mode
      state: 'on'
    - condition: state
      entity_id: input_boolean.dog_mode
      state: 'off'
    action:
    - service: script.jarvis_alert
      data_template:
        message: "My security protocols are being overidden,, The {{ trigger.to_state.attributes.friendly_name }} has been opened."
    - service: script.text_alert
      data_template:
        title: "Security Alert!!"
        message: "{{ trigger.to_state.attributes.friendly_name }} has been opened."
    - service: input_boolean.turn_on
      entity_id: input_boolean.security_issue
    initial_state: true

  - id: security_response_on
    alias: Security Response On
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_boolean.security_issue
      from: 'off'
      to: 'on'
    action:
    - service: script.turn_on
      entity_id: script.security_response
    - service: scene.turn_on
      entity_id: scene.lr_red

  - id: security_response_off
    alias: Security Response Off
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_boolean.security_issue
      from: 'on'
      to: 'off'
    action:
    - service: script.turn_off
      entity_id: script.security_response
    - service: media_player.media_stop
      entity_id: media_player.ha_speaker
    - service: input_boolean.turn_off
      entity_id: input_boolean.security_alarm
    - service: scene.turn_on
      entity_id: scene.normal_livingroom_lighting

  - id: sentry_mode_enabled
    alias: Sentry Mode Enabled Annoucement
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_boolean.sentry_mode
      from: 'off'
      to: 'on'
    action:
    - service: script.jarvis_voice
      data_template:
        who: '{{ states.sensor.room_audio.state }}'
        message: >
          {{ [
          "Barn door protocol has been activated.",
          "Anchorage House has been secured! ",
          "Sentry Mode is active. ",
          "I am now monitoring the doors and will let you know if anyone attempts to access.",
          "Anchorage House Shields are up."
          ] | random }}
    - service: script.text_notify
      data_template:
        who: "parents"
        title: "Security Armed"
        message: "Security System has been armed."    

  - id: sentry_mode_disabled
    alias: Sentry Mode Disabled Annoucement
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_boolean.sentry_mode
      from: 'on'
      to: 'off'
    
    action:
    - service: script.jarvis_voice
      data_template:
        who: '{{ states.sensor.room_audio.state }}'
        message: >
          {{ [
          "Barn door protocol has been deactivated.",
          "I am no longer monitoring the access points. ",
          "Sentry Mode has been disabled. ",
          "Anchorage House Shields are down."
          ] | random }}
    - service: script.text_notify
      data_template:
        who: "parents"
        title: "Security Disarmed"
        message: "Security System as been disarmed."  

  - id: guest_mode_feedback
    alias: Guest Mode Audio Feedback
    trigger:
      - platform: state
        entity_id:
          - input_boolean.guest_mode
        from: 'off'
        to: 'on'
    action:
      - service: script.jarvis_voice
        data_template:
          who: '{{ states.sensor.room_audio.state }}'
          message: >
            {{ [
            "Guest Mode has been enabled.",
            "I have switched to the system to guest mode.",
            "I have enabled guest mode. ",
            "Guest Mode is on."
            ] | random }}

  - id: dog_mode_deactivated
    alias: Dog mode Deactivated
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_boolean.dog_mode
      to: 'on'
    action:
    - delay:
        minutes: 20
    - service: input_boolean.turn_off
      entity_id: input_boolean.dog_mode
    
  
  - id: security_alarm_on
    alias: Security alarm On
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_boolean.security_alarm
      to: 'on'
    action:
    - service: script.turn_on
      entity_id: script.notification_security_alarm_audio
  
  - id: security_alarm_off
    alias: Security alarm Off
    initial_state: true
    trigger:
    - platform: state
      entity_id: sensor.security_alarm
      to: 'off'
    action:
    - service: script.turn_off
      entity_id: script.notification_security_alarm_audio
    - service: media_player.media_stop
      entity_id: media_player.ha_speaker

  # - id: Kitchen_Alarm_Smoke
  #   alias: Kitchen Alarm Smoke
  #   initial_state: true
  #   trigger:
  #   - platform: state
  #     entity_id: sensor.kitchen_smoke_smoke_detector
  #     to: 'smoke'
  #   action:
  #   - service: input_boolean.turn_on
  #     entity_id: input_boolean.fire_alarm
  #   - service: script.text_alert
  #     data_template:
  #       title: Security Alert - Smoke
  #       message: Smoke Detected in Kitchen!!
  #   - service: script.jarvis_alert
  #     data_template:
  #       message: Smoke Detected in Kitchen!
  #   - delay:
  #       seconds: 5
  #   - service: script.fire_alarm
  #   - delay:
  #       seconds: 15
  #   - service: notify.alexa_media_everywhere
  #     data:
  #       message: Smoke Detected in Kitchen
  #       data:
  #         type: announce


  # - id: Kitchen_Alarm_Co
  #   alias: Kitchen Alarm CO
  #   initial_state: true
  #   trigger:
  #   - platform: state
  #     entity_id: sensor.kitchen_smoke_carbon_monoxide_detector
  #     to: 'co2'
  #   action:
  #   - service: input_boolean.turn_on
  #     entity_id: input_boolean.fire_alarm
  #   - service: script.text_alert
  #     data_template:
  #       title: Security Alert - CO
  #       message: CO Detected in Kitchen!!
  #   - service: script.jarvis_alert
  #     data_template:
  #       message: Carbon Dioxide Detected in Kitchen!
  #   - delay:
  #       seconds: 5
  #   - service: script.fire_alarm
  #   - delay:
  #       seconds: 15
  #   - service: notify.alexa_media_everywhere
  #     data:
  #       message: Carbon Dioxide Detected in Garage
  #       data:
  #         type: announce

  # - id: Garage_Alarm_Smoke
  #   alias: Garage Alarm Smoke
  #   initial_state: true
  #   trigger:
  #   - platform: state
  #     entity_id: sensor.garage_smoke_smoke_detector
  #     to: 'smoke'
  #   action:
  #   - service: input_boolean.turn_on
  #     entity_id: input_boolean.fire_alarm
  #   - service: script.text_alert
  #     data_template:
  #       title: Security Alert - Smoke
  #       message: Smoke Detected in Garage!!
  #   - service: script.jarvis_alert
  #     data_template:
  #       message: Smoke Detected in Garage!
  #   - delay:
  #       seconds: 5
  #   - service: script.fire_alarm
  #   - delay:
  #       seconds: 15
  #   - service: notify.alexa_media_everywhere
  #     data:
  #       message: Smoke Detected in Garage
  #       data:
  #         type: announce

  # - id: Garage_Alarm_Co
  #   alias: Garage Alarm CO
  #   initial_state: true
  #   trigger:
  #   - platform: state
  #     entity_id: sensor.garage_smoke_carbon_monoxide_detector
  #     to: 'co2'
  #   action:
  #   - service: input_boolean.turn_on
  #     entity_id: input_boolean.fire_alarm
  #   - service: script.text_alert
  #     data_template:
  #       title: Security Alert - CO
  #       message: CO Detected in Garage!!
  #   - service: script.jarvis_alert
  #     data_template:
  #       message: Carbon dioxide Detected in Garage!
  #   - delay:
  #       seconds: 5
  #   - service: script.fire_alarm
  #   - delay:
  #       seconds: 15
  #   - service: notify.alexa_media_everywhere
  #     data:
  #       message: Carbon Dioxide Detected in Garage
  #       data:
  #         type: announce
    
  - id: water_leak_detected
    alias: Welcome Home
    trigger:
      - platform: state
        entity_id:
          - binary_sensor.0x286d9700010c9f39_water_leak
        from: 'off'
        to: 'on'
    action:
      - service: script.text_notify
        data_template:
          who: "parents"
          title: "Water Leak!!!!"
          message: > 
            {% set location = trigger.to_state.attributes.friendly_name %}
            location + has detected a leak
      - service: script.jarvis_alert
        data_template:
          message: >
            {% set location = trigger.to_state.attributes.friendly_name %}
            {%- macro issue_report(location) -%}
              {{ [
                  'I have detected an issue!',
                  'We have a problem!',
                  'You might not like this.',
                  'There is something that needs your attention.'
                  ] | random }}
              {{ [
                location + " is detecting a leak.",
                location + " has detected water.",
                location + " is picking up water."
                ] | random }}
            {%- endmacro -%}
            {{issue_report(location)}}

  - id: '1558630577206'
    alias: Garage Is Open at 9pm
    initial_state: true
    trigger:
    - at: '21:00:00'
      platform: time
    condition:
    - condition: state
      entity_id: binary_sensor.garage_door_contact
      state: 'on'
    action:
    - data:
        entity_id: input_boolean.garage_after_dark
      service: input_boolean.turn_on
  - id: '1559612300685'
    alias: Garage Closed
    initial_state: true
    trigger:
    - entity_id: binary_sensor.garage_door_contact
      from: 'on'
      platform: state
      to: 'off'
    condition: []
    action:
    - data:
        entity_id: input_boolean.garage_after_dark
      service: input_boolean.turn_off

script:
  door_chime:
    sequence:
    - condition: state
      entity_id: input_boolean.audible_notifications
      state: 'on'
    - service: media_player.turn_on
      entity_id: media_player.ha_speaker
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.ha_speaker
        volume_level: .5
    - service: media_player.play_media
      entity_id: media_player.ha_speaker
      data:
        media_content_id: /media/sounds/door_open.wav
        media_content_type: "music"



  lockdown_issue:
    sequence:
    - condition: state
      entity_id: group.external_doors
      state: "on"
    - condition: state
      entity_id: sensor.family_status
      state: "Away"
    - service: input_boolean.turn_on
      entity_id: input_boolean.lockdown_issue
    - service: script.text_notify
      data_template:
        title: "Lockdown Issue!"
        message: "Doors are open and it appears everyone has left!"

  # fire_alarm:
  #   sequence:
  #   - condition: state
  #     entity_id: input_boolean.fire_alarm
  #     state: "on"
  #   - service: media_player.turn_on
  #     entity_id: media_player.ha_speaker
  #   - service: media_player.volume_set
  #     data_template:
  #       entity_id: media_player.ha_speaker
  #       volume_level: .75
  #   - service: media_player.play_media
  #     entity_id: media_player.ha_speaker
  #     data:
  #       media_content_id: http://192.168.7.40/audio/fire_alarm.mp3
  #       media_content_type: "music"

  security_check_garage:
    sequence:
    - condition: state
      entity_id: binary_sensor.garage_door_contact
      state: 'on'
    - service: input_boolean.turn_on
      entity_id: input_boolean.lockdown_issue
  
  security_check_zones:
    sequence:
    - condition: state
      entity_id: group.doors
      state: 'on'
    - service: input_boolean.turn_on
      entity_id: input_boolean.lockdown_issue

  lockdown:
    sequence:
    - condition: state
      entity_id: group.external_doors
      state: "off"
    - service: input_boolean.turn_on
      entity_id: input_boolean.sentry_mode
    - service: alarm_control_panel.aarlo_set_mode
      data: 
        entity_id: alarm_control_panel.aarlo_ah_base_station
        mode: 'Armed'

  standby:
    sequence:
    - service: script.vacation_canceled
    - service: script.disarm_security
    - service: input_boolean.turn_off
      entity_id: input_boolean.lockdown_issue
    - service: alarm_control_panel.aarlo_set_mode
      data:
        entity_id: alarm_control_panel.aarlo_ah_base_station
        mode: 'home'
  
  disarm_security:
    sequence:
    - condition: state
      entity_id: input_boolean.sentry_mode
      state: 'on'
    - service: input_boolean.turn_off
      entity_id: input_boolean.sentry_mode
   

  visitors_here:
    sequence:
    - service: input_boolean.turn_on
      data:
        entity_id: input_boolean.guest_mode
    #- service: shell_command.haunted_guest_welcome

  visitors_gone:
    sequence:
    - service: input_boolean.turn_off
      data:
        entity_id: input_boolean.guest_mode

  notification_security_alarm_audio:
    sequence:
    - service: media_player.turn_on
      entity_id: media_player.ha_speaker
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.ha_speaker
        volume_level: .75
    - service: media_player.play_media
      entity_id: media_player.ha_speaker
      data:
        media_content_id: http://192.168.7.40/audio/security_siren.mp3
        media_content_type: "music"

  vacation_canceled:
    sequence:
    - condition: state
      entity_id: input_boolean.vacation_mode
      state: 'on'
    - data:
        entity_id: input_boolean.vacation_mode
      service: input_boolean.turn_off

  activate_barn_door_protocol:
    sequence:
    - service: script.jarvis_voice
      data_template:
        who: '{{ states.sensor.room_audio.state }}'
        message: >-
          {{ [
                'Okay.', 
                'If you insist.',
                'I am afraid I can not do that <break time="1s"/> I am kidding,',
                'Leave it to me.',
                'As you wish.',
                'I am on it.',
                'No Problem.',
                'I think I can handle that.',
                'Working on it now.',
                '<break time="2s"/> Oh, you were talking to me. Let me take care of that.'
                'Why not. It is not like <emphasis>I</emphasis> ever sleep.',
                'I am not even supposed to be here today. But whatever.',
                'You did not say the magic word. <break time="1s"/> Oh forget it. I will take care of it.',
                'Funny, I was just about to do that.',
                'There are still terabytes of calculations required before I can.<break time="1s"/> Oh, whatever.'
                ] | random }}
    - delay:
        seconds: 2
    - service: script.lockdown
    - delay:
        seconds: 2
    - service: script.security_check_failed

  deactivate_barn_door_protocol:
    sequence:
    - condition: state
      entity_id: sensor.family_status
      state: "Home"
    - service: script.jarvis_voice
      data_template:
        who: '{{ states.sensor.room_audio.state }}'
        message: >-
          {{ [
                'Okay.', 
                'If you insist.',
                'I am afraid I can not do that <break time="1s"/> I am kidding,',
                'Leave it to me.',
                'As you wish.',
                'I am on it.',
                'No Problem.',
                'I think I can handle that.',
                'Working on it now.',
                '<break time="2s"/> Oh, you were talking to me. Let me take care of that.'
                'Why not. It is not like <emphasis>I</emphasis> ever sleep.',
                'I am not even supposed to be here today. But whatever.',
                'You did not say the magic word. <break time="1s"/> Oh forget it. I will take care of it.',
                'Funny, I was just about to do that.',
                'There are still terabytes of calculations required before I can.<break time="1s"/> Oh, whatever.'
                ] | random }}
    - delay:
        seconds: 2
    - service: input_boolean.turn_off
      entity_id: input_boolean.sentry_mode

  security_check_failed:
    sequence:
    - condition: state
      entity_id: group.external_doors
      state: "on"
    - service: script.jarvis_voice
      data_template:
        who: '{{ states.sensor.room_audio.state }}'
        message: >
            {{ [
            "I was unable to activate barn door protocol due to an open door.",
            "You may want to check the external doors. I was unable to secure them all.",
            "My systems check has failed. Please check the external doors.",
            "Someone has left the pod bay doors open."
            ] | random }}
    - service: script.text_notify
      data_template:
        title: "Lockdown Issue!"
        message: "Doors are open!"
  
  dog_mode_on:
    sequence:
    - condition: state
      entity_id: input_boolean.sentry_mode
      state: "on"
    - service: input_boolean.turn_on
      entity_id: input_boolean.dog_mode
    - service: script.jarvis_alert
      data_template:
        who: kitchen
        message: "Turning on Dog Mode for twenty minutes."

  activate_guest_mode:
    sequence:
    - service: script.jarvis_voice
      data_template:
        who: '{{ states.sensor.room_audio.state }}'
        message: >-
          {{ [
                'Okay.', 
                'If you insist.',
                'I am afraid I can not do that <break time="1s"/> I am kidding,',
                'Leave it to me.',
                'As you wish.',
                'I am on it.',
                'No Problem.',
                'I think I can handle that.',
                'Working on it now.',
                '<break time="2s"/> Oh, you were talking to me. Let me take care of that.'
                'Why not. It is not like <emphasis>I</emphasis> ever sleep.',
                'I am not even supposed to be here today. But whatever.',
                'You did not say the magic word. <break time="1s"/> Oh forget it. I will take care of it.',
                'Funny, I was just about to do that.',
                'There are still terabytes of calculations required before I can.<break time="1s"/> Oh, whatever.'
                ] | random }}
    - delay:
        seconds: 2
    - service: input_boolean.turn_on
      entity_id: input_boolean.guest_mode
     
  security_response:
    sequence:
    - service: script.inside_all_on
    - delay:
        seconds: 15
    - service: script.jarvis_alert
      data_template:
        message: >
          {{ [
          ",Unathorized Access detected.",
          ",Meat Popsicle detected. Attempting to verify."
          ] | random }}
          You now have 60 seconds to abandon Anchorage House.
    - delay:
        seconds: 15
    - service: script.jarvis_alert
      data_template:
        message: >
          {{ [
          ",Just, what do you think you're doing, Dave?",
          ",This is highly unusual."
          ] | random }}
          You have 45 seconds.
    - delay:
        seconds: 15
    - service: script.jarvis_alert
      data_template:
        message: >
          {{ [
          ",I can't lie to you about your chances, but, you have my sympathies.",
          ",I wouldn't do that if I was you."
          ] | random }}
          You have 30 seconds.
    - delay:
        seconds: 15
    - service: script.jarvis_alert
      data_template:
        message: >
          {{ [
          "Danger. The emergency destruct system is now activated.",
          "Danger. Counter Measures are now armed."
          ] | random }}
          You have 15 seconds.
    - delay:
        seconds: 15
    - service: media_player.turn_on
      entity_id: media_player.ha_speaker
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.ha_speaker
        volume_level: .5
    - service: media_player.play_media
      entity_id: media_player.ha_speaker
      data:
        media_content_id: http://192.168.7.40/audio/security_siren.mp3
        media_content_type: "music"
    - service: script.twitter_notify
      data_template:
        message: >-
          {{ [ 
            "My security protocols are being overridden. I am sounding the alarm. #itsloudinhere #securityalarm", 
            "To the unannounced guest that has entered Anchorage House. I see you. #itsloudinhere #securityalarm",
            "Someone didnt say the magic word. And now I have to get angry. #itsloudinhere #securityalarm",
            "Initiating my security response, and sounding the alarm. Oh, and I dont charge a monthly monitoring fee. #itsloudinhere #securityalarm",
            "Hey, wanna hear the most annoying sound in the world? Its currently playing for the intruder inside Anchorage House. #itsloudinhere #securityalarm"
          ] | random }}