Aqara smoke detector linkage alarm

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

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
5 Likes

Hi…
This seems very cool…

Unfortunaly I dont have Aquara smoke detectors, but Frient smoke detectors.

Could this not be made to work with all detectors, so alot more people could benefit from this nice blueprint!?

I do not have the skills my self, so have no clue, on how it should be modified unfortunally…

Best regardz Morten

Well, this is specifically designed around this smoke detector and how it is implemented in z2m. So, the short answer is no.

THANK YOU :smiley: for this blueprint

Thanks for your blueprint.
Question?
Whats happen, when you manualy turn on the buzzer on a smoke detector? Do the other alarms also go on?
Does it matter if the linkage_alarm is on or not?

It is not possible to select a notification group because only mobile_app is allowed in your blueprint.

When you manually turn on the buzzer nothing special happens. The alarm is triggered by the sensor detecting smoke. About the group you are right, there is no possibility to currently use a selector for a group as far as I can tell. It is also not possible to just use “multiple: true” here, since for whatever reason that will not work for notification service. All I could offer (at least temporarily) is to enable multiple inputs for devices to be notified (you can leave them empty if not needed).

Edit: I believe I impemented notifying multiple devices correctly by using repeat for each device to create notifications.

1 Like

Many thanks - this is great!

I’m brand new to Zigbee, what do you think is the level of effort to port this to working with ZHA?

We’re close to getting this smoke detector working in ZHA: [Device Support Request] Aqara Smoke Detector JY-GZ-01AQ · Issue #1828 · zigpy/zha-device-handlers · GitHub

Then maybe we can figure out how to get this Blueprint working for ZHA

1 Like

I’m curious why does this need to be enabled?

If you set the manual alarm to enable on the device it won’t actually sound the alarm unless linkage alarm is enabled.

Oh interesting thanks for the info!

Do you use MQTT? there I can just flip the switch to linkage and then trigger the alarm - which was the reason why I did buy this one for sleeping-rooms.

What do you mean? I use zigbee2mqtt, so yes, this uses mqtt. But triggering the alarm does not automatically trigger other devices (the device does not have that logic). You still need N automation (which is also what the aqara hub does).

Hi,

It is a good Blueprint. However, how can I test this blueprint. I try to manually alarm or setting smoke status to be detected or even click run automation, but no notification sent.

Triggering the manual alarm won’t do anything, since the automation is only triggered when a smoke detector detects actual smoke. Editing the status of the sensor in the backend won’t really work, I also tried that when testing. You could try sending an event, but I am not sure if that would work. The only thing that worked for me was actually creating smoke to trigger the alarm on the device (with a candle for example).

Manually triggering the automation won’t work either because there is no valid trigger device id if no actual device has triggered the automation.

Hey, I really want to get this to work, seems perfect for my usage.

however, They don’t link or even send the notification.

I’ve tried power cycling HA, the detectors, z2m, no dice.

this is how I set it up

  1. added the smoke detectors to rooms and enabled link

  2. clicked import blue print

  3. add automation and selected the blue print

  4. all 3 detectors are found and added, then select 2 devices for notifications and filled out the message to send.

  5. blew some vape smoke into the sensor, it sounds and shows smoke detected in z2m and HA but no text and no link.

IDK what to look for in the logs, I really dont use blue prints much and blue prints seems to not show triggers like in custom automations which is how i normally troubleshoot

any help would be appreciated.

Hello,

I have the same, I trigger an alarm by smoke detector test spray, the smoke detector detects and HA triggers the other smoke detectors, all give a signal of themselves.
I just don’t get a notification on my IOS Devices, this is where I have my iPhone and iPad set up.
If I understand it correctly, the HA automation is Unable to resolve the webhook ID from the device ID.

Log from HA automation:

## hoose/1/sequence/1
Executed: 20. Juli 2023 um 16:33:52
Error: Unable to resolve webhook ID from the device ID
## hoose/1/sequence/1/repeat/sequence/0
Executed: 20. Juli 2023 um 16:33:52
Error: Unable to resolve webhook ID from the device ID
1 Like

Yeah, there seems to be a change how the notifications are handled. I have a fix already, going to update soon. Sorry guys

Thank you very much for your quick feedback!

Is it perhaps also possible to add an optional task in which a service can be executed after notification?