k.v.riel
(Ken)
January 18, 2022, 9:42pm
1
I’m trying to read the battery percentage of my device and it will not register the attribute handler on initialization.
I’m using the following code to register the powerConfiguration, also tried the onOff attribute and that one is working.
zigbee_handlers = {
attr = {
[clusters.PowerConfiguration.ID] = {
[clusters.PowerConfiguration.attributes.BatteryPercentageRemaining.ID] = commands.BatteryPercentageRemaining
}
}
}
Logging shows that it’s not picking up the powerConfiguration
default_handlers:
attr:
global:
cluster:
ZclClusterCommandHandler: cluster: Level, command: Move
ZclClusterCommandHandler: cluster: Level, command: MoveWithOnOff
ZclClusterCommandHandler: cluster: Scenes, command: 0x08
ZclClusterCommandHandler: cluster: Scenes, command: 0x07
ZclClusterCommandHandler: cluster: OnOff, command: On
ZclClusterCommandHandler: cluster: OnOff, command: Off
zdo:
child_dispatchers:
I don’t know if it’s because you haven’t assigned the attribute handler to a function.
Should be?
[clusters.PowerConfiguration.ID] = {
[clusters.PowerConfiguration.attributes.BatteryPercentageRemaining.ID] = commands_BatteryPercentageRemaining
}
k.v.riel
(Ken)
January 18, 2022, 10:07pm
3
I’m using a class where I write all my commands, so that is why you see.
commands.BatteryPercentageRemaining
function commands.batteryPercentageRemaining(_, device, command, args)
...some code...
end
1 Like
k.v.riel:
I’m using a class where I write all my commands, so that is why you see.
commands.BatteryPercentageRemaining
function commands.batteryPercentageRemaining(_, device, command, args)
...some code...
end
Yes, that’s right, I also use it in some drivers
But I think that the value of the attribute is going to be sent in the zb_rx message (value.value
) and not in the command .
I always get the value of the attribute for the handler according to the defaults handler:
function battery_defaults.battery_perc_attr_handler(driver, device, value, zb_rx)
device:emit_event_for_endpoint(
zb_rx.address_header.src_endpoint.value,
capabilities.battery.battery(math.floor(value.value / 2.0 + 0.5))
)
end
I use function xxxxx(_, device, command)
to handle capabilities commands, on-off commands for example
1 Like
k.v.riel
(Ken)
January 18, 2022, 10:49pm
5
I got it working, it’s the amount of arguments given to the function.
This was what I had, and the args in this case is a argument to much.
function commands.batteryPercentageRemaining(_, device, command, args)
...some code...
end
This is what I have now
function commands.batteryPercentageRemaining(_, device, attribute)
...attribute.value...
end