How to detected when ZigBee entity is offline or timeout'ed

Hi,
Iam using serveral Aquara temperature sensors (lumi weather) to track temperature in my house. As router I use SONOFF ZigBee Bridge (ZHA).

Temperature reading will be used to controll floor heating. They will travel to heating controller from home assistant over MQTT using mqtt_statestream.

So i need a way to know last temperature reading is too old and no longer actual

Any suggestions how to achive this?

from my observations:

  • mqtt_statestream posts temperature only when it changes. so when temperature not changing - no messages
  • i removed the battery from one of temperature senors almost 2 hours ago, but it hapily shows last known temperature
1 Like

This seems to be a tough problem currently. Several discussion around this on the forums, none I’ve seen have yielded a good solution.
On ZHA, the entity state for a zigbee sensor should go to ‘unknown’ when this sensor does not report in. In ZHA, the device is set to ‘offline’ and then I believe ZHA passes the ‘unknown’ value along to the HA entity state at this point. However this ‘reporting in window’ seems to be up to the individual zigbee device manufacture to set. I’ve yet to see period that is less than 10’s of minutes and some are hours. My Aqara Lumi weather sensors report temperature on average a little over 2.3 times per hour (over 10 day example shown below). So backing into a solution with the Aqara, you could set an automation if you did see any update say every 45 minutes, but this not a great solution.

I have yet to find a zigbee temperature sensor that will report much above this number per hours. I have heard reports that is possible to set the Sonoff SNZB-02 to report at higher frequency, but I have to see a set of instructions on how to accomplish this under any of the zigbee systems, Deconz, zigbee2mqtt or ZHA.

I would recommend going with a bluetooth low energy set of sensors. You want temperature updates tens of time per minute, this is what you can get with some of the BLE sensors. 2 updates per hour with zigbee sensors is not the level to useful IMHO. There are multiple ways to setup a network of them with Home Assistant. You can find them here on this forum. I created one for my houses, I have twenty BLE sensors in and around a house using a dedicated raspberry pi to collect the data. Depending on the BLE sensor you select you can get tens of samples per minute. I monitor my BLE sensors updates with a monitoring program, if it does not see an update in mqtt for a given period, it will attempt to reboot the raspberry pi collector and send an alert notification to mobile phones. The chart at the link below shows the update frequency of several BLE sensors. Good hunting!

https://github.com/deepcoder/bluetooth-temperature-sensors
2 Likes

Thanks for detailed answer David.

After little bit of reading on how ZigBee works now i see there is no way to “PING” the bettery powered devices. So this leaves time gap between entity gets unavailable state and device is actually offline.
My sensor with removed battery got unavailable state after around 6 hours. I beleave this numbers is somewhere hardcoded or configured. I will try to find out if it is possible to adjust.

I found that zigbee2mqtt has something like this. AC powered devices can be pingend, and for battery powered they say it is 25 hours :open_mouth:

https://www.zigbee2mqtt.io/information/availability.html

Also i got one more idea. The device itself has “Last Seen” attribute. I think this attribute is updated when one of senor entities receives new value. My sesnor has 4 (temperature, battery, humidity, pressure). I see “Last Seen” attribute is no older than 30 min for online devices.
Main question here is how could i get this attribute pushed out to MQTT to make decisions in heating controller about temperature reading is timeout’ed or not.

DeviceInfo

P.S. currently iam using BLE sensors, gathering thier data with ESP8266 flashed with ESPHOME witch posts data to MQTT. Now just decided to try ZigBee for making my house more smart (light swithches etc.)…

1 Like

One place I found where “last seen” can be taken is a file /config/.storage/zha.storage
e.g.:

{
    "version": 1,
    "key": "zha.storage",
    "data": {
        "devices": [
            {
                "name": "Silicon Labs EZSP",
                "ieee": "60:a4:23:ff:ff:ff:ff:ff",
                "last_seen": 1624646040.4617698
            }, 
           [...]

So I am reading this file with a Node-RED ‘function’ node, parsing the data with a small Javascript code (e.g. converting the UNIX timestamp to a human readable) and doing actions like sending notifications, etc.

Frankly, I am not sure if this is the optimal way to do it, but after searching for info how to fetch “last seen” timestamp I did not find any alternatives.

Watching this parameter is important, as I have seen cases when “last UPDATED” attribute of a Zigbee entity has been refreshed (e.g. after HASS restart), but “last seen” of the Zigbee device has not, whereas actually the device became offline and needed attention.

1 Like

I have created a feature request for this exact thing but it is not gaining much traction. I guess that more votes are needed.

ZHA show last_seen, LQI and RSSI as entity attributes - Feature Requests - Home Assistant Community (home-assistant.io)

6 Likes

re
I was looking for how to get my SNZB-02 temp and humidity sensor reporting more frequently (actually, the temp has been reporting the same figure for a really long time - it seems stuck). I found a discussion on the Deconz github about changing some values relating to reporting frequency, that it may also be possible to change via MQTT or ZHA. I use ZHA so tried the following just now:

  1. Go to Configuration > Devices and Services > Devices > Zigbee Home Automation Devices then select the SNZB-02
  2. Click Manage Clusters
  3. Under Clusters select TemperatureMeasurement
  4. Under Cluster Attributes select measured_value
  5. For Value type maxInterval
  6. For Manufacturer Code Override type 300
  7. Click Set Zigbee Attribute

I am not sure if this applied. I tried to quickly do this after re-pairing the sensor to ZHA. I’m not sure I have the syntax right either :slight_smile:

I’ve created sort of a workaround as last_seen is not available on zha devices: How can I read the "Last Seen" value of Zigbee device? - #10 by oveand

1 Like