ZIGBEE (ZHA): Get a Cluster Attribute that isn't normally tracked

I have a Smart Things Multi sensor(Multi4)I’ve gotten working with ZHA. There are some attributes I can’t find in the pre-made senosrs that can be found in CentraLiteAccelCluster: x_axis, y_axis and z_axis; I need these exposed since I’d like to use this as a tilt sensor.

From Home Assistant I can see the attribute value if I go to Zigbee Home Automation, select the device, select the cluster then select the attribute and press “GET ZIGBEE ATTRIBUTE” but It is not exposed as a attribute anywhere else including node-red.

Is there a way to get this data, poll for the data or create a new sensor with it?
I am using HassOS 2.12 with v0.94.3.
I’ve looked at https://github.com/dmulcahey/zha-device-handlers/blob/master/zhaquirks/smartthings/multiv4.py but this seems mostly about identification(could be wrong?).
I’ve also looked at https://www.pydoc.io/pypi/ais-dom-0.72.8/autoapi/components/zha/index.html#module-components.zha and thoguht perhaps I could use _attempt_single_cluster_device, but this is obviously an internal method(that I’m sure I don’t fully understand here) and I don’t know how to call it.

I’ve also found zha.set_zigbee_cluster_attribute in the call services, which is super close to what I need, just need a get_ version of it.


Posting my solution for anyone else with this issue:

Okay, I’m experimenting with a possibility though I’m not sure how good of an idea it is.
I’ve noticed in the /config/zigbee.db that the attributes I want are tracked there so I’ve set up a sql sensor

  - platform: sql
    db_url: sqlite:////config/zigbee.db
    scan_interval: 10
      - name: PS4_x_axis
        query: "SELECT value FROM attributes where ieee = 'ieee address' and cluster = 64514 and attrid = 18"
        column: "value" 
      - name: PS4_y_axis
        query: "SELECT value FROM attributes where ieee = 'ieee address' and cluster = 64514 and attrid = 19"
        column: "value"
      - name: PS4_z_axis
        query: "SELECT value FROM attributes where ieee = 'ieee address' and cluster = 64514 and attrid = 20"
        column: "value"

I’m not sure how frequent the updates will be but I suspect it will update with the other sensor’s data such as acceleration which would be fine. I’ll post how it goes.

Seems to work great! Updates are frequent enough to catch when my garage door is open. Hopefully there are no issues I’m missing.

This will allow me to use my smartthings multisensor (multi4) as a garage door tilt sensor (to tell if the garage door is open or closed).

The image shows from horizontal to vertical, so I’ll just need to add a sensor template with < 100 open and >= 100 closed.

Below is my binary_sensor setup for anyone interested. I just did 500 instead of 100 since it splits the difference.

- platform: template
      device_class: opening
      value_template: "{{ states('sensor.PS4_z_axis')|float > 500 }}"

Great! Works!
I have a zigbee smart plug which accumulates the power consumption in the metering cluster (0x702) attribute 0. I can read it now!

@dargonos Do you find that the zigbee.db file gets updated fast enough with the attribute value? I’m looking to do something similar but I need to get an updated value every 1 second. It doesn’t seem like the database file is updated that often though :frowning:

For my purposes it updates fast enough but it really seems to be dependant, not on the database, but how fast the Zigbee device updates. You could drop scan_interval: to 1 and see.

I’m using Multi4’s (1st gen smartthings multi sensor) and I’ve noticed that the db derived (x,y,z coords) sensor updates occur just as fast as the any other normally monitored sensor such as the acceleration sensor. With the Multi4, it updates very quickly when something is happening, such as motion, and very slowly when idle… which makes sense.

I’ve noticed the updates(at least on battery powered devices known as “sleepy” devices) are pushed typically, meaning the device decides when to send them(you can see this happen in the logs when devices are joining) so it is really up to your device you want info from.

In 0.100.x the multi-sensor is working with latest native zha setup.

I unpaired mine, reset it, and re-added it and x, y, and z showed in the logs and the binary sensor responded to vibrations without having to change a thing.

Thanks for your efforts, Jeff! This worked great until better HA support arrived.

1 Like

I’m running 0.107.7 and x,y,z still don’t get added as entities.
The values do show in the logs as you stated.

Thanks a million @dargonos! This would’ve taken me quite a while to solve.
I was really disappointed because i was using this sensor thru smartthings hub and I had the xyz values. But it was a bit too far from the hub so i switched it to the ZHA hub which is closer and then discovered I’d lost what I depended on!

FYI: Using this as a tilt sensor for a spa cover. Contact sensor doesn’t work in that case because there’s too much slop in the positioning.

I’m really glad I found this thread. Thanks for taking the time to figure that out!

Additionally, CASE and value comparisons seem to work pretty well. No need for additional templates, which wasn’t really suiting my needs. You could always do another query for the direct value should you need it.

      - name: garage_tilt_sensor_x_axis
        query: "SELECT CASE WHEN value < 1000 then 'closed' WHEN value > 1000 then 'open' END result FROM attributes where ieee = 'xxxxxxxx' and cluster = 64514 and attrid = 18 "
        column: result

you’ll see your sensor state comes back as the value of ‘result’.

How do you open zigbee.db to see it’s content? What format zha uses for db?

zigbee.db is a SQLite format. SQLite Browser is what I use to view the data within.

Do you know how to read attribute which is not in zigbee.db but has value when I look with ‘Manage Clusters’?
I have Schwaiger power socket which measures delivered energy but this attribute is not in zigbee.bd.
How can I read this value from device cluster in template?

I too hope that our courageous developers start adding other clusters to ZHA.

1 Like

With ‘Manage Clusters’ is possible read all clusters and attributes.
We just need some sort of query, like platform: sql, to read directly from zigbee devices.
Maybe there is already such way, but I can’t find it.

@ratsepa You may have already done this but how I found it:

  1. Open config/zibee.db with DB Browser for SQLite
  2. Click on the Browse Data Tab
  3. Select the attributes table
  4. Under ieee Filter enter the IEEE number found under Integrations->Zigbee->configure->devices->Device Name->Under Zigbee info (just copy and paste it)

All the tracked items are will be listed there.

If its NOT tracked there, it kinda goes back to my original problem of looking for an option to poll a Zigbee attribute from automation.


hello friend, you did a good job, thank you
do you know how to get WYZE LOCK status, like door is opened, closed, locked manually and unlocked manually?
thank you

@akhlghatyan Sorry, I don’t have this device so I can’t say for sure. I would recommend first checking in the device states under Developer Tools->States. Most things are tracked there and can be accessed with automation.

If you can’t find it there and it is a Zigbee device, you can check under Clusters under the zigbee integration… you’ll need to hunt for it.
Congig->integrations->zigbee->devices->(device you want to check)->Manage Clusters
You select Clusters then attribute to see what is in it.

Thanks a lot, I solved my problem


I’m using Moes TRVs. However ZHA doesn’t support battery percentage.
In clusters I found that there’s a battery low warning (binary).
Now I want to make a binary sensor with this data.
Did anyone figure out how to do this?

Thanks in advance!

This solution to read data from the smartthings sensors has been working great for over a year, but I just noticed the other day it stopped working. I’m thinking most likely it stopped after recently updating homeassistant.

Has anyone else seen this happen? It is still reading a value from the zigbee.db file but it never updates based on the orientation of the device.

I had been fighting with this issue after a recent update as well. Turns out ZHA updated their schema and the attributes table is currently called attributes_cache_v6.

So the query from above is now…

SELECT CASE WHEN value < 1000 then 'closed' WHEN value > 1000 then 'open' END result
FROM attributes_cached_v6
WHERE ieee = 'xxxxxxxx' and cluster = 64514 and attrid = 18

It looks like ZHA may be continuing with versioning their table names moving forward as well. I think I saw a reference to attributes_cached_v7 somewhere. So this issue may pop up again.

1 Like