home-assistant / android

:iphone: Home Assistant Companion for Android
https://companion.home-assistant.io/
Apache License 2.0
2.35k stars 657 forks source link

Update home-assistant network Thread credentials not possible #4146

Open agners opened 10 months ago

agners commented 10 months ago

Home Assistant Android app version(s): 2024.1.2-full

Android version(s): 14

Device model(s): Pixel Pro 8

Home Assistant version: 2024.1.3

Last working Home Assistant release (if known):

Description of problem, include YAML if issue is related to notifications: When creating a new home-assistant Thread network in Home Assistant (e.g. via "Reset border router" feature in the Home Assistant Thread integration configuration page) updating the Thread credentials seems not to work.

To reproduce:

  1. "Clear all data" of "Google Play services" method to make sure to start from a clear slate
  2. Have a home-assistant network as preferred set in Core (say home-assistant network 1)
  3. Select "Sync Thread credentials" -> "✅ Added network from Home Assistant to this device"
  4. Select "Sync Thread credentials" -> "✅ Home Assistant and this device use the same network" :+1:
  5. Create a home-assistant Thread network e.g. by using "Reset border router"
  6. Select "Make preferred network" to mark this new home-assistant network as preferred
  7. Select "Sync Thread credentials" -> "✅ Updated network from Home Assistant to this device"
  8. Select "Sync Thread credentials" -> "✅ Updated network from Home Assistant to this device"

Up to 7 everything is as expected. However, when trying to commission a device after step 7, it won't work because the credentials didn't really got updated. Step 8 also proves that. It seems the app is not able to update the dataset.

**Screenshot and log of step 3:** ![image](https://github.com/home-assistant/android/assets/34061/31e4fcad-c02f-4747-8206-dcd79be0a47d) ``` 01-20 14:36:30.259 7110 7110 W WindowOnBackDispatcher: sendCancelIfRunning: isInProgress=falsecallback=com.google.android.material.motion.MaterialBackOrchestrator$Api34BackCallbackDelegate$1@288a0ce 01-20 14:36:30.268 7110 7110 W InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed. 01-20 14:36:30.282 7110 7110 D ServerConnectionInfo: localUrl is: false, usesInternalSsid is: false, usesWifi is: true 01-20 14:36:30.282 7110 7110 D WebSocketRepository: Sending message 49: {type=get_config, id=49} 01-20 14:36:30.282 7110 7110 D WebSocketRepository: Message number 49 sent 01-20 14:36:30.343 7110 13794 D WebSocketRepository: Websocket: onMessage (text) 01-20 14:36:30.344 7110 13794 D WebSocketRepository: Message number 49 received 01-20 14:36:30.365 7110 7110 D WebSocketRepository: Sending message 50: {type=thread/list_datasets, id=50} 01-20 14:36:30.365 7110 7110 D WebSocketRepository: Message number 50 sent 01-20 14:36:30.372 7110 13794 D WebSocketRepository: Websocket: onMessage (text) 01-20 14:36:30.373 7110 13794 D WebSocketRepository: Message number 50 received 01-20 14:36:40.384 7110 7110 D WebSocketRepository: Sending message 51: {type=thread/get_dataset_tlv, dataset_id=01H7SF0EZ6CZR08N4P2G77R6ZG, id=51} 01-20 14:36:40.384 7110 7110 D WebSocketRepository: Message number 51 sent 01-20 14:36:40.396 7110 13794 D WebSocketRepository: Websocket: onMessage (text) 01-20 14:36:40.397 7110 13794 D WebSocketRepository: Message number 51 received 01-20 14:36:40.472 7110 7110 D ThreadManagerImpl: Thread import to device completed 01-20 14:36:49.002 7110 7110 W WindowOnBackDispatcher: sendCancelIfRunning: isInProgress=falsecallback=android.app.Dialog$$ExternalSyntheticLambda2@e6e29be 01-20 14:36:49.018 7110 7110 W InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed. 01-20 14:36:49.031 7110 7110 D IntegrationRepository: isAppLocked(): false. (LockEnabled: false, appActive: true, expireMillis: 0, currentMillis: 1705757809031) 01-20 14:36:49.031 7110 7110 D IntegrationRepository: setAppActive(): true 01-20 14:36:49.891 7110 7277 D LogcatReader: Read logcat for pid 7110 ``` **Screenshot and log of step 8:** ![image](https://github.com/home-assistant/android/assets/34061/eeedb5c4-bd87-4471-a71f-9380070b8043) ``` 01-20 14:39:22.718 7110 7110 W WindowOnBackDispatcher: sendCancelIfRunning: isInProgress=falsecallback=com.google.android.material.motion.MaterialBackOrchestrator$Api34BackCallbackDelegate$1@53b36cf 01-20 14:39:22.730 7110 7110 W InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed. 01-20 14:39:22.732 7110 7110 D ServerConnectionInfo: localUrl is: false, usesInternalSsid is: false, usesWifi is: true 01-20 14:39:22.733 7110 7110 D WebSocketRepository: Sending message 59: {type=get_config, id=59} 01-20 14:39:22.733 7110 7110 D WebSocketRepository: Message number 59 sent 01-20 14:39:22.742 7110 13794 D WebSocketRepository: Websocket: onMessage (text) 01-20 14:39:22.742 7110 13794 D WebSocketRepository: Message number 59 received 01-20 14:39:22.757 7110 7110 D WebSocketRepository: Sending message 60: {type=thread/list_datasets, id=60} 01-20 14:39:22.757 7110 7110 D WebSocketRepository: Message number 60 sent 01-20 14:39:22.768 7110 13794 D WebSocketRepository: Websocket: onMessage (text) 01-20 14:39:22.768 7110 13794 D WebSocketRepository: Message number 60 received 01-20 14:39:32.788 7110 7110 D WebSocketRepository: Sending message 61: {type=thread/get_dataset_tlv, dataset_id=01HMKD0FR3Q9J27680PM3293DQ, id=61} 01-20 14:39:32.789 7110 7110 D WebSocketRepository: Message number 61 sent 01-20 14:39:32.797 7110 13794 D WebSocketRepository: Websocket: onMessage (text) 01-20 14:39:32.797 7110 13794 D WebSocketRepository: Message number 61 received 01-20 14:39:42.843 7110 7110 D ThreadManagerImpl: Thread: device doesn't prefer core preferred dataset 01-20 14:40:02.974 7110 7110 D ThreadManagerImpl: Thread device prefers app added dataset: home-assistant (PAN 19939, EXTPAN /��xɎ) 01-20 14:40:02.974 7110 7110 D ThreadManagerImpl: Thread: device prefers dataset from app 01-20 14:40:02.975 7110 7110 D WebSocketRepository: Sending message 62: {type=thread/get_dataset_tlv, dataset_id=01HMKD0FR3Q9J27680PM3293DQ, id=62} 01-20 14:40:02.975 7110 7110 D WebSocketRepository: Message number 62 sent 01-20 14:40:02.997 7110 13794 D WebSocketRepository: Websocket: onMessage (text) 01-20 14:40:02.998 7110 13794 D WebSocketRepository: Message number 62 received 01-20 14:40:03.064 7110 7110 D ThreadManagerImpl: Thread update device completed: deleted 1 datasets, updated 1 01-20 14:40:10.140 7110 7110 W WindowOnBackDispatcher: sendCancelIfRunning: isInProgress=falsecallback=android.app.Dialog$$ExternalSyntheticLambda2@d20115 01-20 14:40:10.146 7110 11187 D OpenGLRenderer: endAllActiveAnimators on 0xb4000077e690e3a0 (RippleDrawable) with handle 0xb400007846579d40 01-20 14:40:10.170 7110 7110 D IntegrationRepository: isAppLocked(): false. (LockEnabled: false, appActive: true, expireMillis: 1705757942197, currentMillis: 1705758010170) 01-20 14:40:10.170 7110 7110 D IntegrationRepository: setAppActive(): true 01-20 14:40:14.569 7110 7110 D IntegrationRepository: isAppLocked(): false. (LockEnabled: false, appActive: true, expireMillis: 1705757942197, currentMillis: 1705758014569) 01-20 14:40:14.569 7110 7110 D IntegrationRepository: setAppActive(): true 01-20 14:40:14.811 7110 7174 D LogcatReader: Read logcat for pid 7110 ``` **Additional information:**
agners commented 10 months ago

The current work around is to delete all Thread credentials on the device. The Thread credentials are stored as part of the Google Play services. They ca be removed using the "Clear all data" button in the Google Play service storage menu.

:warning: Deleting Google Play services data does reset some other device settings, namely the Google Wallet cards. :warning:

Screenshot_20231213-105945

:information_source: Note that existing Google Thread Border router need to be reset too. They also initially come up with a NEST-PAN-XXXX network, even if you synced another network to your phone. The Google Thread Border router will only be setup when first commissioning a device.

jpelgrom commented 10 months ago

Resetting the border router in Home Assistant will result in a different border agent ID, which is what the app uses/needs to keep track of border routers, so step 7 will result in a delete + add new credential. The "deleted 1 datasets" part of the log statement is incorrect; this number is simply all datasets managed by the app so even updating an existing one will show deleted 1 updated 1 (to be fixed).

Potential library bug: https://issuetracker.google.com/issues/286158210

The example app also doesn't do anything for clearing the credential which is surprising: https://github.com/google-home/sample-apps-for-matter-android/blob/244ccdd78b7e869fe5260adbe0d051e8c9b5ee29/3p-ecosystem/src/main/java/com/google/homesampleapp/screens/thread/ThreadViewModel.kt#L133-L135

I have not yet tried to replicate this because of a Nest Hub on my network which I need to reset + keep offline while doing this to prevent it from becoming the preferred credential. Maybe/hopefully logcat on device will provide a hint what is happening inside GPS, even if it is redacted.

WindFreaker commented 6 months ago

Are there any updates on this issue? No matter what I do I can't get my Android phone to prefer the HA thread border router. It continues to prefer a no longer connected Nest Hub border router. This causes a conflict and blocks adding new devices.

jimb0b commented 6 months ago

Hi - I found this thread as I was also having issues with syncing Thread credentials to Android from the Thread integration page (pressing the Import Credentials button) - no matter what I did (including wiping my google play services data) it would not sync. I even tried deleting the OpenThread and Thread integrations from HA and setting everything up from scratch, with no avail.

Then I found another thread (https://community.home-assistant.io/t/matter-over-thread-commissioning-issue-with-gl-inet-s200/695901/2) which talks about a different method of syncing credentials, specifically via the Android app in "Settings -> Companion App -> Troubleshooting -> Sync thread credentials" route. This method of syncing worked for me! It still requires trashing google play services data unfortunately, so it's more of a workaround - but wanted to post it here in case this is the step others are struggling with.

j-m commented 2 months ago

The workaround also worked for me, however it's worth highlighting a few extra things.

  1. Deleting your google play service data also removes things like Find My Device. Pretend you have a new phone and double check everything is as it was!
  2. Only your credit/debit cards in your Google Wallet will need reverifying via their CVCs (or completely re-added if not saved to your google account), whereas things like shop memberships etc will be kept.
  3. If you managed to connect your device to thread but you're still having trouble connecting the device to matter, try disconnecting from any VPNs. I have tailscale on my HA and had it set on my android as an Always On vpn and to block any non-vpn connections, and for whatever reason this prevented matter from successfully generating new credentials.
  4. Somewhat annoyingly, my fiancée's iPhone had no problems whatsoever changing preferred networks. So, if you're struggling, try the dark side!

My scenario was for Nanoleaf A19s/NL45s & NL65s, but I figure this could apply more broadly. Hope this helps someone!