Skip to content

Commit

Permalink
Use alarm blueprints to handle presence alarm
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-V committed Aug 10, 2024
1 parent a7ea391 commit db08a81
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 188 deletions.
15 changes: 10 additions & 5 deletions blueprints/automation/alarm/clear_alarm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,27 @@ blueprint:
name: Name of the thing this alarm handles.
selector:
text: { }
tag:
name: An optional tag to identify this notification.
default: ""
selector:
text: { }

initial_state: true
max_exceeded: "silent"
mode: "single"

trigger_variables:
name: !input name
group: !input group

trigger:
- platform: "state"
entity_id: !input group
from: "on"
to: "off"
for: 10

variables:
name: !input name
group: !input group

action:
- service: python_script.notify
data:
Expand All @@ -38,6 +43,6 @@ action:
persistent: true
priority: false
push_target: "household"
tag: "alarm_{{ name | slugify }}"
tag: "alarm_{{ name | slugify }}_{{ tag | slugify }}"
title: "{{ name | capitalize }} cleared"
url: "/lovelace/security"
43 changes: 33 additions & 10 deletions blueprints/automation/alarm/start_alarm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ blueprint:
name: Start an alarm
domain: automation
input:
actions:
name: Quick actions available with the notification.
description: >
Accepts an array of objects in the shape of `{title: string, action: string}`
selector:
object: { }
default: ~
group:
name: Sensor group.
description: Binary sensor group that will start the alarm once it turns on.
Expand All @@ -14,22 +21,36 @@ blueprint:
name: Name of the thing this alarm handles.
selector:
text: { }
silenced:
name: Silenced condition
description: Optional condition to determine if the audio broadcast is silenced.
selector:
condition: { }
default:
- condition: template
value_template: "{{ false }}"
tag:
name: An optional tag to identify this notification.
default: ""
selector:
template: { }

initial_state: true
max_exceeded: "silent"
mode: "single"

trigger_variables:
name: !input name
group: !input group

trigger:
- platform: "homeassistant"
event: "start"
- platform: "state"
entity_id: !input group
to: "on"

variables:
name: !input name
group: !input group
tag: !input tag

condition:
- condition: state
entity_id: !input group
Expand All @@ -44,26 +65,28 @@ action:
persistent: true
priority: true
push_target: "household"
tag: "alarm_{{ name | slugify }}"
push_actions: !input actions
tag: "alarm_{{ name | slugify }}_{{ tag | slugify }}"
title: "{{ name | capitalize }} detected"
url: "/lovelace/security"
message: &alarm_message >
{% from 'strings.jinja' import nice_join %}
{%
set locations = expand(group)
| selectattr('state', '==', 'on')
| selectattr('state', '!=', 'off')
| map(attribute = 'entity_id')
| map('area_name')
| map('lower')
| sort | unique
%}
{{ name | capitalize }} detected in {{ nice_join(locations) }}.

- repeat:
sequence:
- service: "script.broadcast_notification"
data:
message: *alarm_message
- if: !input silenced
then:
- service: "script.broadcast_notification"
data:
message: *alarm_message
- delay: 10
until:
- condition: state
Expand Down
35 changes: 7 additions & 28 deletions dashboards/views/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@
- type: "markdown"
content: |
{%
set devices = state_attr('binary_sensor.intrusion_events', 'devices') | default([], True) | list
set entities = state_attr('binary_sensor.intrusion_activity', 'entity_id')
| default([], True) | list
-%}
{%
set entities = state_attr('binary_sensor.intrusion_events', 'entities') | default([], True) | list
-%}
{% set count = (devices + entities) | length -%}
{% set area_names = (devices + entities) | map('area_name') | select('string') | unique | sort | list -%}
{% set count = entities | length -%}
{% set area_names = entities | map('area_name') | select('string') | unique | sort -%}
<ha-icon icon="mdi:identifier"></ha-icon> {{ states('input_text.presence_armed_id') }}
Expand All @@ -53,35 +51,16 @@
{% endfor %}
{%- endif %}
- type: "markdown"
title: "Device interactions"
content: |
{%
set device_ids =
state_attr('binary_sensor.intrusion_events', 'devices') | default([], True)
| unique
-%}
{% for device_id in device_ids -%}
* [{{ device_attr(device_id, 'name') }}](/config/devices/device/{{ device_id }})
{% endfor %}
- type: "custom:auto-entities"
card:
type: "entities"
title: "Entity interactions"
title: "Interactions"
show_header_toggle: false
sort:
method: "name"
filter:
template: >-
{%
set entity_ids = (
state_attr('binary_sensor.intrusion_events', 'entities') | default([], True)
) | sort | unique
-%}
{% for entity_id in entity_ids -%}
* {{ entity_id }} {% if states[entity_id] %}({{ states[entity_id].name }}){% endif %}
{% endfor %}
include:
- group: binary_sensor.intrusion_activity

- type: "vertical-stack"
title: "Devices"
Expand Down
Loading

0 comments on commit db08a81

Please sign in to comment.