# Security Package # ----------------------------------------------------------------------------- # Security Device Customization homeassistant: customize_glob: "binary_sensor.*_door": device_class: door "binary_sensor.*_window": device_class: window binary_sensor.all_doors: device_class: door binary_sensor.all_windows: device_class: window binary_sensor.garage_door_open: device_class: door # ----------------------------------------------------------------------------- # Manual Alarm Control Panel alarm_control_panel: - platform: manual code: !secret alarm_code code_arm_required: false arming_time: 30 delay_time: 20 trigger_time: 600 disarm_after_trigger: false disarmed: trigger_time: 0 armed_home: arming_time: 0 delay_time: 0 # ----------------------------------------------------------------------------- # Alarm Trigger Source input_text: ha_alarm_trigger: # ----------------------------------------------------------------------------- # Alarm Settings input_boolean: disable_camera_events: name: Disable Camera Events guest_mode: name: Guest Mode input_datetime: alarm_auto_arm_night_start: name: Auto-Arm Night Start initial: '21:00' has_date: false has_time: true alarm_auto_arm_night_end: name: Auto-Arm Night Start initial: '05:00' has_date: false has_time: true binary_sensor: # ----------------------------------------------------------------------------- # Doorbell Camera Online State - platform: rest name: Doorbell Camera Online resource: !secret doorbell_camera_rest_url authentication: digest username: admin password: !secret doorbell_camera_password params: action: getConfig name: VSP_PaaS.Online value_template: "{{ value.split('=')[1] }}" device_class: connectivity # ----------------------------------------------------------------------------- # Door and Window Groups - platform: group name: All Doors entities: - binary_sensor.front_door - binary_sensor.laundry_door - binary_sensor.living_room_door - platform: group name: Living Room Window entities: - binary_sensor.living_room_window_left - binary_sensor.living_room_window_right - platform: group name: All Windows entities: - binary_sensor.dining_room_front_window - binary_sensor.dining_room_side_window - binary_sensor.kitchen_left_window - binary_sensor.kitchen_right_window - binary_sensor.laundry_window - binary_sensor.office_window - binary_sensor.living_room_window - binary_sensor.guest_room_front_window - binary_sensor.guest_room_side_window - binary_sensor.bathroom_window - binary_sensor.bedroom_side_window - binary_sensor.bedroom_back_window - platform: group name: All Motion Sensors entities: - binary_sensor.entry_sensor_motion - binary_sensor.guest_room_sensor_motion - binary_sensor.hallway_sensor_motion - binary_sensor.office_sensor_motion template: sensor: - name: Open Windows/Doors unique_id: open_windows_doors state: > {{ expand(state_attr('binary_sensor.all_doors', 'entity_id') + state_attr('binary_sensor.all_windows', 'entity_id')) | selectattr('state', 'in', ['on']) | map(attribute='attributes.friendly_name') | list | join(', ') }} - name: Motion Detected state: > {{ expand(state_attr('binary_sensor.all_motion_sensors', 'entity_id')) | selectattr('state', 'in', ['on']) | map(attribute='attributes.friendly_name') | list | join(', ') }} binary_sensor: - name: Garage Door Open state: "{{ states('binary_sensor.garage_door') }}" icon: >- {% if is_state('binary_sensor.garage_door', 'on') %} mdi:garage-open {% else %} mdi:garage {% endif %} - name: Security Night state: > {% set time = states('sensor.time') %} {{ states('input_datetime.alarm_auto_arm_night_start') <= time or time <= states('input_datetime.alarm_auto_arm_night_end') }} # ----------------------------------------------------------------------------- # Garage Door Button input_button: garage_door: name: Garage Door icon: mdi:garage # ----------------------------------------------------------------------------- # Force Doorbell Online State shell_command: doorbell_camera_set_online: !secret doorbell_camera_online_command # ----------------------------------------------------------------------------- # Doorbell Event Start Command rest_command: doorbell_start_event: url: !secret frigate_doorbell_event_url method: post # ----------------------------------------------------------------------------- # Security Scripts script: pause_camera_events: alias: Pause Exterior Camera Event Detection sequence: - service: mqtt.publish data: topic: frigate/backyard/detect/set payload: 'OFF' - service: mqtt.publish data: topic: frigate/doorbell/detect/set payload: 'OFF' resume_camera_events: alias: Resume Exterior Camera Event Detection sequence: - service: mqtt.publish data: topic: frigate/backyard/detect/set payload: 'ON' - service: mqtt.publish data: topic: frigate/doorbell/detect/set payload: 'ON' auto_resume_camera_events: alias: Auto Resume Camera Events fields: minutes: name: Minutes description: "The amount of time to wait before resuming detection" default: 60 selector: number: min: 0 max: 240 step: 10 unit_of_measurement: minutes mode: slider mode: restart sequence: - delay: minutes: "{{ minutes }}" - service: input_boolean.turn_off target: entity_id: input_boolean.disable_camera_events - service: script.resume_camera_events # ----------------------------------------------------------------------------- # Security Automations automation: - alias: Run Garage Door trigger: - platform: state entity_id: input_button.garage_door action: - service: switch.turn_on target: entity_id: switch.garage_door_relay_1 - alias: Auto-Arm Alarm (Presence) trigger: - platform: state entity_id: sensor.house_presence_status to: Away action: - service: alarm_control_panel.alarm_arm_away target: entity_id: alarm_control_panel.ha_alarm data: code: !secret alarm_code - alias: Auto-Disarm Alarm (Presence) trigger: - platform: state entity_id: sensor.house_presence_status to: Just Arrived action: - service: alarm_control_panel.alarm_disarm target: entity_id: alarm_control_panel.ha_alarm data: code: !secret alarm_code - alias: Auto-Arm Alarm (Night - After Arrival) trigger: - platform: state entity_id: sensor.house_presence_status to: Home condition: - "{{ is_state('binary_sensor.security_night', 'on') }}" - "{{ is_state('alarm_control_panel.ha_alarm', 'disarmed' )}}" action: - service: alarm_control_panel.alarm_arm_night target: entity_id: alarm_control_panel.ha_alarm data: code: !secret alarm_code - alias: Auto-Arm Alarm (Night - Default) trigger: - platform: state entity_id: binary_sensor.security_night to: 'on' condition: "{{ is_state('alarm_control_panel.ha_alarm', 'disarmed' )}}" action: - service: alarm_control_panel.alarm_arm_night target: entity_id: alarm_control_panel.ha_alarm data: code: !secret alarm_code - alias: Auto-Disarm Alarm (Night) trigger: - platform: state entity_id: binary_sensor.security_night to: 'off' condition: "{{ is_state('alarm_control_panel.ha_alarm', 'armed_night' )}}" action: - service: alarm_control_panel.alarm_disarm target: entity_id: alarm_control_panel.ha_alarm data: code: !secret alarm_code - alias: Notify on Alarm Arm/Disarm trigger: - platform: state entity_id: alarm_control_panel.ha_alarm to: disarmed - platform: state entity_id: alarm_control_panel.ha_alarm to: armed_home - platform: state entity_id: alarm_control_panel.ha_alarm to: armed_away - platform: state entity_id: alarm_control_panel.ha_alarm to: armed_night - platform: state entity_id: alarm_control_panel.ha_alarm to: armed_vacation action: - service: notify.security data: message: > {% set person = states.person |selectattr('attributes.user_id', 'eq', trigger.to_state.context.user_id) |first|default({'attributes':{'friendly_name':'Automation'}}) %}Alarm changed to {{ trigger.to_state.state|replace('_', ' ')|title }} by {{ person.attributes.friendly_name }} - alias: Reset Alarm Trigger on Disarm trigger: - platform: state entity_id: alarm_control_panel.ha_alarm to: 'disarmed' action: - service: input_text.set_value target: entity_id: input_text.ha_alarm_trigger data: value: "" - alias: Notify on Alarm Triggered trigger: - platform: state entity_id: alarm_control_panel.ha_alarm to: 'triggered' action: - service: notify.security data: message: Alarm triggered by {{ states('input_text.ha_alarm_trigger') }} - alias: Trigger Alarm on Window or Door Open trigger: - platform: state entity_id: binary_sensor.all_doors to: 'on' - platform: state entity_id: binary_sensor.all_windows to: 'on' condition: condition: state entity_id: alarm_control_panel.ha_alarm state: - 'armed_away' - 'armed_home' - 'armed_night' - 'armed_vacation' action: - service: input_text.set_value target: entity_id: input_text.ha_alarm_trigger data: value: "{{ states('sensor.open_windows_doors') }}" - service: alarm_control_panel.alarm_trigger target: entity_id: alarm_control_panel.ha_alarm - alias: Trigger Alarm on Interior Motion trigger: - platform: state entity_id: binary_sensor.all_motion_sensors to: 'on' condition: condition: state entity_id: alarm_control_panel.ha_alarm state: - 'armed_away' - 'armed_vacation' action: - service: input_text.set_value target: entity_id: input_text.ha_alarm_trigger data: value: "{{ states('sensor.motion_detected') }}" - service: alarm_control_panel.alarm_trigger target: entity_id: alarm_control_panel.ha_alarm - alias: Trigger Alarm on Garage Door Open trigger: - platform: state entity_id: binary_sensor.garage_door to: 'on' condition: condition: state entity_id: alarm_control_panel.ha_alarm state: - 'armed_night' - 'armed_away' - 'armed_vacation' action: - service: input_text.set_value target: entity_id: input_text.ha_alarm_trigger data: value: Garage Door - service: alarm_control_panel.alarm_trigger target: entity_id: alarm_control_panel.ha_alarm - alias: Pause Camera Event Detection trigger: - platform: state entity_id: input_boolean.disable_camera_events to: 'on' action: - service: script.pause_camera_events - service: script.turn_on target: entity_id: script.auto_resume_camera_events data: variables: minutes: 60 - alias: Resume Camera Event Detection trigger: - platform: state entity_id: input_boolean.disable_camera_events to: 'off' action: - service: script.turn_off target: entity_id: script.auto_resume_camera_events - service: script.resume_camera_events - alias: Pause Doorbell Event Detection on Arrival or Departure trigger: - platform: state entity_id: person.jpk to: 'home' - platform: state entity_id: person.jen to: 'home' - platform: state entity_id: binary_sensor.front_door to: 'on' condition: condition: state entity_id: input_boolean.disable_camera_events state: 'off' mode: restart action: - service: mqtt.publish data: topic: frigate/doorbell/detect/set payload: 'OFF' - delay: 300 - service: mqtt.publish data: topic: frigate/doorbell/detect/set payload: 'ON' - alias: Pause Backyard Event Detection when Garage Door Opens trigger: - platform: state entity_id: binary_sensor.garage_door to: 'on' condition: - "{{ is_state('alarm_control_panel.ha_alarm', 'disarmed') }}" - "{{ is_state('input_boolean.guest_mode', 'off') }}" mode: restart action: - service: mqtt.publish data: topic: frigate/backyard/detect/set payload: 'OFF' - alias: Resume Backyard Event Detection when Garage Door Closes trigger: - platform: state entity_id: binary_sensor.garage_door to: 'off' - platform: state entity_id: alarm_control_panel.ha_alarm not_to: disarmed condition: - "{{ is_state('input_boolean.disable_camera_events', 'off') }}" - "{{ is_state('input_boolean.guest_mode', 'off') }}" mode: restart action: - delay: 30 # Allow time to walk inside before events restart - service: mqtt.publish data: topic: frigate/backyard/detect/set payload: 'ON' - alias: Pause Backyard Event Detection in Guest Mode trigger: - platform: state entity_id: input_boolean.guest_mode to: 'on' mode: restart action: - service: mqtt.publish data: topic: frigate/backyard/detect/set payload: 'OFF' - alias: Resume Backyard Event Detection from Guest Mode trigger: - platform: state entity_id: input_boolean.guest_mode to: 'off' mode: restart action: - service: mqtt.publish data: topic: frigate/backyard/detect/set payload: 'ON' - alias: Reset Doorbell Camera Online Mode trigger: - platform: state entity_id: binary_sensor.doorbell_camera_online to: 'off' - platform: homeassistant event: start action: - service: shell_command.doorbell_camera_set_online - alias: Frigate Event Notification trigger: - platform: mqtt topic: frigate/events payload: new value_template: "{{ value_json.type }}" condition: - "{{ not is_state('alarm_control_panel.ha_alarm', 'disarmed') }}" - "{{ trigger.payload_json.after.has_clip }}" action: - service: notify.security data: message: "A {{ trigger.payload_json.after.label }} detected on {{ trigger.payload_json.after.camera|title }} camera" data: image: "/api/frigate/notifications/{{ trigger.payload_json.after.id }}/thumbnail.jpg" clickAction: "https://hass.kraussnet.com/api/frigate/notifications/{{ trigger.payload_json.after.id }}/clip.mp4" ttl: 0 priority: high tag: "{{ trigger.payload_json.after.id }}" when: "{{ trigger.payload_json.after.start_time|int }}" actions: - action: URI title: View Clip uri: "https://hass.kraussnet.com/api/frigate/notifications/{{ trigger.payload_json.after.id }}/clip.mp4" - action: URI title: View Snapshot uri: "https://hass.kraussnet.com/api/frigate/notifications/{{ trigger.payload_json.after.id }}/snapshot.jpg" - if: - condition: template value_template: >- {{ trigger.payload_json.after.label|lower == 'person' }} then: - service: persistent_notification.create data: notification_id: "camera-{{ trigger.payload_json.after.id }}" title: "A {{ trigger.payload_json.after.label }} detected on {{ trigger.payload_json.after.camera|title }} camera" message: >- ![image](/api/frigate/notifications/{{ trigger.payload_json.after.id }}/snapshot.jpg) [View Clip](/api/frigate/notifications/{{ trigger.payload_json.after.id }}/clip.mp4) - alias: Chime on Doorbell Button trigger: - platform: state entity_id: binary_sensor.doorbell_alarm_local to: 'on' action: - action: media_player.play_media data: media_content_id: media-source://media_source/local/S005-corsica-doorbell.mp3 media_content_type: audio target: entity_id: media_player.tablet_lr - alias: Notify on Doorbell Button trigger: - platform: state entity_id: binary_sensor.doorbell_alarm_local to: 'on' action: - service: rest_command.doorbell_start_event response_variable: event_data - if: "{{ event_data['status'] == 200 }}" then: - service: notify.security data: title: 'Doorbell' message: 'Home Doorbell Rang' data: image: "/api/frigate/notifications/{{ event_data['content']['event_id'] }}/thumbnail.jpg" clickAction: "https://hass.kraussnet.com/api/frigate/notifications/{{ event_data['content']['event_id'] }}/snapshot.jpg" ttl: 0 priority: high actions: - action: URI title: View Clip uri: "https://hass.kraussnet.com/api/frigate/notifications/{{ event_data['content']['event_id'] }}/clip.mp4" - action: URI title: View Snapshot uri: "https://hass.kraussnet.com/api/frigate/notifications/{{ event_data['content']['event_id'] }}/snapshot.jpg" - service: persistent_notification.create data: notification_id: "camera-{{ event_data['content']['event_id'] }}" title: "Doorbell Rang" message: >- ![image](/api/frigate/notifications/{{ event_data['content']['event_id'] }}/snapshot.jpg) [View Clip](/api/frigate/notifications/{{ event_data['content']['event_id'] }}/clip.mp4) else: - service: notify.security data: title: "Doorbell" message: "Home Doorbell Rang but could not create event: {{ event_data['content']['message'] }}" - alias: Notify that Garage Door is Open when Alarm Arms description: Send a Garage Door Open Notice to Phones trigger: - platform: state entity_id: alarm_control_panel.ha_alarm to: armed_home - platform: state entity_id: alarm_control_panel.ha_alarm to: armed_away - platform: state entity_id: alarm_control_panel.ha_alarm to: armed_night - platform: state entity_id: alarm_control_panel.ha_alarm to: armed_vacation condition: "{{ is_state('binary_sensor.garage_door', 'on') }}" mode: single action: - alias: Set up variables for action callback variables: action_ignore: "{{ 'IGNORE_' ~ context.id }}" action_close: "{{ 'CLOSE_' ~ context.id }}" - alias: Send notice to devices action: notify.security data: message: "Garage door is open! It will close in 10 minutes if not ignored." data: actions: - action: "{{ action_ignore }}" title: Ignore - action: "{{ action_close }}" title: Close - alias: Wait for action callback wait_for_trigger: - platform: event event_type: mobile_app_notification_action event_data: # waiting for the specific action avoids accidentally continuing # for another script/automation's notification action action: "{{ action_ignore }}" - platform: event event_type: mobile_app_notification_action event_data: action: "{{ action_close }}" - platform: state entity_id: alarm_control_panel.ha_alarm to: disarmed timeout: minutes: "10" - alias: Process callback choose: - conditions: "{{ wait.remaining > 0 and 'event' in wait.trigger and wait.trigger.event.data.action == action_ignore }}" sequence: - alias: Notify that the event was ignored action: notify.security data: message: > {% set person = states.person |selectattr('attributes.user_id', 'eq', wait.trigger.event.context.user_id) |first|default({'attributes':{'friendly_name':'Automation'}}) %}Open garage door ignored by {{ person.attributes.friendly_name }} - conditions: "{{ wait.remaining > 0 and 'event' in wait.trigger and wait.trigger.event.data.action == action_close }}" sequence: - alias: Close garage door action: switch.turn_on target: entity_id: switch.garage_door_relay_1 - conditions: "{{ wait.remaining > 0 and 'entity_id' in wait.trigger and wait.trigger.entity_id == 'alarm_control_panel.ha_alarm' }}" sequence: - alias: Notify the event was cancelled action: notify.security data: message: "Garage door timeout cancelled because alarm was disarmed" - conditions: "{{ not wait.completed }}" sequence: - alias: Close garage door action: switch.turn_on target: entity_id: switch.garage_door_relay_1 - alias: Notify the event timed out action: notify.security data: message: "Garage door closing automatically" - alias: Notify that Front Door is Unlocked when Alarm Arms description: Send a Front Door Unlocked Notice to Phones trigger: - platform: state entity_id: alarm_control_panel.ha_alarm to: armed_home - platform: state entity_id: alarm_control_panel.ha_alarm to: armed_away - platform: state entity_id: alarm_control_panel.ha_alarm to: armed_night - platform: state entity_id: alarm_control_panel.ha_alarm to: armed_vacation condition: "{{ is_state('lock.front_door_lock_doorlock', 'unlocked') }}" mode: single action: - alias: Set up variables for action callback variables: action_ignore: "{{ 'IGNORE_' ~ context.id }}" action_lock: "{{ 'LOCK_' ~ context.id }}" - alias: Send notice to devices action: notify.security data: message: "Front door is unlocked! It will lock in 10 minutes if not ignored." data: actions: - action: "{{ action_ignore }}" title: Ignore - action: "{{ action_lock }}" title: Lock - alias: Wait for action callback wait_for_trigger: - platform: event event_type: mobile_app_notification_action event_data: # waiting for the specific action avoids accidentally continuing # for another script/automation's notification action action: "{{ action_ignore }}" - platform: event event_type: mobile_app_notification_action event_data: action: "{{ action_lock }}" - platform: state entity_id: alarm_control_panel.ha_alarm to: disarmed timeout: minutes: "10" - alias: Process callback choose: - conditions: "{{ wait.remaining > 0 and 'event' in wait.trigger and wait.trigger.event.data.action == action_ignore }}" sequence: - alias: Notify that the event was ignored action: notify.security data: message: > {% set person = states.person |selectattr('attributes.user_id', 'eq', wait.trigger.event.context.user_id) |first|default({'attributes':{'friendly_name':'Automation'}}) %}Unlocked front door ignored by {{ person.attributes.friendly_name }} - conditions: "{{ wait.remaining > 0 and 'event' in wait.trigger and wait.trigger.event.data.action == action_lock }}" sequence: - alias: Lock front door action: lock.lock target: entity_id: lock.front_door_lock_doorlock - conditions: "{{ wait.remaining > 0 and 'entity_id' in wait.trigger and wait.trigger.entity_id == 'alarm_control_panel.ha_alarm' }}" sequence: - alias: Notify the event was cancelled action: notify.security data: message: "Front door timeout cancelled because alarm was disarmed" - conditions: "{{ not wait.completed }}" sequence: - alias: Lock front door action: lock.lock target: entity_id: lock.front_door_lock_doorlock - alias: Notify the event timed out action: notify.security data: message: "Front door locking automatically"