While I can control the lights without any issues and the devices are running the latest firmware, the battery status does not display.
However, I can read the battery status using the Cluster command and get a correct value from 0 to 200 for battery_percentage_remaining (id: 0x0021).
Interestingly, the lights are showing as main-powered instead of battery-powered.
Does anyone have any ideas on how to solve this issue?
I also couldn’t create a sensor with the battery value of the hive via ZHA.
Seems, the function zha.read_zigbee_cluster_attribute isn’t implemented yet (see also topics here in the forum and on Github)
A possible solution is to install the HACS-integration zha-toolkit with its function zha_toolkit.attr_read.
An automation reads the battery level periodically, writes the value into a helper (input_number), which is used as base for the battery-sensor (helper/template-sensor):
Add helper “template” (sensor): sensor.hive_battery
with state template:
{{ (states('input_number.hive_battery_measure') | int / 2 ) | round(0) }}
Add automation:
alias: Hive Battery
description: ""
trigger:
- platform: time_pattern
hours: /1
condition:
- alias: Test if available
condition: not
conditions:
- condition: or
conditions:
- condition: state
entity_id: light.hive
state: unknown
- condition: state
entity_id: light.hive
state: unavailable
action:
- service: zha_toolkit.attr_read
data:
ieee: light.hive
endpoint: 1
cluster: 1
attribute: 33
state_id: input_number.hive_battery_measure
mode: single
The automation reads the battery value once an hour, what seems enough for me and doesn’t drain the battery too much. To prevent errors, a condition checks whether the lamp is (not) available. The attribute 33 is the decimal equivalent for hex 0x0021, the id of Hives cluster attribute battery_percentage_remaining.
In the template, the measured battery value is converted into an integer percentage value (division by 2).
Apparently the battery level changes in steps of 20, the sensor accordingly by 10%.
Oh, wow - nice work!
Seems to be a solution without extra stuff like zha-toolkit.
How did you built this custom quirk, and where is it stored to be available in home assistant?
Did you publish it anywhere, e.g. on https://github.com/zigpy/zha-device-handlers