"zha-toolkit" - a big set of Zigbee commands on top of ZHA/zigpy

I just updated a system to 2023.2.1 to check this - I do not have an issue.

Check your logs to see if there is any message regarding zha_toolkit indicating some issue.

There can be several causes. For example: a user had two integrations managing the USB stick or once a zigpy/zha itself did not start (the user did a reboot and the system worked).

Upgrading to 2023.2.1 fixed it: the zha_toolkit services are now available again in the “Developers Tools” → “Service” menu.

I reliably do not get the zha_toolkit services. it appears despite the dependency in the manifest.json, that zha_toolkit is loading before ZHA:

2023-02-06 13:48:00.541 DEBUG (MainThread) [custom_components.zha_toolkit] hass.data['zha']['zha_gateway'] missing, not initializing zha_toolkit - zha_toolkit needs zha (not deconz, not zigbee2mqtt).

@tube0013 Can you see in the log that zha_toolkit is loadling before zha?
What version of HA are you using?

EDIT: I released v0.8.33 - hopefully that will allow zha-toolkit to be setup - it no longer expects “the gateway” to be defined in ZHA to do its own initialisation. Hopefully that fixes it. If not, zha-toolkit will have to be setup not testing anything about zha at startup at all and report that zha is missing later (on every zha-toolkit service call).


Ive created a sensor with attr_read/allow_create: true, but how do i remove that sensor?

  - service: zha_toolkit.execute
      command: attr_read
      ieee: 1f:ff:00:00:00:00:00:00
      cluster: 0x0000
      attribute: 0x0000
      state_id: sensor.new_sensor
      state_value_template: value / 100
      allow_create: true

So on Link to Entities – My Home Assistant you can tick the checkbox at the start of the line for an entity. A menu will appear at the top where the “red button” allows you to delete the selected entities.

I just had a chance to update, and seems to be reliably loading now. thanks!

Lately my zigbee coordinator goes offline sometimes.
I tried setting up an automation to warn me about that using the device_offline trigger, but that doesn’t seem to help. can zha_toolkit help here?

An indirect way of checking if you coordinator is offline, is likely to check the last_seen value of one or more devices that should always be online.

I gave an example how to access this data here:

ant there is also an example in the zha_toolkit repository:

That could be adjusted to find the most recent last_seen value, update a state and then use that state to generate an alert if the date is too old.

Hello @le_top. Thank you for your great work. Is it possible, to convert the zigbee2mqtt room-loadbalancing-blueprint fron napalm to zha? I use danfoss ally thermostats at my whole house (actually 11, but later 15) but sometimes grouped heaters are uneven hot. With z2m and room loadbalancing, they get even heat. But i have a lot of issues with z2m and would like to go back to zha.

Zigbee2MQTT - Danfoss Ally TRV Room Load Balancing - Blueprints Exchange - Home Assistant Community (home-assistant.io)

It is possible to implement this under ZHA, but there is some work to transform this, mainly to work with the load values.

I think of these 3 ways to do it (I can think of more, but these would be the ones I consider):

  1. Work purely with a yaml automation (/blueprint) and zha-toolkit features to read the load values;
  2. Extend the existing danfoss quirk/zha_device_handlers (+ZHA?) to add the load values as a state attribute. Then use this attribute in a yaml script.
  3. Implement part of the code in Python, and mix with a yaml automation. It is easy and dynamic to add a new service to ZHA-Toolkit. There could be a set of danfoss specific services, and we would need one that accepts a list of devices that need load balancing, and the python code would take care of getting the current load indicators, compute the totals and send them to the devices.
    It would then suffice to call this service on a regular basis.

1. Using Yaml and ZHA-Toolkit features.

a. One should verify/configure the Load reporting configuration of the Danfoss Valves. This is a one time configuration that could be added to the existing Danfoss configuration script.
A correct configuration ensures that the valves are reporting their load without a need to send a zigbee attribute read request to the valves.
b. The load values would then end up in the cached values in the zigpy/zha database. They can be read using a service call like this (the example is for reading a cached temperature value). The key elements in this example are (1) use_cache which avoids sending a read request to the valve, and (2) writing the result directly to a state value or state attribute which is then useable in the automation.

  - alias: Try to get more precise temperature (should work if zigbee temperature
    service: zha_toolkit.attr_read
      ieee: '{{ temp_sensor_id }}'
      use_cache: true
      cluster: 1026
      attribute: 0
      state_id: '{{ temp_sensor_id }}'
      state_attr: best_val
      state_value_template: value/100

c. Compute the total load value - use a repeat loop in yaml and use the attr_read service as shown in (b) to get the load value, and compute the required sum. After the sum, loop again and use attr_write to send this value to the valves.

2. Update the zha_quirk

Implies starting from the existing quirk and make necessary changes to make the load value accessible from Home Assistant. I know that ZHA has evolve recently to make some of that easier to implement.

3. Implement part of the code in Python

One could start by adding a user service as shown in the _user.py example and documented here.

Zha-toolkit reloads the code before calling it so one can evolve and test the code without restarting HA.

The command_data argument/field can be used to provide the list of devices in one room. The python code would then loop over this list, either use the ‘attr_read’ service by calling it internally with the proper arguments, or implement the reads more explicitly and check the cache using code as in zcl_attr.py.

1 Like

Thank you for your explanation. I thought, it would be much easier to implement this feature. :sweat_smile: Too bad, that my coding knowledge is nearly zero. Well, i have to stay at z2m then i think. :slight_smile:

@le_top Thanks again for continuing to develop zha-toolkit! Wondering if can suggest that you update your original post in this thread for the current feature so that it summarize is correct when it is linked:

:warning: HA2023.7 with zigpy 0.56.0 has breaking changes, you need to update to zha-toolkit v0.9.4

Can “responding services” feature from Home Assistant Core 2023.7 make ZHA Toolkit more useful?


Sounds also like this feature could make it easier to use ZHA services directly in an automation?

Hi @Hedda

zha-toolkit did not wait for such a feature for providing responses which can be fouind in the event data. There are some examples that demonstrate how to use that.

However, it would certainly beneficial to provide the data directly to the automation rather than having to retrieve it from the event (which is kind of complex to capture in an automation).
However, I did not find technical documentation on how to generate those responses in a component’s python by following the links in the release notes.

Home Assistant Developers Blog only mentions “service return values” which might be the same thing?



I did find this example on “Response Data” for services in the Home Assistant documentation:


and this about “service response data” in the developer’s documentation:


Release notes also mention that integration developers first need to enable it per service. So you can not get responses from just any service, instead, it has been enabled in the integration for each specific service that you want to be able to give a response.


As I understand, the release notes implies that other than for scripts it has so far only been enabled for calendar.list_events and conversation.process services in the Calander integration as an example so guess that integration developers would need to use that as a reference?

Perhaps @allenporter has more info or links on implementing responses for services in integrations?

You found everything… The last link is the developer docs for implementing this.

@Hedda Thanks for pulling this together.
@allenporter I agree that Integration Services | Home Assistant Developer Docs holds the relevant information.

The documentation suggests:


but then I get SyntaxError: positional argument follows keyword argument - I will find the correct way to do it (named argumetn or positional argument).

Submitted docs: fix Supporting Response Data example by pdecat · Pull Request #1853 · home-assistant/developers.home-assistant · GitHub to fix the documentation example.