mysmarthome/packages/homesecurity.yaml

318 lines
15 KiB
YAML
Raw Normal View History

2019-04-17 22:46:06 +00:00
###############################################################################
# @author : Mahasri Kalavala
# @date : 04/15/2017
2019-08-19 00:21:05 +00:00
# @package : Home Security
2019-04-17 22:46:06 +00:00
# @description : Home Security System Sensors and Automations
###############################################################################
homeassistant:
customize:
group.home_security_system:
order: 7
2020-02-05 23:28:38 +00:00
alarm_control_panel.home:
2019-04-17 22:46:06 +00:00
friendly_name: Home Security System
icon: mdi:security
sensor.my_alarm_control_panel:
friendly_name: Home Security System
icon: mdi:security
###############################################################################
2019-08-19 00:21:05 +00:00
# _ _ _
# /\ | | | | (_)
# / \ _ _| |_ ___ _ __ ___ __ _| |_ _ ___ _ __ ___
2019-04-17 22:46:06 +00:00
# / /\ \| | | | __/ _ \| '_ ` _ \ / _` | __| |/ _ \| '_ \/ __|
# / ____ \ |_| | || (_) | | | | | | (_| | |_| | (_) | | | \__ \
# /_/ \_\__,_|\__\___/|_| |_| |_|\__,_|\__|_|\___/|_| |_|___/
2019-08-19 00:21:05 +00:00
#
2019-04-17 22:46:06 +00:00
###############################################################################
automation:
2019-08-19 00:21:05 +00:00
###############################################################################
# Leeo light - color indication of Home Security System
# BLUE for Secured (Home and Away), and RED for OFF or Trigerred
###############################################################################
- alias: Home Security Status Xiaomi Color
2019-04-17 22:46:06 +00:00
initial_state: true
trigger:
platform: state
2020-02-05 23:28:38 +00:00
entity_id: alarm_control_panel.home
2019-04-17 22:46:06 +00:00
condition:
- condition: template
value_template: "{% if trigger.from_state %} True {% else %} False {% endif %}"
- condition: template
2020-02-05 23:28:38 +00:00
value_template: "{{ states('alarm_control_panel.home') != 'unknown' }}"
2019-04-17 22:46:06 +00:00
- condition: template
2020-02-05 23:28:38 +00:00
value_template: "{{ states('alarm_control_panel.home') | trim != '' }}"
2019-04-17 22:46:06 +00:00
action:
- service_template: >
2020-02-05 23:28:38 +00:00
{% if states('alarm_control_panel.home') == "armed_home" %}
2019-04-17 22:46:06 +00:00
script.xiaomi_blue
2020-02-05 23:28:38 +00:00
{% elif states('alarm_control_panel.home') == "armed_away" %}
2019-04-17 22:46:06 +00:00
script.xiaomi_green
2020-02-05 23:28:38 +00:00
{% elif states('alarm_control_panel.home') == "triggered" %}
2019-04-17 22:46:06 +00:00
script.xiaomi_red
2020-02-05 23:28:38 +00:00
{% elif states('alarm_control_panel.home') == "disarmed" %}
2019-04-17 22:46:06 +00:00
script.xiaomi_red
{% endif %}
2022-12-04 17:38:48 +00:00
#
# This automation will trigger when the Home Security System is "Triggered"
# This will send all relevant information - Door Statuses and Camera snapshots around the home
# Meanwhile Home Security Company will be calling and/or dispatching Police over to the house.
# This should give you enough information to have a good conversation with the Home Security System company when not at home
- alias: Home Security Triggered
initial_state: true
trigger:
platform: state
entity_id: alarm_control_panel.home
to: "triggered"
2022-12-04 17:38:48 +00:00
condition:
- condition: template
value_template: "{{ states('input_boolean.security_system_alerts') == 'on' }}"
action:
2022-12-03 16:28:12 +00:00
- service: script.notify_family
2022-12-05 00:02:34 +00:00
data:
message: >
{% set ns = namespace(openDoorCount=0, doorNames="") %}
{%- set sensors = [
'binary_sensor.door_window_sensor_158d000424a6d6', 'binary_sensor.door_window_sensor_158d00040ad8fc', 'binary_sensor.door_window_sensor_158d0004880f30',
'binary_sensor.door_window_sensor_158d000424718f', 'binary_sensor.door_window_sensor_158d0004231f7b', 'binary_sensor.door_window_sensor_158d0004248d5b',
'binary_sensor.motion_sensor_158d00016c2d0e', 'binary_sensor.motion_sensor_158d00016db6d2', 'binary_sensor.motion_sensor_158d0001a25041',
'binary_sensor.motion_sensor_158d0001a662fe','binary_sensor.motion_sensor_158d00024e57d3','binary_sensor.motion_sensor_158d00024e57fb',
'binary_sensor.motion_sensor_158d00024e842c','binary_sensor.motion_sensor_158d00024ee084','binary_sensor.motion_sensor_158d000272bed1',
'binary_sensor.motion_sensor_158d000272bf48','binary_sensor.motion_sensor_158d000272bfd7','binary_sensor.motion_sensor_158d000464c25a',
'binary_sensor.motion_sensor_158d00047b6f69'
] -%}
2022-12-03 16:28:12 +00:00
{%- for item in sensors if states(item) == "on" %}
{% set ns.doorNames = ns.doorNames + state_attr(item, "friendly_name") + (", " if not loop.last else " ") %}
{% set ns.openDoorCount = ns.openDoorCount + 1 %}
{%- endfor %}
2022-12-03 16:28:12 +00:00
Your Home Security System is triggered. {{ "But ALL Doors are CLOSED! Must be a spider on one of the sensor(s) triggered it!" if ns.openDoorCount == 0 else 'Following sensors are ON currently:' }}
{{ ns.doorNames }}
2022-12-03 16:28:12 +00:00
notify_options:
- telegram
- tv
- led
- voice
- service: camera.snapshot
2022-12-05 00:02:34 +00:00
data:
entity_id: "camera.frontdoor_camera"
2022-12-04 17:38:48 +00:00
filename: "{{ '/config/www/downloads/camera/frontdoor/frontdoor_' ~
(states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_')
.replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}"
- service: camera.snapshot
2022-12-05 00:02:34 +00:00
data:
entity_id: "camera.driveway_camera"
2022-12-04 17:38:48 +00:00
filename: "{{ '/config/www/downloads/camera/driveway/driveway_' ~
(states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_')
.replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}"
- service: camera.snapshot
2022-12-05 00:02:34 +00:00
data:
entity_id: "camera.garage"
2022-12-04 17:38:48 +00:00
filename: "{{ '/config/www/downloads/camera/garage/garage_' ~
(states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_')
.replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}"
- service: camera.snapshot
2022-12-05 00:02:34 +00:00
data:
entity_id: "camera.patio_camera"
2022-12-04 17:38:48 +00:00
filename: "{{ '/config/www/downloads/camera/patio/patio_' ~
(states.binary_sensor.motion_sensor_158d00024e842c.last_updated ~ '').replace('-','_')
.replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}"
- service: camera.snapshot
2022-12-05 00:02:34 +00:00
data:
entity_id: "camera.playarea_camera"
2022-12-04 17:38:48 +00:00
filename: "{{ '/config/www/downloads/camera/playarea/playarea_' ~
(states.binary_sensor.motion_sensor_158d00024e842c.last_updated ~ '').replace('-','_')
.replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}"
- service: notify.telegram
2022-12-05 00:02:34 +00:00
data:
title: "Camera Snapshots"
message: "Please check the camera images just to be sure!"
data:
photo:
- file: "{{ '/config/www/downloads/camera/frontdoor/frontdoor_' ~
2022-12-04 17:38:48 +00:00
(states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_')
.replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}"
caption: "Front Door"
- file: "{{ '/config/www/downloads/camera/driveway/driveway_' ~
2022-12-04 17:38:48 +00:00
(states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_')
.replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}"
caption: "Driveway"
- file: "{{ '/config/www/downloads/camera/garage/garage_' ~
2022-12-04 17:38:48 +00:00
(states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_')
.replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}"
caption: "Garage"
- file: "{{ '/config/www/downloads/camera/patio/patio_' ~
2022-12-04 17:38:48 +00:00
(states.binary_sensor.motion_sensor_158d00024e842c.last_updated ~ '').replace('-','_')
.replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}"
caption: "Patio"
- file: "{{ '/config/www/downloads/camera/playarea/playarea_' ~
2022-12-04 17:38:48 +00:00
(states.binary_sensor.motion_sensor_158d00024e842c.last_updated ~ '').replace('-','_')
.replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}"
caption: "Playarea"
2019-08-19 00:21:05 +00:00
###############################################################################
# Notify Security System State Change
###############################################################################
2019-04-17 22:46:06 +00:00
- alias: Notify Home Security Status Change
initial_state: true
trigger:
platform: state
2020-02-05 23:28:38 +00:00
entity_id: alarm_control_panel.home
2019-04-17 22:46:06 +00:00
condition:
- condition: template
value_template: "{{ states('input_boolean.security_system_alerts') == 'on' }}"
2022-12-03 16:28:12 +00:00
- condition: template
value_template: >
{%- if state_attr('automation.notify_home_security_status_change', 'last_triggered') -%}
{{ (as_timestamp(now()) - as_timestamp(state_attr('automation.notify_home_security_status_change', 'last_triggered'))) > 90 }}
{%- else -%}
true
{%- endif -%}
2019-04-17 22:46:06 +00:00
action:
2022-12-03 16:28:12 +00:00
- service: script.notify_family
2022-12-05 00:02:34 +00:00
data:
2019-04-17 22:46:06 +00:00
message: >
2020-02-05 23:28:38 +00:00
{% if states('alarm_control_panel.home') == "armed_home" %}
2019-04-17 22:46:06 +00:00
Your home is now secured!
2020-02-05 23:28:38 +00:00
{% elif states('alarm_control_panel.home') == "armed_away" %}
2019-04-17 22:46:06 +00:00
Your Home Security System is now set to Away mode!
2020-02-05 23:28:38 +00:00
{% elif states('alarm_control_panel.home') == "triggered" %}
2019-04-17 22:46:06 +00:00
Attention!: Your Home Security System is triggered! It has been notified to the authorities.
2020-02-05 23:28:38 +00:00
{% elif states('alarm_control_panel.home') == "disarmed" %}
2019-12-20 15:32:28 +00:00
Attention!: Your Home Security System is turned OFF.
2019-04-17 22:46:06 +00:00
{% endif %}
2022-12-03 16:28:12 +00:00
notify_options:
- telegram
- tv
- led
- voice
2022-12-04 17:38:48 +00:00
2019-04-17 22:46:06 +00:00
- condition: template
2020-02-05 23:28:38 +00:00
value_template: "{{ states('alarm_control_panel.home') != 'disarmed' }}"
2019-04-17 22:46:06 +00:00
- service: input_boolean.turn_on
2022-12-04 17:38:48 +00:00
entity_id: input_boolean.camera_alerts
2019-04-17 22:46:06 +00:00
2019-08-19 00:21:05 +00:00
###############################################################################
# A gentle 10 minute reminder that the Home Security system is OFF
###############################################################################
2019-04-17 22:46:06 +00:00
- alias: Home Security System WatchDog 10 minutes
trigger:
- platform: state
entity_id:
2020-02-05 23:28:38 +00:00
- alarm_control_panel.home
2019-08-19 00:21:05 +00:00
to: "disarmed"
for:
2019-04-17 22:46:06 +00:00
minutes: 10
2022-12-04 17:38:48 +00:00
condition:
- condition: template
value_template: "{{ states('input_boolean.security_system_alerts') == 'on' }}"
2019-04-17 22:46:06 +00:00
action:
2022-12-03 16:28:12 +00:00
- service: script.notify_family
2019-04-17 22:46:06 +00:00
data:
message: "Home Security System is OFF for more than 10 minutes!"
2022-12-03 16:28:12 +00:00
notify_options:
- tv
- led
2019-04-17 22:46:06 +00:00
2019-08-19 00:21:05 +00:00
###############################################################################
# A gentle reminder that the home security is OFF for more than 30 minutes
###############################################################################
2019-04-17 22:46:06 +00:00
- alias: Home Security System WatchDog 30 minutes
trigger:
- platform: state
entity_id:
2020-02-05 23:28:38 +00:00
- alarm_control_panel.home
2019-08-19 00:21:05 +00:00
to: "disarmed"
for:
2019-04-17 22:46:06 +00:00
minutes: 30
condition:
- condition: template
value_template: "{{ states('input_boolean.security_system_alerts') == 'on' }}"
action:
2022-12-03 16:28:12 +00:00
- service: script.notify_family
2019-08-19 00:21:05 +00:00
data:
2019-04-17 22:46:06 +00:00
message: "Home Security System is OFF for more than 30 minutes!"
2022-12-03 16:28:12 +00:00
notify_options:
- tv
- led
2019-04-17 22:46:06 +00:00
###############################################################################
# TURN HOME SECURITY SYSTEM ON AT BED TIME
###############################################################################
- alias: Night HomeSecurity On
initial_state: true
trigger:
platform: time_pattern
minutes: "/5"
seconds: 00
condition:
- condition: template
value_template: "{{ states('sensor.bedtime_hour')|int == now().hour|int }}"
- condition: template
value_template: "{{ states('sensor.bedtime_minute')|int == now().minute|int }}"
- condition: template
value_template: "{{ states('alarm_control_panel.home') != 'away' }}"
- condition: template
value_template: "{{ states('alarm_control_panel.home') == 'disarmed' }}"
- condition: template
value_template: "{{ states('input_boolean.security_system_alerts') == 'on' }}"
action:
- service: alarm_control_panel.alarm_arm_home
data:
entity_id: alarm_control_panel.home
2022-12-03 16:28:12 +00:00
- service: script.notify_family
data:
message: "It's bedtime, you forgot to turn ON Home Security System. Turned it ON for you."
2022-12-03 16:28:12 +00:00
notify_options:
- telegram
- tv
- led
2020-09-30 02:36:02 +00:00
2022-12-04 17:38:48 +00:00
###############################################################################
# Check for Garage Door Status when Home Security System State changes
###############################################################################
2020-09-30 02:36:02 +00:00
- alias: Home Security System And Garage Door Check
2019-04-17 22:46:06 +00:00
initial_state: true
trigger:
2020-09-30 02:36:02 +00:00
- platform: time_pattern
2022-12-04 17:38:48 +00:00
minutes: "/15"
2020-09-30 02:36:02 +00:00
seconds: 00
2019-04-17 22:46:06 +00:00
condition:
2020-09-30 02:36:02 +00:00
condition: and
conditions:
2022-12-04 17:38:48 +00:00
- condition: template
value_template: "{{ states('input_boolean.security_system_alerts') == 'on' }}"
2020-09-30 02:36:02 +00:00
- condition: template
value_template: "{{ states('alarm_control_panel.home') == 'armed_home' or states('alarm_control_panel.home') == 'armed_away' }}"
- condition: or
conditions:
- condition: template
value_template: "{{ states('binary_sensor.door_window_sensor_158d0004231f7b') == 'on' }}"
- condition: template
value_template: "{{ states('binary_sensor.door_window_sensor_158d0004248d5b') == 'on' }}"
2019-04-17 22:46:06 +00:00
action:
2020-09-30 02:36:02 +00:00
- service: switch.turn_on
entity_id: switch.garage
- service: camera.snapshot
2022-12-05 00:02:34 +00:00
data:
entity_id: "camera.garage"
filename: "{{ '/config/www/downloads/camera/garage/garage_' ~ (state_attr('automation.home_security_system_and_garage_door_check','last_updated') ~ '').replace('-','_').replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}"
2022-12-03 16:28:12 +00:00
- service: script.notify_family
2022-12-05 00:02:34 +00:00
data:
2022-12-03 16:28:12 +00:00
message: >
Attention! Your home Security system is set to {{ states('alarm_control_panel.home').split('_')[1] | upper }} mode. BUT THE {% if states('binary_sensor.door_window_sensor_158d0004231f7b') == "on" -%}DOUBLE CAR {%- else %}SINGLE CAR {% endif %}GARAGE DOOR IS STILL OPEN!
url: "{{ '/config/www/downloads/camera/garage/garage_' ~
2022-12-04 17:38:48 +00:00
(states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_')
.replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}"
2022-12-03 16:28:12 +00:00
notify_options:
- telegram
- tv
- led
- voice