[ZHA] Read Cluster Attributes Programatically

Right now, a Zigbee cluster attribute can be set programmatically from a Python script like so:

service_data1 = {
    "ieee": "some_ieee",
    "endpoint_id": 11,
    "cluster_id": 6,
    "cluster_type": "in",
    "attribute": 16387,
    "value": 255,

hass.services.call("zha", "set_zigbee_cluster_attribute", service_data1, False)

However, I couldn’t find a way to read an attribute programatically. Maybe it’s possible through issue_zigbee_cluster_command, but I don’t know the command for that, and I couldn’t find any documentation on this.

This would be useful to verify certain actions, for example, that the above service call succeeded, or in general scripts where reading a cluster attribute is useful.

Concrete example: After configuring the Hue lights’ power-on behavior with set_zigbee_cluster_attribute, we want to verify that our operation was successful by reading that value after the change. Note that some ZHA commands fail silently (the set operation “works” but reading the value proves it didn’t actually succeed)

I was looking about the same! No one eve done this? Searching google I could not find any useful information about how to read an attribute value programmatically using ZHA… So I’m queuing in looking if someone reply to this.

Not sure I understand the question, but you can read the attributes from the event data.

You can read attributes by setting up a SQL sensor that read the attributes table in the zigbee.db file, but only if the attribute is one of those that are polled by ZHA. If you want to read an attribute not present there like you do in Clusters management in the device page? How do you do it?

I’m also following this. My new Aqara E1 roller blinds do not seem to report their actual state back. Only when I manually get the actual value, it updates.

I would like to write an automation for this, to periodically and/or after an action check the actual state of the roller blind.

1 Like

I’m also looking for this already long time. It can’t be difficult because we can read any cluster/attribute from ‘Manage Clusters’ page. We just need the same functionality with service call.
I try to rise this idea in GitHub

1 Like

Ran across this thread while browsing, I use node-red to achieve this. Simply add a home assistant “API” node, set the protocol to websocket and put in the data a json similar to this:

    "ieee": "XX:XX:XX:XX:XX:XX:XX:XX",
    "endpoint_id": 1,
    "cluster_id": 1794,
    "cluster_type": "in",
    "attribute": 0,
    "type": "zha/devices/clusters/attributes/value",
    "id": 52

Where “id” is a random number to identify the websocket command.

I have been using the solution from @antoineDion for more than a year. Its listed here - https://github.com/home-assistant/core/issues/44032.

It breaks once in a while when the ZHA component is updated, but then I just readd the tweaks as a ZHA_custom-component and voila - back in business. I then read the attribute using an automation.

1 Like

Can you please add the feature developed in this issue? zha.READ_zigbee_cluster_attribute · Issue #44032 · home-assistant/core · GitHub

1 Like