home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74k stars 31.05k forks source link

Thread Homekit Devices not being added #131229

Open ffedee7 opened 5 days ago

ffedee7 commented 5 days ago

The problem

I have 10 Thread Nanoleaf Essential Bulbs (non-Matter) which were working correctly for more than a year. After I moved I deleted them from Home Assistant, reseted them and tried to add them to Home Assistant.

Every one of them gives me this error: This accessory is already paired to another device. Please reset the accessory and try again..

The thing is, they are not paired to another device. The steps I'm taking to add them are:

I have 2 HomePods and 1 AppleTV, the Thread network seems to be working fine. I even reinstalled Home Assistant from a backup.

What version of Home Assistant Core has the issue?

core-2024.11.2

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

homekit_controller

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2024-11-21 22:48:27.212 WARNING (MainThread) [aiohomekit.controller.coap.pdu] Transaction 0 failed with error 6 (Invalid request
2024-11-21 22:48:27.297 ERROR (MainThread) [homeassistant.components.homekit_controller.config_flow] Pairing attempt failed with an unhandled exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/coap/pairing.py", line 111, in _ensure_connected
    await self.connection_future
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/coap/connection.py", line 404, in connect
    await self.get_accessory_info()
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/coap/connection.py", line 440, in get_accessory_info
    results = await self.enc_ctx.post_all(OpCode.CHAR_READ, iids, data)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/coap/connection.py", line 201, in post_all
    res_pdu = await self.post_bytes(req_pdu)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/coap/connection.py", line 171, in post_bytes
    response = await self.coap_ctx.request(request).response
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiocoap/protocol.py", line 758, in _run_outer
    await cls._run(app_request, response, weak_observation, protocol, log)
  File "/usr/local/lib/python3.12/site-packages/aiocoap/protocol.py", line 833, in _run
    blockresponse = await blockrequest.response
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
aiocoap.error.LibraryShutdown
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/config_flow.py", line 437, in async_step_pair
    return await self._entry_from_accessory(pairing)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/config_flow.py", line 565, in _entry_from_accessory
    name = await pairing.get_primary_name()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/abstract.py", line 264, in get_primary_name
    accessories = await self.list_accessories_and_characteristics()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/coap/pairing.py", line 147, in list_accessories_and_characteristics
    await self._ensure_connected()
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/coap/pairing.py", line 113, in _ensure_connected
    raise AccessoryDisconnectedError("failed to connect")
aiohomekit.exceptions.AccessoryDisconnectedError: failed to connect
2024-11-21 22:48:27.328 WARNING (MainThread) [coap-server] An exception that is not an aiocoap Error was raised from a transport; please report this as a bug in aiocoap: TypeError("'NoneType' object does not support item assignment")
2024-11-21 22:48:27.331 ERROR (MainThread) [aiohomekit.utils] Failure running background task: Task-745
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/utils.py", line 40, in _handle_task_result
    task.result()
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/coap/pairing.py", line 169, in _process_config_changed
    await self.list_accessories_and_characteristics()
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/coap/pairing.py", line 149, in list_accessories_and_characteristics
    accessories = await self.connection.get_accessory_info()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/coap/connection.py", line 413, in get_accessory_info
    _, body = await self.enc_ctx.post(OpCode.UNK_09_READ_GATT, 0x0000, b"")
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/coap/connection.py", line 194, in post
    res_pdu = await self.post_bytes(req_pdu)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/coap/connection.py", line 171, in post_bytes
    response = await self.coap_ctx.request(request).response
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiocoap/protocol.py", line 758, in _run_outer
    await cls._run(app_request, response, weak_observation, protocol, log)
  File "/usr/local/lib/python3.12/site-packages/aiocoap/protocol.py", line 833, in _run
    blockresponse = await blockrequest.response
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiocoap/protocol.py", line 473, in send
    request_interface.request(pipe)
  File "/usr/local/lib/python3.12/site-packages/aiocoap/tokenmanager.py", line 246, in request
    self.outgoing_requests[key] = request
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^
TypeError: 'NoneType' object does not support item assignment

Additional information

No response

ffedee7 commented 5 days ago

Tried resetting the Apple Thread Network (factory reset all thread border routers + delete Apple Home). Same happens.

home-assistant[bot] commented 4 days ago

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)

jesperkholm commented 3 days ago

I have the same issue.

Jc2k commented 3 days ago

If a bulb says it's connected to a different controller there's nothing we can do, it thinks it is, so it might as well be. We can't force it.

When you delete a device from HomeKit apple says it works, but sometimes (as often as not for thread and Bluetooth) it's telling a lie.

For some thread devices, this is basically guaranteed to happen. Their firmware just doesn't support unpairing over thread.

For others, if the network conditions aren't favourable it will silently fail and say it worked.

I can't help fix those cases, they are firmware and iOS bugs, but if you use HomeKit over Bluetooth in HA you should be able to avoid the problem.

In general, (and I mean going forward) favour matter over HomeKit at this point. The HomeKit over thread devices typically have older less robust thread firmware. And the HomeKit over thread protocol is reverse engineered, so our implementation will never be as polished and robust as matter which is even using upstream libraries.

ffedee7 commented 2 days ago

@Jc2k I ended up buying Philips Hue because I was tired of these Thread issues (even the Matter ones are unreliable some times) 😂, Zigbee seems like rock solid to me. Anyway, it happened with 9 Nanoleaf Thread Bulbs, the thing is, with the same firmware it worked a few month back, so it's very odd that now it doesn't work anymore. I guess that it could be that Apple changed something in their implementation. It's a bummer since they were working really good and reliable before moving.