ZigBee Lost Connection Notifications

Introduction

By default you can see on your dashboard only that some of ZigBee devices lost connection with Home Assistant. It’s useless because you can have no idea about this until you notice that some of automations doesn’t work any more.

This guidance about configuring notifications with ZigBee2MQTT and Telegram messenger integration.

You can find guidance on how to configure the necessary integrations and add-ons with following links:

Hence, prerequisite for this article are configured  ZigBee2MQTT add-ons and integration with Telegram.

BTW, Telegram is not mandatory requirement – you can use any configured notification method in your HA with small changes in this guidance.

Configurations

ZigBee2MQTT configuration.

Fortunately, Zigbee2MQTT already has functionality to check devices availability.

Please go to Zigbee2MQTT interface in HA, click on Settings menu, choose “Availability” tab and enable “Availability (simple)” check box.

Z2M has advanced settings for checking availability, so you can play this those mode as well.

Please don’t forget to submit you change and restart ZigBee2MQTT for applying the new setting.

As a result, additional “Availability” column will appear on your Z2M dashboard with actual status:

You can switch off some of devices and check changes of statuses to test the functionality.

Please play with advanced mode if you don’t happy with timeouts.

Home assistant configuration

Now notifications can be configured.

Please go to “Settings” -> “Automation & Scenes”, click “CREATE AUTOMATION” and choose “Start with empty automation”.

Add a “State” trigger, choose your device and name your trigger ID. A trigger ID is needed for perform an action depending on triggered device.

Please set your device as Entity or add some parameter of device if you can’t add a device.

 

You can point “Unavailable” in “To state” field. But Z2M provides also “Unknown” status for some issues with device. 

Thera are two ways:

  1. Add one more trigger for this state.
  2. Switch to “Edit in YAML” mode and edit your trigger manualy.

This is the code for trigger for two states:

 

platform: state
entity_id:
  - light.ikea_rgb_1
to:
  - unavailable
  - unknown
id: RGB_1_Lost_Connection

The trigger for restored connection looks similar:

platform: state
entity_id:
  - light.ikea_rgb_1
from:
  - unavailable
  - unknown
id: RGB_1_Connected

Add “Choose” Action:

Add condition “Triggered by” and choose your trigger.

After that, add “Call Service” action, choose notification method (telegram in my case) and add a message for

notification:

 

Save your automation and test it.

As a result you have a sample for notification about disconnected device.

So, you can configure notification for all your devices following the sample.

Also you can use YAML editor to create one trigger for all of your devices:

alias: Zigbee Lost connection notify
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.socket1
      - switch.socket2
      - switch.socket3
      - light.ikea_rgb_1
      - light.ikea_rgb_2
      - sensor.ikea_remote_lr_battery
      - sensor.hue_sensor_1_linkquality
      - sensor.aqara_thp_1_pressure
    id: connection_lost
    to:
      - unavailable
      - unknown
condition: []
action:
  - service: notify.telegram_to_me
    data:
      message: "{{trigger.to_state.attributes.friendly_name }}  lost connection "
mode: queued
max: 20

Pay attention to queued mode. Notifications should be sent one-by-one, otherwise, you can exceed Telegram (or another notification platform)  limits and lost notifications.

Please feel free to ask any questions in the comments.

Leave a Reply

Your email address will not be published. Required fields are marked *