Aqara smoke detecotrs have the “ability” to alarm each other once one has detected fire.
Since this linkage as achieved through the aqara hub, Home Assistant now has to take care of that job.
- Created for zigbee2mqtt
- Linkage_alarm needs to be enabled/set to true for each device
- Needs each device (smoke detector) to be assigned to a room in order to be correctly notified which device was triggered in which room
- Select the smoke detectors you want to link
- Also mutes all the smoke detectors when one is muted
Since I had only limited possibilities to test this thoroughly, feedback is gladly appreciated.
Updates:
- 01/16/23: Added possibility to select multiple devices to be notified.
- 07/24/23: Fixed issue notifications not working
blueprint:
name: Link Aqara smoke detectors
description:
Aqara smoke detecotrs have the \"ability\" to alarm each other once one has detected fire.
Since this linkage as achieved through the aqara hub, Home Assistant now has to take care of that job.
Select the smoke detectors you want to link. Also mutes all the smoke detectors when one is muted.
source_url: https://community.home-assistant.io/t/aqara-smoke-detector-linkage-alarm/517656
domain: automation
input:
smoke_detectors:
name: Smoke detectors
description: The smoke detectors you want to link.
selector:
device:
model: 'Aqara smart smoke detector (JY-GZ-01AQ)'
multiple: true
notify_device:
name: Devics to notify
description: Device to be notified via the mobile app
selector:
device:
integration: mobile_app
multiple: true
message_title:
name: Message title
description: Title of the notification.
selector:
text:
message_button:
name: Button label
description: The label the action-button has to stop the alarm, e.g. Stop alarm.
selector:
text:
message_string:
name: Message
description: Message content prefixing the area name where smoke was detected.
selector:
text:
variables:
notify_devices: !input notify_device
message: !input message_string
button_label: !input message_button
devices: !input smoke_detectors
buzzers: >-
{% set data = namespace(buzzer=[]) %}
{% set temp = [] %}
{% for device in devices %}
{% set temp = device_entities(device) | select('match', 'select.*_buzzer') | list | join %}
{%- set data.buzzer = data.buzzer + [temp] -%}
{% endfor %}
{{ data.buzzer }}
v_smoke_sensors: >-
{% set data = namespace(alarm_entity=[]) %}
{% set temp = [] %}
{% for device in devices %}
{% set temp = device_entities(device) | select('match', 'binary_sensor.*_smoke') | list | join %}
{%- set data.alarm_entity = data.alarm_entity + [temp] -%}
{% endfor %}
{{ data.alarm_entity }}
sensor_trigger_entity: >-
{% set data = namespace(alarm=false, trigger_id="0") %}
{% for sensor in v_smoke_sensors %}
{% if is_state(sensor, "on") %}
{% set data.trigger_id = sensor %}
{% set data.alarm = true %}
{% endif %}
{% endfor %}
{{ data.trigger_id }}
trigger_variables:
button_label: !input message_string
devices: !input smoke_detectors
smoke_sensors: >-
{% set data = namespace(alarm_entity=[]) %}
{% set temp = [] %}
{% for device in devices %}
{% set temp = device_entities(device) | select('match', 'binary_sensor.*_smoke') | list | join %}
{%- set data.alarm_entity = data.alarm_entity + [temp] -%}
{% endfor %}
{{ data.alarm_entity }}
mute_sensors: >-
{% set data = namespace(muted=[]) %}
{% set temp = [] %}
{% for device in devices %}
{% set temp = device_entities(device) | select('match', 'binary_sensor.*_buzzer_manual_mute') | list | join %}
{%- set data.muted = data.muted + [temp] -%}
{% endfor %}
{{ data.muted }}
trigger:
- platform: template
value_template: >-
{% set data = namespace(alarm=false) %}
{% for sensor in smoke_sensors %}
{% if is_state(sensor, "on") %}
{% set data.alarm = true %}
{% endif %}
{% endfor %}
{{ data.alarm }}
id: "alarm"
- platform: template
value_template: >-
{% set data = namespace(alarm_muted=false) %}
{% for sensor in mute_sensors %}
{% if is_state(sensor, "on") %}
{% set data.alarm_muted = true %}
{% endif %}
{% endfor %}
{{ data.alarm_muted }}
id: "mute"
condition:
action:
- choose:
- conditions:
- condition: template
value_template: "{{trigger.id == 'alarm'}}"
sequence:
- service: select.select_option
target:
entity_id: "{{buzzers}}"
data:
option: "alarm"
- parallel:
- sequence:
- alias: "Setup notification variables"
variables:
action_stop: "{{ 'STOP_' ~ context.id }}"
- alias: "Repeat notify for each device"
repeat:
for_each: "{{notify_devices}}"
sequence:
- service: "notify.mobile_app_{{ device_attr(repeat.item, 'name') | slugify }}"
data:
title: "{{ title | default('') }}"
message: '{{message}} {{area_name(sensor_trigger_entity)}}!'
data:
tag: "fire"
sticky: true
persistent: true
actions:
- action: "{{ action_stop }}" # The key you are sending for the event
title: "{{ button_label }}" # The button title
- wait_for_trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: "{{ action_stop }}"
- service: select.select_option
target:
entity_id: "{{buzzers}}"
data:
option: "mute"
- sequence:
- wait_template: >-
{% set data = namespace(alarm_finished=true) %}
{% for sensor in v_smoke_sensors %}
{% if is_state(sensor, "on") %}
{% set data.alarm_finished = false %}
{% endif %}
{% endfor %}
{{ data.alarm_finished }}
- service: select.select_option
target:
entity_id: "{{buzzers}}"
data:
option: "mute"
- conditions:
- condition: template
value_template: "{{trigger.id == 'mute'}}"
sequence:
- service: select.select_option
target:
entity_id: "{{buzzers}}"
data:
option: "mute"
- alias: "Repeat notify for each device"
repeat:
for_each: "{{notify_devices}}"
sequence:
- service: "notify.mobile_app_{{ device_attr(repeat.item, 'name') | slugify }}"
data:
title: "{{ title | default('') }}"
message: 'clear_notification'
data:
tag: "fire"
mode: restart
max_exceeded: silent