There was a bug in zigpy which was fixed lately and zha-toolkit was also corrected/evolved to support array reads and writes. See this pull request in zha-toolkit.
And you can read about it in the documentation (look for “ZCL Array type”) .
There was a bug in zigpy which was fixed lately and zha-toolkit was also corrected/evolved to support array reads and writes. See this pull request in zha-toolkit.
And you can read about it in the documentation (look for “ZCL Array type”) .
Hi @le_top , I succeed to write array to an attribute with the commande
service: zha_toolkit.attr_write
data:
ieee: 50:0b:91:40:00:03:ed:b0
endpoint: 1
cluster: 0xff01
attribute: 0x0240
attr_type: 0x48
attr_val: [32, 12, 0, 194, 17, 0, 0, 136, 119, 0, 0, 1, 0, 0, 0]
read_before_write: true
read_after_write: true
When I check the value in ZHA It is ok but the attr_write commande still give an error at the end. Look like it want to convert data to json. See the log.
2023-11-05 21:18:51.929 DEBUG (MainThread) [custom_components.zha_toolkit.zcl_attr] Reading attr result (attrs, status): ({576: Array(type=AnonymousLVList, value=[194, 17, 0, 0, 136, 119, 0, 0, 1, 0, 0, 0])}, {})
2023-11-05 21:18:51.929 DEBUG (MainThread) [custom_components.zha_toolkit.utils] Can't convert Array(type=AnonymousLVList, value=[1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]) to JSON, serializing if possible.
2023-11-05 21:18:51.930 DEBUG (MainThread) [custom_components.zha_toolkit.utils] Can't convert Array(type=AnonymousLVList, value=[194, 17, 0, 0, 136, 119, 0, 0, 1, 0, 0, 0]) to JSON, serializing if possible.
2023-11-05 21:18:51.931 DEBUG (MainThread) [custom_components.zha_toolkit] event_data {'zha_toolkit_version': 'v1.1.5', 'zigpy_version': '0.59.0', 'zigpy_rf_version': '0.21.1', 'ieee_org': 50:0b:91:40:00:03:ed:b0, 'ieee': '50:0b:91:40:00:03:ed:b0', 'command': 'attr_write', 'command_data': None, 'start_time': '2023-11-06T02:18:51.816641+00:00', 'errors': ["UnicodeDecodeError('ascii', b' \\x0c\\x00\\xc2\\x11\\x00\\x00\\x88w\\x00\\x00\\x01\\x00\\x00\\x00', 3, 4, 'ordinal not in range(128)')"], 'params': {'endpoint_id': 1, 'cluster_id': 65281, 'attr_id': 576, 'attr_type': 72, 'attr_val': [32, 12, 0, 194, 17, 0, 0, 136, 119, 0, 0, 1, 0, 0, 0], 'dir': 0, 'tries': 1, 'expect_reply': True, 'args': [], 'read_before_write': True, 'read_after_write': True}, 'compare_val': [32, 12, 0, 194, 17, 0, 0, 136, 119, 0, 0, 1, 0, 0, 0], 'attr_type': '0x48', 'write_is_equal': False, 'read_before': ({576: ' \x0c\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00'}, {}), 'result_write': Write_Attributes_rsp(status_records=[WriteAttributesStatusRecord(status=<Status.SUCCESS: 0>)]), 'result_read': ({576: Array(type=AnonymousLVList, value=[194, 17, 0, 0, 136, 119, 0, 0, 1, 0, 0, 0])}, {}), 'success': False}
2023-11-05 21:18:51.937 ERROR (MainThread) [custom_components.zha_toolkit] Exception ''ascii' codec can't decode byte 0xc2 in position 3: ordinal not in range(128)' for service call with data '{'zha_toolkit_version': 'v1.1.5', 'zigpy_version': '0.59.0', 'zigpy_rf_version': '0.21.1', 'ieee_org': 50:0b:91:40:00:03:ed:b0, 'ieee': '50:0b:91:40:00:03:ed:b0', 'command': 'attr_write', 'command_data': None, 'start_time': '2023-11-06T02:18:51.816641+00:00', 'errors': ["UnicodeDecodeError('ascii', b' \\x0c\\x00\\xc2\\x11\\x00\\x00\\x88w\\x00\\x00\\x01\\x00\\x00\\x00', 3, 4, 'ordinal not in range(128)')"], 'params': {'endpoint_id': 1, 'cluster_id': 65281, 'attr_id': 576, 'attr_type': 72, 'attr_val': [32, 12, 0, 194, 17, 0, 0, 136, 119, 0, 0, 1, 0, 0, 0], 'dir': 0, 'tries': 1, 'expect_reply': True, 'args': [], 'read_before_write': True, 'read_after_write': True}, 'compare_val': [32, 12, 0, 194, 17, 0, 0, 136, 119, 0, 0, 1, 0, 0, 0], 'attr_type': '0x48', 'write_is_equal': False, 'read_before': ({576: ' \x0c\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00'}, {}), 'result_write': Write_Attributes_rsp(status_records=[WriteAttributesStatusRecord(status=<Status.SUCCESS: 0>)]), 'result_read': ({576: Array(type=AnonymousLVList, value=[194, 17, 0, 0, 136, 119, 0, 0, 1, 0, 0, 0])}, {}), 'success': False}'
2023-11-05 21:18:51.940 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: 'ascii' codec can't decode byte 0xc2 in position 3: ordinal not in range(128)
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 704, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 666, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/__init__.py", line 825, in toolkit_service
raise handler_exception
File "/config/custom_components/zha_toolkit/__init__.py", line 781, in toolkit_service
handler_result = await handler(
^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/__init__.py", line 891, in command_handler_default
return await default.default(
^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/default.py", line 40, in default
await handler(app, listener, ieee, cmd, data, service, params, event_data)
File "/config/custom_components/zha_toolkit/zcl_attr.py", line 645, in attr_write
u.dict_to_jsonable(event_data[key][0]),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/utils.py", line 476, in dict_to_jsonable
value = str(value, encoding="ascii")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 3: ordinal not in range(128)
2023-11-05 21:18:51.970 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [547857616448] Error handling message: Unknown error (unknown_error) Claude Gelinas from 192.168.2.40 (Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36)
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response
await func(hass, connection, msg)
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 731, in handle_execute_script
script_result = await script_obj.async_run(msg.get("variables"), context=context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1578, in async_run
return await asyncio.shield(run.async_run())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 420, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 470, in _async_step
self._handle_exception(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 493, in _handle_exception
raise exception
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 704, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 666, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/__init__.py", line 825, in toolkit_service
raise handler_exception
File "/config/custom_components/zha_toolkit/__init__.py", line 781, in toolkit_service
handler_result = await handler(
^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/__init__.py", line 891, in command_handler_default
return await default.default(
^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/default.py", line 40, in default
await handler(app, listener, ieee, cmd, data, service, params, event_data)
File "/config/custom_components/zha_toolkit/zcl_attr.py", line 645, in attr_write
u.dict_to_jsonable(event_data[key][0]),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/utils.py", line 476, in dict_to_jsonable
value = str(value, encoding="ascii")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 3: ordinal not in range(128)
I had some doubts about this method of conversion proposed here and there - checkout beta v1.1.6 .
Hi @le_top , I’m trying to read a value like this
service: zha_toolkit.attr_read
data:
ieee: climate.salle_de_bain_thermostat
cluster: 0xff01
attribute: 0x010d
manf: 0x4508
state_id: sensor.room_temperature
state_value_template: {{ value / 100 }}
allow_create: true
force_update: true
use_cache: true
event_success: my_read_success_trigger_event
event_fail: my_read_fail_trigger_event
event_done: my_read_done_trigger_event
without the line
state_value_template: {{ value / 100 }}
it work but I dont know how to write the state_value_template. I need to divide the value by 100 to get wright temperature
The state value template should work as any template but you should not add the ‘{ { }}’ as we do not want it to be resolved by home assistant immediately.
You should submit it as a string.
zha-toolkit then has HA resolve the expression and provides the content for “value” at that time (after having read the attribute from cache in this case).
So the example you provide should work if you remove the ‘{{ }}’ parentheses.
Your probably do not need to set the event options anymore. Interactively we see the response data in the UI when executing the service call and in a script or automation you can use ‘response_variable’ which is more efficient. There is a post above where I give some information and a complex example for response_variable.
Edit: I use this in the automation (blueprint): https://github.com/mdeweerd/zha-toolkit/blob/e320f98ae4f643efef5679d0b3fb91c9ad8dd5c5/blueprints/danfoss_ally_remote_temperature_min_delay.yaml .
Thank you, could be good to remove the {{ }} in description of zha_toolkit.attr_read
state_value_template
When defined, the read attribute is converted using this template before writing it to the state. {{ value / 100 }}
state_value_template: “value / 100” work perfectly
I had to search a bit where that was as the documentation was ok - it was present in the services.yaml which I updated now. It’s not released yet.
Thanks, sorry I should have think of service.yaml
No problem, but it helps to be more precise - if you would have shared that this was in the Developer > Service UI or in the Automation UI I would have been less puzzled why it was not in the README. Anyway, not always easy to think about that ;-).
Is there a reason that we cannot read array value for this cluster 0xff01, attribute 0x0101. There is no value in scan device as below and there is an error in log
"0x0101": {
"attribute_id": "0x0101",
"attribute_name": "unknown_attr_7",
"value_type": [
"0x48",
"Array",
"Discrete"
],
"access": "READ|REPORT",
"access_acl": 5,
"manf_id": 4508
Log error show this:
2023-11-26 17:16:59.511 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [547609737280] Error handling message: Unknown error (unknown_error) Claude Gelinas from 192.168.2.40 (Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36)
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response
await func(hass, connection, msg)
File "/usr/src/homeassistant/homeassistant/components/zha/websocket_api.py", line 827, in websocket_read_zigbee_cluster_attributes
success, failure = await cluster.read_attributes(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/zigpy/zcl/__init__.py", line 531, in read_attributes
orig_attribute = orig_attributes[record.attrid]
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 256
with 1.1.6 it was scanning device except array
With 1.1.7 it give error as follow
2023-11-26 20:46:51.348 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: 256
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 704, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 666, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/__init__.py", line 825, in toolkit_service
raise handler_exception
File "/config/custom_components/zha_toolkit/__init__.py", line 781, in toolkit_service
handler_result = await handler(
^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/__init__.py", line 891, in command_handler_default
return await default.default(
^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/default.py", line 40, in default
await handler(app, listener, ieee, cmd, data, service, params, event_data)
File "/config/custom_components/zha_toolkit/scan_device.py", line 445, in scan_device
scan = await scan_results(
^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/scan_device.py", line 92, in scan_results
await scan_endpoint(
File "/config/custom_components/zha_toolkit/scan_device.py", line 112, in scan_endpoint
clusters[key] = await scan_cluster(
^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/scan_device.py", line 148, in scan_cluster
await discover_attributes_extended(
File "/config/custom_components/zha_toolkit/scan_device.py", line 266, in discover_attributes_extended
success, failed = await read_attr(
^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/scan_device.py", line 29, in read_attr
return await cluster.read_attributes(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/zigpy/zcl/__init__.py", line 531, in read_attributes
orig_attribute = orig_attributes[record.attrid]
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 256
There should have been something that change in zigpy as about 2 week ago I was able to read array in ZHA manage zigbee device and now it is not working. Same error 256 as in zha toolkit scan_device
I agree that this is likely a change in zigpy.
It reminded me of something I did for commands: zigpy does or did not work when the command we try to send is/was not known to zigpy.
The workaround was to add the missing command to the zigpy internal data structure as in the following code:
Possibly this is now also needed for unknown attributes.
A recent change made to zcl/__init__py is below:
It could be the reason for the new issue because orig_attributes is built from the attributes dict that seems to be impacted by this - this is the change (added else: and the next line):
else:
attr = attr.replace(id=attr_id)
cls.attributes[attr.id] = attr.replace(id=attr_id)
The error occurs just after getting the attributes back from a successful read.
The attribute id somehow disappears from the attributes list.
result = await self.read_attributes_raw(to_read, manufacturer=manufacturer)
#[...]
else:
for record in result[0]:
orig_attribute = orig_attributes[record.attrid] # fails here...
Other potential reasons I see are:
I guess that more logging (zigpy low level traces) is useful to identify what is received and how it was decoded + ideally the corresponding sniffed packet.
You could at least set this:
service: logger.set_level
data:
custom_components.zha_toolkit: debug
zigpy.zcl: debug
or more:
service: logger.set_level
data:
custom_components.zha_toolkit: debug
zigpy: debug
zigpy_deconz.zigbee.application: debug
zigpy_deconz.api: debug
##zigpy_xbee.zigbee.application: debug
zigpy_xbee.api: debug
zigpy_zigate: debug
zigpy_znp: debug
bellows: debug
zhaquirks: debug
## Extra, not sure this works:
zigpy.zdo: debug
zigpy.device: debug
zigpy_znp.api: debug
zigpy_znp.zigbee.zdo_converters: debug
zigpy_znp.zigbee.application: debug
zigpy_znp.commands.application: debug
zigpy_znp.commands.zdo: debug
zigpy_znp.commands.znp: debug
zigpy_znp.logger: debug
zigpy.util: debug
Here is the log for the section where it fail. It was reading cluster 0xff01, attribute 160, 161, 176, 257 which are
0x00A0 |160 |t.uint32_t |Timer |Time, 1 to 86400 second
0x00A1 |161 |t.uint32_t |Timer_countDown |Seconds remaining on timer
0x00B0 |176 |t.Bool |unknown |1 |read/report|
0x0101 |257 |Array ||read/report ||
Look like array is empty but after reading those attribute it try reading
ReadAttributeRecord(attrid=0x0000, status=<Status.FAILURE: 1>), ReadAttributeRecord(attrid=0x0000, status=<Status.FAILURE: 1>)])
There is no attribute 0x0000 in cluster 0xff01
attributes are: [1, 2, 3, 4, 53, 55, 56, 96, 112, 116, 118, 119, 120, 121, 122, 123, 124, 125, 128, 144, 160, 161, 176, 257, 298, 300, 512, 514, 515, 640, 641, 642, 643, 644, 65533]
The next attribute after the array (257) is 298 which is of type enum8. So I presume that it fail on reading array. see the log
023-11-27 21:46:00.136 DEBUG (MainThread) [zigpy.zcl] [0x448B:1:0xff01] Sending request: Read_Attributes(attribute_ids=[160, 161, 176, 257])
2023-11-27 21:46:00.137 DEBUG (MainThread) [zigpy_deconz.zigbee.application] Sending packet: ZigbeePacket(timestamp=datetime.datetime(2023, 11, 28, 2, 46, 0, 137116, tzinfo=datetime.timezone.utc), src=AddrModeAddress(addr_mode=<AddrMode.NWK: 2>, address=0x0000), src_ep=1, dst=AddrModeAddress(addr_mode=<AddrMode.NWK: 2>, address=0x448B), dst_ep=1, source_route=None, extended_timeout=False, tsn=225, profile_id=260, cluster_id=65281, data=Serialized[b'\x04\x9c\x11\xe1\x00\xa0\x00\xa1\x00\xb0\x00\x01\x01'], tx_options=<TransmitOptions.NONE: 0>, radius=0, non_member_radius=0, lqi=None, rssi=None)
2023-11-27 21:46:00.137 DEBUG (MainThread) [zigpy_deconz.api] Command Command.aps_data_request (28, 226, <DeconzSendDataFlags.NONE: 0>, <DeconzAddressEndpoint address_mode=AddressMode.NWK address=0x448b endpoint=1>, 260, 65281, 1, b'\x04\x9c\x11\xe1\x00\xa0\x00\xa1\x00\xb0\x00\x01\x01', <DeconzTransmitOptions.USE_NWK_KEY_SECURITY: 2>, 0)
2023-11-27 21:46:00.140 DEBUG (MainThread) [zigpy_deconz.api] Received command aps_data_request[2, <DeviceState.APSDE_DATA_REQUEST_SLOTS_AVAILABLE|2: 34>, 226]
2023-11-27 21:46:00.141 DEBUG (MainThread) [zigpy_deconz.api] APS data request response: [2, <DeviceState.APSDE_DATA_REQUEST_SLOTS_AVAILABLE|2: 34>, 226]
2023-11-27 21:46:00.149 DEBUG (MainThread) [zigpy_deconz.api] Received command device_state_changed[<DeviceState.APSDE_DATA_CONFIRM|APSDE_DATA_REQUEST_SLOTS_AVAILABLE|130: 166>, 0]
2023-11-27 21:46:00.149 DEBUG (MainThread) [zigpy_deconz.api] Device state changed response: [<DeviceState.APSDE_DATA_CONFIRM|APSDE_DATA_REQUEST_SLOTS_AVAILABLE|130: 166>, 0]
2023-11-27 21:46:00.150 DEBUG (MainThread) [zigpy_deconz.api] Command Command.aps_data_confirm (0,)
2023-11-27 21:46:00.152 DEBUG (MainThread) [zigpy_deconz.api] Received command aps_data_confirm[12, <DeviceState.APSDE_DATA_REQUEST_SLOTS_AVAILABLE|2: 34>, 226, <DeconzAddressEndpoint address_mode=AddressMode.NWK address=0x448b endpoint=1>, 1, <TXStatus.SUCCESS: 0>, 0, 0, 0, 0]
2023-11-27 21:46:00.153 DEBUG (MainThread) [zigpy_deconz.api] APS data confirm response for request with id 226: 00
2023-11-27 21:46:00.153 DEBUG (MainThread) [zigpy_deconz.api] Request id: 0xe2 'aps_data_confirm' for <DeconzAddressEndpoint address_mode=AddressMode.NWK address=0x448b endpoint=1>, status: 0x00
2023-11-27 21:46:00.186 DEBUG (MainThread) [zigpy_deconz.api] Received command device_state_changed[<DeviceState.APSDE_DATA_INDICATION|APSDE_DATA_REQUEST_SLOTS_AVAILABLE|130: 170>, 0]
2023-11-27 21:46:00.186 DEBUG (MainThread) [zigpy_deconz.api] Device state changed response: [<DeviceState.APSDE_DATA_INDICATION|APSDE_DATA_REQUEST_SLOTS_AVAILABLE|130: 170>, 0]
2023-11-27 21:46:00.187 DEBUG (MainThread) [zigpy_deconz.api] Command Command.aps_data_indication (1, <DataIndicationFlags.Always_Use_NWK_Source_Addr: 1>)
2023-11-27 21:46:00.190 DEBUG (MainThread) [zigpy_deconz.api] Received command aps_data_indication[66, <DeviceState.APSDE_DATA_REQUEST_SLOTS_AVAILABLE|2: 34>, <DeconzAddress address_mode=AddressMode.NWK address=0x0000>, 1, <DeconzAddress address_mode=AddressMode.NWK address=0x448b>, 1, 260, 65281, b'\x1c\x9c\x11\xe1\x01\xa0\x00\x00#\x00\x00\x00\x00\xa1\x00\x00#\x00\x00\x00\x00\xb0\x00\x00\x10\x01\x01\x01\x00H\n\x00\x00\x00\x01\x00\x00\x00\x00\x01\x00\x00\x01', 0, 175, 255, 166, 228, 200, 9, -43]
2023-11-27 21:46:00.190 DEBUG (MainThread) [zigpy_deconz.api] APS data indication response: [66, <DeviceState.APSDE_DATA_REQUEST_SLOTS_AVAILABLE|2: 34>, <DeconzAddress address_mode=AddressMode.NWK address=0x0000>, 1, <DeconzAddress address_mode=AddressMode.NWK address=0x448b>, 1, 260, 65281, b'\x1c\x9c\x11\xe1\x01\xa0\x00\x00#\x00\x00\x00\x00\xa1\x00\x00#\x00\x00\x00\x00\xb0\x00\x00\x10\x01\x01\x01\x00H\n\x00\x00\x00\x01\x00\x00\x00\x00\x01\x00\x00\x01', 0, 175, 255, 166, 228, 200, 9, -43]
2023-11-27 21:46:00.191 DEBUG (MainThread) [zigpy.application] Received a packet: ZigbeePacket(timestamp=datetime.datetime(2023, 11, 28, 2, 46, 0, 191169, tzinfo=datetime.timezone.utc), src=AddrModeAddress(addr_mode=<AddrMode.NWK: 2>, address=0x448B), src_ep=1, dst=AddrModeAddress(addr_mode=<AddrMode.NWK: 2>, address=0x0000), dst_ep=1, source_route=None, extended_timeout=False, tsn=None, profile_id=260, cluster_id=65281, data=Serialized[b'\x1c\x9c\x11\xe1\x01\xa0\x00\x00#\x00\x00\x00\x00\xa1\x00\x00#\x00\x00\x00\x00\xb0\x00\x00\x10\x01\x01\x01\x00H\n\x00\x00\x00\x01\x00\x00\x00\x00\x01\x00\x00\x01'], tx_options=<TransmitOptions.NONE: 0>, radius=0, non_member_radius=0, lqi=255, rssi=-43)
2023-11-27 21:46:00.192 DEBUG (MainThread) [zigpy.zcl] [0x448B:1:0xff01] Received ZCL frame: b'\x1c\x9c\x11\xe1\x01\xa0\x00\x00#\x00\x00\x00\x00\xa1\x00\x00#\x00\x00\x00\x00\xb0\x00\x00\x10\x01\x01\x01\x00H\n\x00\x00\x00\x01\x00\x00\x00\x00\x01\x00\x00\x01'
2023-11-27 21:46:00.194 DEBUG (MainThread) [zigpy.zcl] [0x448B:1:0xff01] Decoded ZCL frame header: ZCLHeader(frame_control=FrameControl(frame_type=<FrameType.GLOBAL_COMMAND: 0>, is_manufacturer_specific=True, direction=<Direction.Client_to_Server: 1>, disable_default_response=1, reserved=0, *is_cluster=False, *is_general=True), manufacturer=4508, tsn=225, command_id=1, *direction=<Direction.Client_to_Server: 1>)
2023-11-27 21:46:00.198 DEBUG (MainThread) [zigpy.zcl] [0x448B:1:0xff01] Decoded ZCL frame: SinopeManufacturerCluster:Read_Attributes_rsp(status_records=[ReadAttributeRecord(attrid=0x00A0, status=<Status.SUCCESS: 0>, value=TypeValue(type=uint32_t, value=0)), ReadAttributeRecord(attrid=0x00A1, status=<Status.SUCCESS: 0>, value=TypeValue(type=uint32_t, value=0)), ReadAttributeRecord(attrid=0x00B0, status=<Status.SUCCESS: 0>, value=TypeValue(type=Bool, value=<Bool.true: 1>)), ReadAttributeRecord(attrid=0x0101, status=<Status.SUCCESS: 0>, value=TypeValue(type=Array, value=Array(type=AnonymousLVList, value=[]))), ReadAttributeRecord(attrid=0x0100, status=<Status.SUCCESS: 0>, value=TypeValue(type=NoData, value=<zigpy.types.named.NoData object at 0x7f54526290>)), ReadAttributeRecord(attrid=0x0000, status=<Status.FAILURE: 1>), ReadAttributeRecord(attrid=0x0000, status=<Status.FAILURE: 1>)])
2023-11-27 21:46:00.201 DEBUG (MainThread) [zigpy_deconz.api] 'aps_data_indication' response from <DeconzAddress address_mode=AddressMode.NWK address=0x448b>, ep: 1, profile: 0x0104, cluster_id: 0xff01, data: b'1c9c11e101a000002300000000a100002300000000b000001001010100480a000000010000000001000001'
2023-11-27 21:46:00.202 DEBUG (MainThread) [custom_components.zha_toolkit] event_data {'zha_toolkit_version': 'v1.1.7', 'zigpy_version': '0.59.0', 'zigpy_rf_version': '0.21.1', 'ieee_org': 94:34:69:ff:fe:38:87:aa, 'ieee': '94:34:69:ff:fe:38:87:aa', 'command': 'scan_device', 'command_data': None, 'start_time': '2023-11-28T02:45:01.661145+00:00', 'errors': ['KeyError(256)'], 'params': {'endpoint_id': 1, 'dir': 0, 'tries': 1, 'expect_reply': True, 'args': [], 'event_success': 'my_read_success_trigger_event', 'event_fail': 'my_read_fail_trigger_event', 'event_done': 'my_read_done_trigger_event', 'read_before_write': True, 'read_after_write': True}, 'success': False}
2023-11-27 21:46:00.203 DEBUG (MainThread) [custom_components.zha_toolkit] Fire my_read_fail_trigger_event -> {'zha_toolkit_version': 'v1.1.7', 'zigpy_version': '0.59.0', 'zigpy_rf_version': '0.21.1', 'ieee_org': 94:34:69:ff:fe:38:87:aa, 'ieee': '94:34:69:ff:fe:38:87:aa', 'command': 'scan_device', 'command_data': None, 'start_time': '2023-11-28T02:45:01.661145+00:00', 'errors': ['KeyError(256)'], 'params': {'endpoint_id': 1, 'dir': 0, 'tries': 1, 'expect_reply': True, 'args': [], 'event_success': 'my_read_success_trigger_event', 'event_fail': 'my_read_fail_trigger_event', 'event_done': 'my_read_done_trigger_event', 'read_before_write': True, 'read_after_write': True}, 'success': False}
2023-11-27 21:46:00.203 DEBUG (MainThread) [custom_components.zha_toolkit] Fire my_read_done_trigger_event -> {'zha_toolkit_version': 'v1.1.7', 'zigpy_version': '0.59.0', 'zigpy_rf_version': '0.21.1', 'ieee_org': 94:34:69:ff:fe:38:87:aa, 'ieee': '94:34:69:ff:fe:38:87:aa', 'command': 'scan_device', 'command_data': None, 'start_time': '2023-11-28T02:45:01.661145+00:00', 'errors': ['KeyError(256)'], 'params': {'endpoint_id': 1, 'dir': 0, 'tries': 1, 'expect_reply': True, 'args': [], 'event_success': 'my_read_success_trigger_event', 'event_fail': 'my_read_fail_trigger_event', 'event_done': 'my_read_done_trigger_event', 'read_before_write': True, 'read_after_write': True}, 'success': False}
2023-11-27 21:46:00.204 ERROR (MainThread) [custom_components.zha_toolkit] Exception '256' for service call with data '{'zha_toolkit_version': 'v1.1.7', 'zigpy_version': '0.59.0', 'zigpy_rf_version': '0.21.1', 'ieee_org': 94:34:69:ff:fe:38:87:aa, 'ieee': '94:34:69:ff:fe:38:87:aa', 'command': 'scan_device', 'command_data': None, 'start_time': '2023-11-28T02:45:01.661145+00:00', 'errors': ['KeyError(256)'], 'params': {'endpoint_id': 1, 'dir': 0, 'tries': 1, 'expect_reply': True, 'args': [], 'event_success': 'my_read_success_trigger_event', 'event_fail': 'my_read_fail_trigger_event', 'event_done': 'my_read_done_trigger_event', 'read_before_write': True, 'read_after_write': True}, 'success': False}'
2023-11-27 21:46:00.210 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: 256
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 704, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 666, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/__init__.py", line 825, in toolkit_service
raise handler_exception
File "/config/custom_components/zha_toolkit/__init__.py", line 781, in toolkit_service
handler_result = await handler(
^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/__init__.py", line 891, in command_handler_default
return await default.default(
^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/default.py", line 40, in default
await handler(app, listener, ieee, cmd, data, service, params, event_data)
File "/config/custom_components/zha_toolkit/scan_device.py", line 445, in scan_device
scan = await scan_results(
^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/scan_device.py", line 92, in scan_results
await scan_endpoint(
File "/config/custom_components/zha_toolkit/scan_device.py", line 112, in scan_endpoint
clusters[key] = await scan_cluster(
^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/scan_device.py", line 148, in scan_cluster
await discover_attributes_extended(
File "/config/custom_components/zha_toolkit/scan_device.py", line 266, in discover_attributes_extended
success, failed = await read_attr(
^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/scan_device.py", line 29, in read_attr
return await cluster.read_attributes(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/zigpy/zcl/__init__.py", line 531, in read_attributes
orig_attribute = orig_attributes[record.attrid]
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 256
2023-11-27 21:46:00.260 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [546892513856] Error handling message: Unknown error (unknown_error) Claude Gelinas from 192.168.2.40 (Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36)
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response
await func(hass, connection, msg)
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 731, in handle_execute_script
script_result = await script_obj.async_run(msg.get("variables"), context=context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1578, in async_run
return await asyncio.shield(run.async_run())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 420, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 470, in _async_step
self._handle_exception(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 493, in _handle_exception
raise exception
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 704, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 666, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/__init__.py", line 825, in toolkit_service
raise handler_exception
File "/config/custom_components/zha_toolkit/__init__.py", line 781, in toolkit_service
handler_result = await handler(
^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/__init__.py", line 891, in command_handler_default
return await default.default(
^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/default.py", line 40, in default
await handler(app, listener, ieee, cmd, data, service, params, event_data)
File "/config/custom_components/zha_toolkit/scan_device.py", line 445, in scan_device
scan = await scan_results(
^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/scan_device.py", line 92, in scan_results
await scan_endpoint(
File "/config/custom_components/zha_toolkit/scan_device.py", line 112, in scan_endpoint
clusters[key] = await scan_cluster(
^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/scan_device.py", line 148, in scan_cluster
await discover_attributes_extended(
File "/config/custom_components/zha_toolkit/scan_device.py", line 266, in discover_attributes_extended
success, failed = await read_attr(
^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/scan_device.py", line 29, in read_attr
return await cluster.read_attributes(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/zigpy/zcl/__init__.py", line 531, in read_attributes
orig_attribute = orig_attributes[record.attrid]
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 256
I suggest that you report this at Issues · zigpy/zigpy · GitHub - the information from the trace shouild be enough to create a test case which will help validate the resolution.
Thank’s I’ll do that
Bug submitted and it appear that it is partly because of a malformed array data.
Sice last update of zha toolkit, scan-device is still unable to complete and create the file .txt. But now we can see the value of the array that cause problem
Échec de l'appel du service zha_toolkit.scan_device. Failed to serialize to JSON: /config/scans/TH1123ZB-G2_Sinope-Technologies_fffed9eaf4_01_scan_results.txt. Bad data at $.endpoints[0].in_clusters.0xff01.attributes.0x012c.attribute_value=Array(type=AnonymousLVList, value=[16, 0, 0, 0, 0, 0, 16, 132, 2, 45])(<class 'zigpy.zcl.foundation.Array'>
Since we can see the value of the array and it look good it should be possible to write this value in the txt file and keep going to finish the scan ?
I hope that v1.1.9 (currently a bêta/pre-release) helps with that.
I am using the toolkit to extract temperatures:
- service: zha_toolkit.execute
data:
command: attr_read
ieee: '{{ ieee }}'
cluster: 65281
attribute: 263
state_id: sensor.{{ friendlyname }}_floor_temp
state_value_template: (value/100) | float(0) | round(1)
allow_create: true
tries: 10
all works as expected, but it seems like HA needs a “measurement type” to generate the graphs correctly (see current result below), is it possible to set measurement type directly via ZHA_Toolkit or will I need to create another sensor separately (not ideal) ? otherwise the UI asks for a unique_ID to modify it, any way to set the unique_id ?
thanks!
When zha-toolkit creates an entity, it’s not a real entity as defined in HA.
However, it’s mostly accepted as one.
zha-toolkit
has the zha_toolkit.ha_set_state
service that lets you set a state attribute to a value, so you could set the extra attributes using that (you need ot do that on home assistant restart as well).
Something else you can try is to create a template sensor, define the static attributes you need there, and update the dynamic part using zha-toolkit:
sensor:
- platform: template
sensors:
office_XXXX_demand:
friendly_name: Heating demand
unit_of_measurement: percent
value_template: '{{ YOUR_DEFAULT }}'
- platform: command_line
command: a_dummy_command
scan_interval: 100000000 # Very big to never execute it.
unit_of_measurement: kWh
value_template: '{{ YOUR_DEFAULT }}'
I did not test that, but it should work IMHO.
Another tip: use zha_toolkit.attr_read
- zha_toolkit.execute is there for historical reasons and the UI is not as selective as the more specific service.