Files
Home-Assistant-Configs/packages/security.yaml
Tony Stork 9445c2a4c4 Simplified normal text notifications further
Additionally made the script capable of clearing notifications. Should be almost no need to call notify services directly at all anymore.
2023-02-28 18:14:44 -05:00

490 lines
16 KiB
YAML

input_boolean:
# Main security switch. If this is on, the security is armed.
sentry_mode:
name: Sentry Mode
icon: mdi:security
# Vacation mode is automagically set when we are 3 hours from the house, and turns off when we return.
# This is used to modify some of the normal automations.
vacation_mode:
name: Vacation Mode
icon: mdi:airplane-takeoff
# Guest mode is use to modify automations when we have guests.
# In some cases this prevents security from being set to prevent security alarm going off
guest_mode:
name: Guest Mode
icon: mdi:account-multiple
# This switch powers the security alarm and gives an easy way to kill the alarm.
# When it is on, the alarm is going off
security_alarm:
name: Security Alarm
icon: mdi:speaker-wireless
# This switch powers the fire alarm.
# When on the fire alarm is going off.
fire_alarm:
name: Fire Alarm
icon: mdi:speaker-wireless
# This switch turns on if the security system checks that fire when someone tries to arm the system
# finds a door open, or another condition that would prevent the system from being able to monitor properly.
lockdown_issue:
name: Lockdown Issue
icon: mdi:lock-reset
# This switch is turned on if there is a security breach. Turning on this switch starts the countdown to the alarm.
security_issue:
name: Security Issue
icon: mdi:alert-circle-outline
# These booleans will only provide status/context for automation purposes. They will NOT actually control the security system.
security_armed_home:
name: Security Armed Home
icon: mdi:shield-home
security_armed_away:
name: Security Armed Away
icon: mdi:security
input_datetime:
morning_alarm_disarm:
name: Morning Alarm Disarm
icon: mdi:shield-off
has_date: false
has_time: true
morning_alarm_rearm:
name: Morning Alarm Rearm
icon: mdi:shield-home
has_date: false
has_time: true
sensor:
- platform: template
sensors:
windows_open:
friendly_name: "Windows"
unit_of_measurement: 'open'
value_template: >-
{% set windows = [
states.binary_sensor.front_window_near,
states.binary_sensor.kitchen_big_window,
states.binary_sensor.mud_room_window,
states.binary_sensor.stairway_window_lower,
] %}
{% set windows_open = windows | selectattr('state','eq','on') | list | count %}
{{ windows_open }}
icon_template: >-
{% set windows = [
states.binary_sensor.front_window_near,
states.binary_sensor.kitchen_big_window,
states.binary_sensor.mud_room_window,
states.binary_sensor.stairway_window_lower,
] %}
{% set windows_open = windows | selectattr('state','eq','on') | list | count %}
{% if windows_open == 0 %}
mdi:window-closed
{% else %}
mdi:window-open
{% endif %}
doors_open: #! This sensor is only for exterior doors, and interior doors that are NOT excluded from security protocols
friendly_name: "Doors"
unit_of_measurement: 'open'
value_template: >-
{% set doors = [
states.binary_sensor.front_door,
states.binary_sensor.back_door,
] %}
{% set doors_open = doors | selectattr('state','eq','on') | list | count %}
{{ doors_open }}
icon_template: >-
{% set doors = [
states.binary_sensor.front_door,
states.binary_sensor.back_door,
] %}
{% set doors_open = doors | selectattr('state','eq','on') | list | count %}
{% if doors_open == 0 %}
mdi:door-closed
{% else %}
mdi:door-open
{% endif %}
interior_doors_open: # This sensor is not used for security purposes, only for information
friendly_name: "Interior Doors"
unit_of_measurement: 'open'
value_template: >-
{% set doors = [
states.binary_sensor.basement_studio_door,
states.binary_sensor.downstairs_bathroom_door,
] %}
{% set doors_open = doors | selectattr('state','eq','on') | list | count %}
{{ doors_open }}
icon_template: >-
{% set doors = [
states.binary_sensor.basement_studio_door,
states.binary_sensor.downstairs_bathroom_door,
] %}
{% set doors_open = doors | selectattr('state','eq','on') | list | count %}
{% if doors_open == 0 %}
mdi:door-closed
{% else %}
mdi:door-open
{% endif %}
total_faults:
friendly_name: Faults
unit_of_measurement: 'open'
value_template: >-
{% set windows_open = states('sensor.windows_open') | int %}
{% set doors_open = states('sensor.doors_open') | int %}
{{ doors_open + windows_open }}
icon_template: >-
{% set windows_open = states('sensor.windows_open') | int %}
{% set doors_open = states('sensor.doors_open') | int %}
{% set faults = ( doors_open + windows_open ) %}
{% if faults == 0 %}
mdi:shield-home
{% else %}
mdi:shield-off
{% endif %}
automation:
- id: 51819f36-2407-496c-afcd-ae160d747f0a
alias: Scheduled Alarm Disarm
trigger:
- platform: time
at: input_datetime.morning_alarm_disarm
id: morning
- platform: time
at: input_datetime.master_bedroom_wakeup
id: wakeup
condition:
- condition: state
entity_id: group.adults
state: 'home'
- condition: state
entity_id: input_boolean.vacation_mode
state: 'off'
- condition: state
entity_id: input_boolean.guest_mode
state: 'off'
action:
- choose:
- conditions:
- condition: trigger
id: morning
sequence:
- condition: or
conditions:
- condition: state
entity_id: input_boolean.work_today
state: 'on'
- condition: state
entity_id: input_boolean.kallen_school_today
state: 'on'
- service: script.security_disarm
- conditions:
- condition: trigger
id: wakeup
sequence:
- service: script.security_disarm
- id: f51eb02f-3f44-4b5d-a389-762b8ca88e2a
alias: Scheduled Alarm Rearm
trigger:
- platform: time
at: input_datetime.morning_alarm_rearm
condition:
- condition: state
entity_id: group.adults
state: 'home'
- condition: state
entity_id: input_boolean.vacation_mode
state: 'off'
- condition: state
entity_id: input_boolean.guest_mode
state: 'off'
- condition: time
after: '04:30'
before: '13:30'
- condition: or
conditions:
- condition: state
entity_id: input_boolean.work_today
state: 'on'
- condition: state
entity_id: input_boolean.kallen_school_today
state: 'on'
- condition: template
value_template: >
{% set rearm = state_attr('input_datetime.morning_alarm_rearm','timestamp') %}
{% set wake = state_attr('input_datetime.master_bedroom_wakeup','timestamp') %}
{% set diff = wake - rearm %}
{% if diff <= 1800 %}
false
{% else %}
true
{% endif %}
action:
- if:
- condition: state
entity_id: input_boolean.work_today
state: 'on'
then:
- service: script.security_scheduling
- if:
- condition: and
conditions:
- condition: time
before: "14:00:00"
after: "12:00:00"
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: state
entity_id: input_boolean.kallen_school_early_release
state: "on"
then:
- stop: School early release
- service: script.security_arm_home
- id: c7927c59-e0fe-48b9-b308-dd90fb774920
alias: Lockdown Issue
trigger:
- platform: state
entity_id: input_boolean.lockdown_issue
from: "off"
to: "on"
action:
- service: persistent_notification.create
data:
title: Lockdown Issue
notification_id: lockdown_issue
message: >-
{% set extdoors = expand('binary_sensor.exterior_doors') | selectattr('state','eq','on') | map(attribute='name') | list | join(', ') %}
{% set windows = expand('binary_sensor.windows') | selectattr('state','eq','on') | map(attribute='name') | list | join(', ') %}
A lockdown issue has been caused by the following sensors:
Doors:{% if is_state('binary_sensor.exterior_doors','on') %} {{ extdoors }} {% else %} None {% endif %}
Windows:{% if is_state('binary_sensor.windows','on') %} {{ windows }} {% else %} None {% endif %}
- service: script.text_notify
data:
type: critical
who: 'parents'
title: 'Security Not Armed!'
tag: lockdown-issue
message: >-
{% set extdoors = expand('binary_sensor.exterior_doors') | selectattr('state','eq','on') | map(attribute='name') | list | join(', ') %}
{% set windows = expand('binary_sensor.windows') | selectattr('state','eq','on') | map(attribute='name') | list | join(', ') %}
A lockdown issue has been caused by the following sensors:
Doors:{% if is_state('binary_sensor.exterior_doors','on') %} {{ extdoors }} {% else %} None {% endif %}
Windows:{% if is_state('binary_sensor.windows','on') %} {{ windows }} {% else %} None {% endif %}
- service: scene.create
data:
scene_id: light_state_before_lockdown_issue
snapshot_entities:
- light.living_room_color_1
- light.living_room_color_2
- light.living_room_color_3
- light.tina_lamp_side
- light.tina_lamp_top
- light.tina_desk_strip
- delay:
seconds: 1
- service: switch.turn_off
target:
entity_id:
- switch.adaptive_lighting_living_room
- switch.adaptive_lighting_tina_lamp
- service: light.turn_on
target:
entity_id:
- light.living_room_lights
- light.tina_lamp
- light.tina_desk_strip
data:
color_name: red
brightness_pct: 100
- service: script.status_annc
data:
who: common
call_interruption: 1
call_lockdown_issue: 1
- wait_template: "{{ is_state('binary_sensor.security_faults','off') or is_state('input_boolean.lockdown_issue','off') }}"
timeout:
minutes: 10
- service: input_boolean.turn_off
target:
entity_id: input_boolean.lockdown_issue
- delay:
seconds: 3
- if:
- condition: state
entity_id: binary_sensor.security_faults
state: 'off'
then:
- service: notify.all_ios
data:
type: alert
who: all
message: clear_notification
data:
tag: lockdown-issue
- service: persistent_notification.dismiss
data:
notification_id: lockdown_issue
- if:
- condition: state
entity_id: group.adults
state: 'not_home'
then:
- service: script.security_arm_away
else:
- service: script.security_arm_home
else:
- service: script.speech_engine
data:
who: common
message: 'I am unable to resolve the security issue, so I am giving up. Please report the issue to Tony if applicable.'
- service: scene.turn_on
target:
entity_id: scene.light_state_before_lockdown_issue
- delay:
seconds: 3
- service: switch.turn_on
target:
entity_id:
- switch.adaptive_lighting_living_room
- switch.adaptive_lighting_tina_lamp
- id: 1061c626-17c1-4f0b-8f55-2afc60ef8a3a
alias: Vacation Mode
trigger:
- platform: template
value_template: >
{% set tony = states('sensor.tony_s_iphone_travel_time_min') | float %}
{% set tina = states('sensor.tinas_iphone_travel_time_min') | float %}
{{ is_state('input_boolean.vacation_mode','off') and (tony >= 90) and (tina >= 90) }}
id: leave-radius
- platform: state
entity_id: group.adults
to: 'home'
id: arrive-home
condition:
- condition: state
entity_id: input_boolean.guest_mode
state: 'off'
action:
- choose:
- conditions:
- condition: trigger
id: leave-radius
sequence:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.vacation_mode
- conditions:
- condition: trigger
id: arrive-home
sequence:
- service: input_boolean.turn_off
target:
entity_id: input_boolean.vacation_mode
- id: 027f6f05-289f-4f3d-925e-54d95226ea34
alias: Security Schedules Reset
trigger:
- platform: time
at: "00:00:00"
action:
- service: automation.turn_on
target:
entity_id:
- automation.scheduled_alarm_rearm
- automation.scheduled_alarm_disarm
script:
security_arm_home:
alias: Security Arm - Home
sequence:
- if:
- condition: state
entity_id: binary_sensor.security_faults
state: 'off'
then:
- service: alarm_control_panel.alarm_arm_home
target:
entity_id: alarm_control_panel.stratton_ave_alarm
data:
code: !secret ring_alarm_code
- service: input_boolean.turn_off
target:
entity_id:
- input_boolean.lockdown_issue
- input_boolean.security_armed_away
- service: input_boolean.turn_on
target:
entity_id: input_boolean.security_armed_home
- service: script.status_annc
data:
who: living_room
call_security_armed: 1
else:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.lockdown_issue
security_arm_away:
alias: Security Arm - Away
sequence:
- if:
- condition: state
entity_id: binary_sensor.security_faults
state: 'off'
then:
- service: alarm_control_panel.alarm_arm_away
target:
entity_id: alarm_control_panel.stratton_ave_alarm
data:
code: !secret ring_alarm_code
- service: alarm_control_panel.alarm_arm_away
target:
entity_id: alarm_control_panel.alexa_guard_9ee3b
- service: input_boolean.turn_off
target:
entity_id:
- input_boolean.lockdown_issue
- input_boolean.security_armed_home
- service: input_boolean.turn_on
target:
entity_id: input_boolean.security_armed_away
else:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.lockdown_issue
security_disarm:
alias: Security Disarm
sequence:
- service: alarm_control_panel.alarm_disarm
target:
entity_id: alarm_control_panel.stratton_ave_alarm
data:
code: !secret ring_alarm_code
- service: alarm_control_panel.alarm_disarm
target:
entity_id: alarm_control_panel.alexa_guard_9ee3b
- service: input_boolean.turn_off
target:
entity_id: input_boolean.lockdown_issue
- if:
- condition: state
entity_id: input_boolean.security_armed_home
state: 'on'
then:
- service: script.status_annc
data:
who: living_room
call_security_not_armed: 1
- delay:
seconds: 1
- service: input_boolean.turn_off
target:
entity_id:
- input_boolean.security_armed_home
- input_boolean.security_armed_away