I just updated zha_custom - now zha-toolkit - to request a Zigbee Attribut read and get it directly into a Home Assistant state or state attribute without too much hassle:
Gone the days of writing stuff like:
- platform: sql
db_url: sqlite:////config/zigbee.db
scan_interval: 10
queries:
- name: current_demand
query: "SELECT value FROM attributes_cache_v7 where ieee = '00:12:b1:30:01:01:1e' and cluster = 2820 and attrid = 1295"
column: "value"
However, if Iām concerned about power consumption (using battery powered Zigbee devices), should I rather stick with the SQL method? Iām assuming that when executing attr_read, zha_toolkit sends a request to the device which will have to use power responding with the attribute?
Whereas the SQL method just reads from a database to which the desired attribute has already been pushed along with other attributes on a regular schedule (as far as I understand), thus not requiring any additional communication with the device?
Iām rather new to HA and ZHA, so please let me know if Iām totally off-field
I recently estimated the impact on increasing the number of requests to a zigbee device.
According to that computation it turned out that 1500 data requests per day represent only about 1% of the power consumption. There is a higher impact from the delay between the device wakeup times.
Basically when you make a request to the device, the request can only be made when the device is awake and checks if there is any pending request using a data request message (some documentation.
All then happens very quickly after that and the device will go to sleep again. The extra consumption from extra requests is fairly low according to the computations I used.
1500 requests is about 1 request every minute.
There is another method which is to set a reporting configuration for the attributes that you need, and - if not already supported natively in HA - add a listener for the ZHA events and get the data from the report packets. But that is harder to implement.
This works the same for sleepy devices when the attribute is considered āreadā. If there is no reply, you will not get a value. There is the possibility to use the cache.
So there are two ways to read an attribute:
Through actual reads - with sleepy devices you need to set ātriesā high enough so that the read requests are repeated until they succeed;
Use the āread from cacheā feature (use_cache option), and ensure that the sleepy devices report changes by themselves. The first example in the documentation sets āuse_cacheā to true.
Great tool and clear explanation butā¦are stumbling into a message āFailed to call service zha_toolkit.attr_read. Service response data expected a dictionary, was <class āNoneTypeā>ā. Perhaps somebody has experienced the same.
The case appears to be straightforward; floor heating thermostat with two temperature sensors. The standard ZHA integration only provide one of the two and I like to use the second. Using the āManage zigbeee deviceā menu in the standard ZHA integration, I can read the value. Ref two screendumps below.
The home-assistant.log file will have more information about this - in particular the stack trace.
I suspect that you should not provide the manf value - when you provide it the request is made in the manufacturer attribute space while the attribute you are showing is in the standard name space.
Thanks for the quick reply. I start to wonder if IĀ“ve made an error in configuration of the customer component (basically I just copied-pasted the custom component directory to my hass configuration folder structure) - and therefore it fails to call the service.
Let me dive into the github install instructions to check further.
You can copy zha-toolkit to the custom_component directory, but to enable it you currently need to add āzha_toolkit:ā to your configuration.yaml and restart.
As the services show up in your UI, I think you did that.
Just remove āmanf: 4512ā from your service call.
Thanks for your dedication to get this solved. Really appreciated.
Bit busy with normal life the coming 2 weeks so let me follow-up and check your suggestions a bit down the line.
Thanks again
A value that is reported is not automatically stored to a state. Some will be stored to a state because they are part of the values that are tracked through ZHA./zigpy settings, but most are not (especially if you want to track something āunusualā).
One method is to read the value on a regular basis from zigbee cache and update a state from it. The following yaml configuration does not serve that purpose, but it does have the same effect:
In some case, the entity will already have a state attribute value and you can make a normal state from it (with recorded history for instance) by using a the sensor template. Here āpi_heating_demandā is already available as a state attribute: