core icon indicating copy to clipboard operation
core copied to clipboard

Can't Provision Thread Credentials - Unknown TLV type 74 for <class 'aiohomekit.meshcop.Meshcop'>

Open laurentfignon opened this issue 1 year ago • 1 comments

The problem

I'm adding Smartwings Cellular Shades (HomeKit Thread enabled) to Home Assistant. Adding HomeKit device works correctly via ESP BLE, but when I attempt to provision thread credentials, I always get the error: "Failed to perform the action button/press. Unknown TLV type 74 for <class 'aiohomekit.meshcop.Meshcop'>"

My thread network includes an AppleTV, HomePod mini, and OTBR with SkyConnect. The Preferred Network seems to be working correctly, and the HomeKit iOS app seems to correctly pass credentials to HA and the phone. However, logs do show the following warning and error:

FIRST -- when I send credentials to HA I get this WARNING:

Logger: homeassistant.components.thread.dataset_store Source: components/thread/dataset_store.py:263 integration: Thread (documentation, issues) First occurred: 12:46:14 PM (12 occurrences) Last logged: 1:06:02 PM

Got dataset with same extended PAN ID and same or older active timestamp, old dataset: '0e08000066b7ddca000000030000194a0300001435060004001fffc002088f09c7a782bc40b40708fdca2d9b7143294e0510cde974831a4174b49be214ecff39b40b030f4d79486f6d65383233353639343136010289b00410daceb4ad74e566628d678effa29f01d50c0402a0f7f8', new dataset: '0e08000066b7ddca0000000300001935060004001fffc002088f09c7a782bc40b40708fdca2d9b7143294e0510cde974831a4174b49be214ecff39b40b030f4d79486f6d65383233353639343136010289b00410daceb4ad74e566628d678effa29f01d50c0402a0f7f8'

SECOND -- when I attempt to provision the thread credentials to the device, I get this:

Logger: homeassistant.components.websocket_api.http.connection Source: components/websocket_api/commands.py:245 integration: Home Assistant WebSocket API (documentation, issues) First occurred: 12:47:59 PM (8 occurrences) Last logged: 1:06:43 PM

[139732691690272] Unexpected exception [139732573169856] Unexpected exception [139732650753136] Unexpected exception Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service response = await hass.services.async_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 996, in entity_service_call single_response = await _handle_entity_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1068, in _handle_entity_call result = await task ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/button/init.py", line 132, in _async_press_action await self.async_press() File "/usr/src/homeassistant/homeassistant/components/homekit_controller/button.py", line 190, in async_press await self._accessory.async_thread_provision() File "/usr/src/homeassistant/homeassistant/components/homekit_controller/connection.py", line 1032, in async_thread_provision await self.pairing.thread_provision(dataset) File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ble/pairing.py", line 197, in _async_operation_lock_wrap return await func(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/bleak_retry_connector/init.py", line 505, in _async_wrap_bluetooth_connection_error_retry return await func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ble/pairing.py", line 236, in _async_force_fresh_connection return await func(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ble/pairing.py", line 213, in _async_restore_and_resume return await func(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ble/pairing.py", line 1557, in thread_provision decoded = Meshcop.decode(bytes.fromhex(dataset)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohomekit/tlv8.py", line 299, in decode raise TlvParseException(f"Unknown TLV type {type} for {cls}") aiohomekit.tlv8.TlvParseException: Unknown TLV type 74 for <class 'aiohomekit.meshcop.Meshcop'>

Can anyone help?

What version of Home Assistant Core has the issue?

core-2024.10.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Thread

Link to integration documentation on our website

No response

Diagnostics information

home-assistant_thread_2024-10-04T20-19-22.816Z.log

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

laurentfignon avatar Oct 04 '24 20:10 laurentfignon

I get the same error when I try to provision an Eve Homekit device to Thread.

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/commands.py:245
integration: Home Assistant WebSocket API ([documentation](https://www.home-assistant.io/integrations/websocket_api), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+websocket_api%22))
First occurred: 22:06:23 (3 occurrences)
Last logged: 22:07:01
[547348893408] Unexpected exception

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 996, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1068, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/button/__init__.py", line 132, in _async_press_action
    await self.async_press()
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/button.py", line 190, in async_press
    await self._accessory.async_thread_provision()
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/connection.py", line 1032, in async_thread_provision
    await self.pairing.thread_provision(dataset)
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ble/pairing.py", line 197, in _async_operation_lock_wrap
    return await func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/bleak_retry_connector/__init__.py", line 505, in _async_wrap_bluetooth_connection_error_retry
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ble/pairing.py", line 236, in _async_force_fresh_connection
    return await func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ble/pairing.py", line 213, in _async_restore_and_resume
    return await func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ble/pairing.py", line 1557, in thread_provision
    decoded = Meshcop.decode(bytes.fromhex(dataset))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/tlv8.py", line 299, in decode
    raise TlvParseException(f"Unknown TLV type {type} for {cls}")
aiohomekit.tlv8.TlvParseException: Unknown TLV type 74 for <class 'aiohomekit.meshcop.Meshcop'>

What version of Home Assistant Core has the issue?

Core 2024.10.0

What type of installation are you running?

Docker

Integration causing the issue

Thread

Android 2024.9.4

chaudis avatar Oct 09 '24 20:10 chaudis

Same in 2å24.10.2

chaudis avatar Oct 11 '24 17:10 chaudis

I get the same with Nanoleaf A19 bulbs (Homekit version) on 2024.10.2

lkm avatar Oct 16 '24 08:10 lkm

Still on 2024.11.0

chaudis avatar Nov 06 '24 20:11 chaudis

I found part of the issue and a potential workaround. I did this last night, so I am not entirely sure if it will work long-term. This gist has a script and instructions. These instructions to create the TLV should also work.

When importing credentials from apple, it includes type 74 (OT_MESHCOP_TLV_WAKEUP_CHANNEL), which homeassistant cannot handle properly. It looks like one of the libraries supports the wakeup channel, but aiohomekit does not. The fix might be as simple as adding a field there, but I also don't know enough about thread to claim that it will work in the long-term.

This issue is related: https://github.com/home-assistant/core/issues/108950. I believe that the Eero app, when printing the TLV, omitted the missing TLV type (similar to how my script works).

nbeirne avatar Nov 08 '24 22:11 nbeirne

@nbeirne were you able to provision thread credentials? What hardware are you using?

Osvit avatar Nov 11 '24 21:11 Osvit

I was able to provision them using the modified TLV. Hardware is all apple (2 homepods and an apple tv). I did end up adding a skyconnect/openthread server afterwards

nbeirne avatar Nov 11 '24 21:11 nbeirne

Hi - thanks for solving (I'm the person who posted this originally) This seems awesome but I'm terrible with the command line, etc... Can we get this fixed in the next Home Assistant update?

or: here are my dumb questions -- -I assume I'm supposed to put the fix_tlv.py file in the configs/.storage folder, right? -Then I can run the tlv_fix.py script from advanced ssh by using this exact command (no quotes) "python ./fix_tlv.py [tlv]" or should I replace "tlv" with my tlv as found via the instructions? Thanks so much!

laurentfignon avatar Nov 17 '24 03:11 laurentfignon

I tried the steps but must have failed somewhere, my thread network didn't work so I switched back to the other preferred (which had more data in the UI) but now I just get "Failed to perform the action button/press. Could not migrate device to Thread" instead. Im using OTBR as my border router with a skyconnect.

chaudis avatar Nov 20 '24 20:11 chaudis

@laurentfignon

  1. fix_tlv.py is simply a helper script. It gives you the information you need to fix the creds, and no more. You can put it on your local computer or run it on the HASS part. I'd recommend not putting it in the config directory.
  2. Replace the TLV with the one you found in the instructions

@chaudis hmm. I don't know what's going on there. Id suggest restoring from the backup then.

As as side note, I had to recently re-provision my devices and it seemed to work without these steps. I'm not sure what changed, but it seems to be inconsistent.

nbeirne avatar Nov 29 '24 15:11 nbeirne

Hey there @jc2k, @bdraco, mind taking a look at this issue as it has been labeled with an integration (homekit_controller) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of homekit_controller can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign homekit_controller Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


homekit_controller documentation homekit_controller source (message by IssueLinks)

home-assistant[bot] avatar Nov 29 '24 16:11 home-assistant[bot]

(Ticket didn't have enough information to automatically link to the right integration, so no one was notified).

This impacts TLV's imported via the iOS app, not ones created via OTBR. Unsure about Android, but probably not. It should be fixed in the dev branch of aiohomekit. I'll try and get a release out in time for 2024.12.0.

Jc2k avatar Nov 29 '24 16:11 Jc2k

Thank you. I just moved my eve water guard to thread!

chaudis avatar Dec 04 '24 20:12 chaudis