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

Hey.

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

  - service: zha_toolkit.execute
    data:
      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!

Hi,
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
      sensor)
    service: zha_toolkit.attr_read
    data:
      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?

https://www.home-assistant.io/blog/2023/07/05/release-20237/#services-can-now-respond

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?

https://developers.home-assistant.io/blog/2023/06/14/service-calls/

https://github.com/home-assistant/architecture/discussions/777#discussioncomment-6127898

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

https://www.home-assistant.io/docs/scripts/service-calls#use-templates-to-handle-response-data

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

https://developers.home-assistant.io/docs/dev_101_services/#response-data

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.

https://developers.home-assistant.io/docs/dev_101_services/#supporting-response-data

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:

      hass.services.async_register(
          DOMAIN,
          SEARCH_ITEMS_SERVICE_NAME,
          search_items,
          schema=SEARCH_ITEMS_SCHEMA,
          SupportsResponse.ONLY,
      )

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.

zha-toolkit is now updated to provide response data and I updated one of the scripts to use it:

The response data is also provided by when calling the service interactively which is handier than having to check the even_data.

3 Likes

Hi

I’m trying to use Toolkit, which has been installed/activated correctly. I also activated the custom component under “log” in my configuration. I understand that the feedback from running the services will be listed in the Home Assistant core log file - correct? The problem is I see nothing in the log file.

Is there somebody who can point me in the direction of a solution?! :slight_smile:

image

One way to verify that zha-toolkit is correctly set up is to verify that they appear in “Developrer Tools > Services” (example in French):
image

Using that same location to run services, you can dynamically change the log level (no need to add them to you static configuration - the configuration is kept until reboot or another change):

service: logger.set_level
data:
  custom_components.zha_toolkit: debug
  zigpy.zcl: debug

It is true that the traces should occur in the log (/config/home-assistant.log).

With Home Assistant >=2023.7 and zha-toolkit>=v0.9.7, you can also see the response when using th e “Developer Tools>Services” without the need to activate logging or listen to events:

And when using a zha-toolkit service, you can get the result in a variable by adding “response_variable: …” to the service arguments.

Do you see the zha toolkit services? Do you have zha insdtalled as well (zha-toolkit ‘extends’ zha)? zha has services as well, so you can check that you have access to those:

image

@le_top have you looked at zha-toolkit using “Manufacturer OTA Firmware Update Support” (also referred to as “Generic OTA providers”) that was added with zigpy 0.56.3 release in HA 2023.8.1?

https://github.com/zigpy/zigpy/pull/1165

This allows for new OTA providers to be added to zigpy without extra code, which in turn also allows for users and manufacturers to distribute test feed URLs to customers without deploying them globally.

https://github.com/zigpy/zigpy/wiki/OTA-Information-for-Manufacturers

I believe that this could for example enable users to easier add to for example grab Zigbee OTA firmware files from Koenkk’s Zigbee OTA repo → https://github.com/Koenkk/zigbee-OTA/blob/ef0e28e5bdd0d5c6dca0bed4e5230b86bdea3e2c/index.json (as requested here → https://github.com/zigpy/zigpy/issues/535)

PS: puddly also added a new feature to the “zigpy-cli” tool that manufacturers can use to produce/generate a skeleton index from a given set of OTA files, and that way makes sure manufacturers OTA files are correctly-structured so that they will be compatible with this new JSON format for zigpy OTA providers out-of-the-box. Check out the README.md for the “zigpy-cli” (zigpy CLI tool) → https://github.com/zigpy/zigpy-cli/blob/dev/README.md#generate-ota-index-files