home-assistant-libs / python-matter-server

Python server to interact with Matter
Apache License 2.0
519 stars 79 forks source link

Unable to add accessory to Apple Home (multi-admin)? #923

Open olavt opened 1 month ago

olavt commented 1 month ago

I tested this a while back (a year ago maybe) and then I got this to work with Python Matter Server.

Now, I can't get this to work anymore.

I'm able to first add a device to Apple Home and then add it to Python Matter Server, but not the other way around.

This is how I test:

[13.10.2024 12:26:39.560 INF] MatterServerClient.SendCommandAsync: Sending command: { "message_id": "5", "command": "open_commissioning_window", "args": { "node_id": 1 } }

Getting this reply:

[13.10.2024 12:26:40.177 INF] Received response: { "message_id": "5", "result": { "setup_pin_code": 55079003, "setup_manual_code": "32876333616", "setup_qr_code": "MT:00000K0V012VE278610" } }

Using the QR code I try to add it to Apple Home using the app on the iPhone, but this fails with a generic error like Accessory Not Found or "Uanable to Add Accessory".

This is from the Python Matter Server log:

2024-10-13 12:20:36.191 (MainThread) INFO [matter_server.server.stack] Initializing CHIP/Matter Logging... 2024-10-13 12:20:36.192 (MainThread) INFO [matter_server.server.stack] Initializing CHIP/Matter Controller Stack... [1728822036.259599][1:1] CHIP:CTL: Setting attestation nonce to random value [1728822036.259996][1:1] CHIP:CTL: Setting CSR nonce to random value [1728822036.261495][1:1] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /tmp/chip_kvs [1728822036.261958][1:1] CHIP:DL: writing settings to file (/tmp/chip_kvs-trrJYe) [1728822036.262071][1:1] CHIP:DL: renamed tmp file to file (/tmp/chip_kvs) [1728822036.262433][1:1] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /data/chip_factory.ini [1728822036.262548][1:1] CHIP:DL: writing settings to file (/data/chip_factory.ini-bSIvci) [1728822036.262625][1:1] CHIP:DL: renamed tmp file to file (/data/chip_factory.ini) [1728822036.262661][1:1] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /data/chip_config.ini [1728822036.262755][1:1] CHIP:DL: writing settings to file (/data/chip_config.ini-Jd809e) [1728822036.262820][1:1] CHIP:DL: renamed tmp file to file (/data/chip_config.ini) [1728822036.262855][1:1] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /data/chip_counters.ini [1728822036.262918][1:1] CHIP:DL: writing settings to file (/data/chip_counters.ini-vewg2h) [1728822036.262975][1:1] CHIP:DL: renamed tmp file to file (/data/chip_counters.ini) [1728822036.263378][1:1] CHIP:DL: writing settings to file (/data/chip_factory.ini-PtDF8i) [1728822036.263690][1:1] CHIP:DL: renamed tmp file to file (/data/chip_factory.ini) [1728822036.263716][1:1] CHIP:DL: NVS set: chip-factory/unique-id = "FE6624C782895C28" [1728822036.263862][1:1] CHIP:DL: writing settings to file (/data/chip_factory.ini-PUi0Vf) [1728822036.264843][1:1] CHIP:DL: renamed tmp file to file (/data/chip_factory.ini) [1728822036.264878][1:1] CHIP:DL: NVS set: chip-factory/vendor-id = 65521 (0xFFF1) [1728822036.265023][1:1] CHIP:DL: writing settings to file (/data/chip_factory.ini-NJHPfh) [1728822036.265273][1:1] CHIP:DL: renamed tmp file to file (/data/chip_factory.ini) [1728822036.265304][1:1] CHIP:DL: NVS set: chip-factory/product-id = 32769 (0x8001) [1728822036.265427][1:1] CHIP:DL: writing settings to file (/data/chip_counters.ini-oKAnVe) [1728822036.265628][1:1] CHIP:DL: renamed tmp file to file (/data/chip_counters.ini) [1728822036.265649][1:1] CHIP:DL: NVS set: chip-counters/reboot-count = 1 (0x1) [1728822036.265775][1:1] CHIP:DL: writing settings to file (/data/chip_counters.ini-Dvqvbi) [1728822036.266001][1:1] CHIP:DL: renamed tmp file to file (/data/chip_counters.ini) [1728822036.266037][1:1] CHIP:DL: NVS set: chip-counters/total-operational-hours = 0 (0x0) [1728822036.266174][1:1] CHIP:DL: writing settings to file (/data/chip_counters.ini-vJOxlf) [1728822036.266436][1:1] CHIP:DL: renamed tmp file to file (/data/chip_counters.ini) [1728822036.266461][1:1] CHIP:DL: NVS set: chip-counters/boot-reason = 0 (0x0) [1728822036.266590][1:1] CHIP:DL: writing settings to file (/data/chip_config.ini-fppO6e) [1728822036.266791][1:1] CHIP:DL: renamed tmp file to file (/data/chip_config.ini) [1728822036.266812][1:1] CHIP:DL: NVS set: chip-config/regulatory-location = 0 (0x0) [1728822036.266940][1:1] CHIP:DL: writing settings to file (/data/chip_config.ini-Ek4J2f) [1728822036.267174][1:1] CHIP:DL: renamed tmp file to file (/data/chip_config.ini) [1728822036.267199][1:1] CHIP:DL: NVS set: chip-config/location-capability = 2 (0x2) [1728822036.267527][1:1] CHIP:DL: Got Ethernet interface: eth0 [1728822036.267677][1:1] CHIP:DL: Found the primary Ethernet interface:eth0 [1728822036.267827][1:1] CHIP:DL: Got WiFi interface: wlan0 [1728822036.267860][1:1] CHIP:DL: Failed to reset WiFi statistic counts 2024-10-13 12:20:36.268 (MainThread) INFO [chip.storage] Initializing persistent storage from file: /data/chip.json 2024-10-13 12:20:36.268 (MainThread) ERROR [chip.storage] [Errno 2] No such file or directory: '/data/chip.json' 2024-10-13 12:20:36.269 (MainThread) CRITICAL [chip.storage] Could not load configuration from /data/chip.json - resetting configuration... 2024-10-13 12:20:36.269 (MainThread) WARNING [chip.storage] No valid SDK configuration present - clearing out configuration 2024-10-13 12:20:36.269 (MainThread) WARNING [chip.storage] No valid REPL configuration present - clearing out configuration 2024-10-13 12:20:36.474 (MainThread) INFO [chip.CertificateAuthority] Loading certificate authorities from storage... 2024-10-13 12:20:36.474 (MainThread) INFO [chip.CertificateAuthority] New CertificateAuthority at index 1 2024-10-13 12:20:36.484 (MainThread) INFO [chip.FabricAdmin] New FabricAdmin: FabricId: 0x0000000000000001, VendorId = 0xFFF1 2024-10-13 12:20:36.484 (MainThread) INFO [matter_server.server.stack] CHIP Controller Stack initialized. 2024-10-13 12:20:36.485 (MainThread) INFO [matter_server.server.server] Starting the Matter Server... 2024-10-13 12:20:36.493 (MainThread) INFO [matter_server.server.helpers.paa_certificates] Fetching the latest PAA root certificates from DCL. 2024-10-13 12:20:39.592 (MainThread) INFO [matter_server.server.helpers.paa_certificates] Fetched 63 PAA root certificates from DCL. 2024-10-13 12:20:39.593 (MainThread) INFO [matter_server.server.helpers.paa_certificates] Fetching the latest PAA root certificates from Git. 2024-10-13 12:20:40.174 (MainThread) INFO [matter_server.server.helpers.paa_certificates] Fetched 2 PAA root certificates from Git. 2024-10-13 12:20:40.176 (MainThread) INFO [chip.FabricAdmin] Allocating new controller with CaIndex: 1, FabricId: 0x0000000000000001, NodeId: 0x000000000001B669, CatTags: [] 2024-10-13 12:20:40.392 (Dummy-2) CHIP_ERROR [chip.native.DIS] Failed to advertise records: src/inet/UDPEndPointImplSockets.cpp:416: OS Error 0x02000065: Network is unreachable 2024-10-13 12:20:40.395 (Dummy-2) CHIP_ERROR [chip.native.DIS] Failed to advertise records: src/inet/UDPEndPointImplSockets.cpp:416: OS Error 0x02000065: Network is unreachable 2024-10-13 12:20:40.398 (Dummy-2) CHIP_ERROR [chip.native.DL] Long dispatch time: 220 ms, for event type 2 2024-10-13 12:20:40.409 (MainThread) INFO [matter_server.server.vendor_info] Loading vendor info from storage. 2024-10-13 12:20:40.409 (MainThread) INFO [matter_server.server.vendor_info] Loaded 0 vendors from storage. 2024-10-13 12:20:40.410 (MainThread) INFO [matter_server.server.vendor_info] Fetching the latest vendor info from DCL. 2024-10-13 12:20:40.684 (MainThread) INFO [matter_server.server.vendor_info] Fetched 252 vendors from DCL. 2024-10-13 12:20:40.684 (MainThread) INFO [matter_server.server.vendor_info] Saving vendor info to storage. 2024-10-13 12:20:40.693 (MainThread) INFO [matter_server.server.device_controller] Loaded 0 nodes from stored configuration 2024-10-13 12:20:40.707 (MainThread) INFO [matter_server.server.server] Matter Server successfully initialized. 2024-10-13 12:24:28.377 (MainThread) INFO [matter_server.server.device_controller] Starting Matter commissioning with code using Node ID 1. 2024-10-13 12:24:33.454 (Dummy-2) INFO [chip.ChipDeviceCtrl] Established secure session with Device 2024-10-13 12:24:35.628 (Dummy-2) CHIP_ERROR [chip.native.DL] Long dispatch time: 124 ms, for event type 16389 2024-10-13 12:24:42.766 (Dummy-2) INFO [chip.ChipDeviceCtrl] Commissioning complete 2024-10-13 12:24:42.766 (MainThread) INFO [matter_server.server.device_controller] Commissioned Node ID: 1 vs 1 2024-10-13 12:24:42.767 (MainThread) INFO [matter_server.server.device_controller] Matter commissioning of Node ID 1 successful. 2024-10-13 12:24:42.767 (MainThread) INFO [matter_server.server.device_controller] Interviewing node: 1 2024-10-13 12:24:42.768 (Dummy-2) CHIP_ERROR [chip.native.BLE] no endpoint for unsub complete 2024-10-13 12:24:50.175 (MainThread) INFO [matter_server.server.device_controller] Setting-up node... 2024-10-13 12:24:50.179 (MainThread) INFO [matter_server.server.device_controller] Setting up attributes and events subscription. 2024-10-13 12:24:57.498 (MainThread) INFO [matter_server.server.device_controller] Subscription succeeded with report interval [1, 60] 2024-10-13 12:24:57.501 (MainThread) INFO [matter_server.server.device_controller] Commissioning of Node ID 1 completed. 2024-10-13 12:26:40.527 (Dummy-2) INFO [chip.ChipDeviceCtrl] Open Commissioning Window complete setting nodeid 1 pincode to 55079003

Apollon77 commented 1 month ago

Can you share more details like errors you get from the Apple app or such? It seems that he commissioning window on the devcie gets opened successfully ... the rest happens between apple home and the device ...

olavt commented 1 month ago

From the Apple side I just get the very high level errors mentioned.

I will try to add the device added to Python Matter Server from chip-tool to see if I can get more insight.

olavt commented 1 month ago

I have tested a bit more now.

Test 1:

Test 2:

Test 3:

Test 4:

Test 5:

Looks like the issue is on the Apple Home side.

Has anyone tested adding an accessory paired with the Python Matter Server to Apple Home?

jvmahon commented 1 month ago

Has anyone tested adding an accessory paired with the Python Matter Server to Apple Home?

Yes, and that will generally work. But I do think there is an Apple iOS / tvOS issue that may be at the root of the problem you are seeing. I've also found that sometimes I can't do an initial pair to iOS or HA from iOS Home on iPhone even after multiple device factory resets and attempts, BUT, if I first pair to Google Home on iOS, then pair to iOS Home or HA as a second or third fabric, it all works (I then end up deleting from Google Home). So, the "Yes" to your question works if I follow at least this sequence (a) pair to Google, (b) pair from Google Home to HA, then (c) from HA to iOS (that is not the only sequence that works, but its one I find often succeeds if I am finding trouble with iOS pairing). It makes no sense that pairing first to Google Home on iOS seems to make this all work, but it does.

I've found this issue seems to be present with Matter 1.0 devices (Eve Energy, Eve Motion, Aqara P2 sensors), but Matter 1.1 (Inovelli dimmers) and Matter 1.2 (Aqara locks) don't seem to have this issue. I'm assuming that (maybe) Google Home on iOS may rely on its own code (as opposed to a common iOS provided library) to do the pairing and that somehow gets Google Home past whatever obstacle blocks pairing on iOS.

marcelveldt commented 1 month ago

Did you test it using the manual code instead of QR code ? I noticed lately that the QR code is not working on Amazon Alexa for example...

olavt commented 1 month ago

I re-tested today with an ELKO One Thermostat (certified with Matter 1.2) and I managed to add this device to Apple Home using the generated QR-Code (after invoking commissioning on the Matter Python Server).

tannerdsilva commented 4 hours ago

I am able to do this semi-reliably on HA these days. With HA as its own thread border router and matter server, I can share a device by code an Apple Home on device operating via ethernet.

Works great. The hardest part (for me) is still in the initial commissioning on HA via my iPhone, which seems to fail the first time and succeed the second time on nearly every device I try to pair (yes I have to reset the device between the first and second attempt - probably a new issue).