From 55d8c859d9aadd8d6ff5d728371c27193305a35d Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Tue, 9 Aug 2022 17:39:28 +0200 Subject: [PATCH] Zigbee fix Aqara wrong battery --- .../xdrv_23_zigbee_5_converters.ino | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_5_converters.ino b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_5_converters.ino index dda3b7c4a..94095188d 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_5_converters.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_5_converters.ino @@ -2102,7 +2102,22 @@ void Z_postProcessAttributes(uint16_t shortaddr, uint16_t src_ep, class Z_attrib switch (ccccaaaa) { case 0x00000004: device.setManufId(attr.getStr()); break; case 0x00000005: device.setModelId(attr.getStr()); break; - case 0x00010021: device.setBatteryPercent(uval16 / 2); break; + case 0x00010021: + { + // if both BatteryVoltage and BatteryPercentage are zero, ignore + // Behavior seen on Aqara device when requesting cluster 0x0001 + bool valid_batt_voltage = true; + const Z_attribute * battVoltage_attr = attr_list.findAttribute(0x0001, 0x0020); + if (battVoltage_attr != nullptr) { + if (battVoltage_attr->getUInt() == 0) { + valid_batt_voltage = false; + } + } + if (valid_batt_voltage || uval16 > 0) { + device.setBatteryPercent(uval16 / 2); // set value only if both are not zero + } + } + break; case 0x00060000: case 0x00068000: device.setPower(attr.getBool(), src_ep); break; }