Z2M does not send MQTT message when SNZB-02WD reports 0% battery, causing battery level not to display on the page
What happened?
I have encountered an issue with the Sonoff SNZB-02WD temperature and humidity sensor in Zigbee2MQTT (Z2M). When the device reports a battery level of 0%, Z2M does not send an MQTT message. As a result, the battery level is not displayed on the user interface, which creates confusion for users regarding the battery status.
What did you expect to happen?
When the SNZB-02WD sensor reports a 0% battery level, Zigbee2MQTT should send an MQTT message so that the UI can display the battery status correctly (even when it is 0%).
How to reproduce it (minimal and precise)
No response
Zigbee2MQTT version
2.9.1
Adapter firmware version
7.4.5
Adapter
ember
Setup
Windows
Device database.db entry
No response
Debug log
No response
Notes
No response
Based on my investigation, the issue lies in the battery method within the modernExtend.ts file of the ZHC project. In this method, when batteryPercentageRemaining is 0, percentage is also set to 0, causing payload.battery to remain unchanged. As a result, no MQTT message for the battery level is sent, and the page fails to display the battery level.
Thanks for finding the issue, fixed!
Changes will be available in the dev branch in a few hours from now and in the next release which is every 1st of the month.