home-assistant / android

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

High accuracy not enabled when BT connects, if already inside expanded zone #3424

Closed karwosts closed 1 year ago

karwosts commented 1 year ago

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

Android version(s): 9

Device model(s): Moto X4

Home Assistant version: 2023.3.3

Last working Home Assistant release (if known):

Description of problem, include YAML if issue is related to notifications:

I set the following settings for high accuracy mode:

I am right now sitting outside zone.test, 150 meters away from the zone (outside zone.test, but inside zone.test_expanded). I thought that if I connect my BT device, it should enable high accuracy mode, but it does not.

Is the connection of a BT device enough to trigger entering high accuracy mode if the zone conditions are met, or can it only be triggered by the crossing of a zone boundary?

This would be helpful to me as I am trying to catch myself leaving my house passing through a zone right outside my home zone. So when I am at home, and I connect BT to my car, I would like this to engage high accuracy mode immediately, since my home is in the expanded zone of the test zone. But it doesn't seem possible currently.

I can add logs if requested, but just want to get confirmation if this behavior is by design or not.

Companion App Logs:

Screenshot or video of problem:

Additional information:

dshokouhi commented 1 year ago

please get us the companion app logs as we print to the logs the decision making process and it will tell us what happened. You will need to make sure to reproduce the issue so the logs can capture it. Based on what you describe yes it should work that way where high accuracy mode only comes on when you are in the zone and connected to the device. However while you may physically be in that zone it does not mean the app received that update in that precise moment. The logs will show that.

karwosts commented 1 year ago

Thanks, I'll gather something and get back to you.

karwosts commented 1 year ago

Ok the app seems to claim that I am not in zone.test_expanded, though I can't figure how it thinks that. It has my accurate location right there in the log, and I am 129m from the center of zone.test, well within the 300m trigger range. I've been at the same spot for hours also.

image

Logs ``` 03-17 11:17:29.416 6025 6025 D LocBroadcastReceiver: Begin evaluating if location update should be skipped 03-17 11:17:29.416 6025 6025 D LocBroadcastReceiver: Received location that is 1375 milliseconds old, 1679077048041 compared to 1679077049416 with source fused 03-17 11:17:29.424 6025 6063 D UrlRepository: localUrl is: true, usesInternalSsid is: true, usesWifi is: true 03-17 11:17:29.444 6025 6063 D LocBroadcastReceiver: Location update sent successfully as exact 03-17 11:17:32.003 6025 6025 D IntegrationRepository: isAppLocked(): false. (LockEnabled: false, appActive: false, expireMillis: 1679076902402, currentMillis: 1679077052003) 03-17 11:17:32.026 6025 6025 D IntegrationRepository: setSessionExpireMillis(): 1679077053026 03-17 11:17:32.027 6025 6025 D IntegrationRepository: setAppActive(): false 03-17 11:17:32.028 6025 6025 D IntegrationRepository: setSessionExpireMillis(): 1679077053027 03-17 11:17:32.028 6025 6025 D IntegrationRepository: setAppActive(): false 03-17 11:17:32.732 6025 6025 D LocBroadcastReceiver: Got single accurate location update: Location[fused *5.625145,-*2.472221 hAcc=10 et=+47m39s370ms alt=62.4859619140625 vel=0.8217987 bear=9.007075 vAcc=12 sAcc=0 bAcc=??? {Bundle[mParcelledData.dataSize=416]}] 03-17 11:17:32.732 6025 6025 D LocBroadcastReceiver: Location accurate enough, all done with high accuracy. 03-17 11:17:32.732 6025 6025 D LocBroadcastReceiver: Last Location: 03-17 11:17:32.732 6025 6025 D LocBroadcastReceiver: Coords:(*5.6251445, -*2.4722214) 03-17 11:17:32.732 6025 6025 D LocBroadcastReceiver: Accuracy: 10.184 03-17 11:17:32.732 6025 6025 D LocBroadcastReceiver: Bearing: 9.007075 03-17 11:17:32.736 6025 6025 D UrlRepository: localUrl is: true, usesInternalSsid is: true, usesWifi is: true 03-17 11:17:32.739 6025 6025 D LocBroadcastReceiver: Begin evaluating if location update should be skipped 03-17 11:17:32.739 6025 6025 D LocBroadcastReceiver: Received location that is 28 milliseconds old, 1679077052711 compared to 1679077052739 with source fused 03-17 11:17:32.739 6025 6025 D LocBroadcastReceiver: New location update not possible within 5 seconds, not sending to HA 03-17 11:17:37.190 6025 6025 D SensorReceiver: Received intent: android.bluetooth.device.action.ACL_CONNECTED 03-17 11:17:37.207 6025 6247 D UrlRepository: localUrl is: true, usesInternalSsid is: true, usesWifi is: true 03-17 11:17:37.227 6025 6247 D UrlRepository: localUrl is: true, usesInternalSsid is: true, usesWifi is: true 03-17 11:17:37.351 6025 6063 D UrlRepository: localUrl is: true, usesInternalSsid is: true, usesWifi is: true 03-17 11:17:37.353 6025 6059 I WM-WorkerWrapper: Worker result SUCCESS for Work [ id=b490cacf-91b9-468a-aa7a-4df5b1e310de, tags={ io.homeassistant.companion.android.websocket.WebsocketManager } ] 03-17 11:17:37.649 6025 6247 D BluetoothManager: getConnectedDevices 03-17 11:17:37.933 6025 6025 D LocBroadcastReceiver: Not requesting accurate location, last accurate location was too recent 03-17 11:17:38.021 6025 16244 D BluetoothManager: getConnectedDevices 03-17 11:17:38.023 6025 16244 D LocBroadcastReceiver: High accuracy mode enabled, because defined ([74:45:CE:F8:50:7E]) bluetooth device(s) connected (Connected devices: [BluetoothDevice(address=B8:69:C2:1B:C3:0A, name=SANGEAN WR-22, paired=true, connected=false), BluetoothDevice(address=74:45:CE:F8:50:7E, name=WF-C500, paired=true, connected=true), BluetoothDevice(address=08:76:95:72:71:A2, name=ELANTRA, paired=true, connected=false), BluetoothDevice(address=2C:41:A1:E5:5B:E1, name=Bose AE2 SoundLink, paired=true, connected=false), BluetoothDevice(address=D4:2E:95:D5:71:83, name=Inspire 2, paired=true, connected=false), BluetoothDevice(address=F0:98:CC:D7:DF:EA, name=Hue ambiance downlight, paired=true, connected=false), BluetoothDevice(address=CC:F7:FE:CE:D6:5A, name=Hue ambiance downlight, paired=true, connected=false)]) 03-17 11:17:38.023 6025 16244 D LocBroadcastReceiver: High accuracy mode disabled, because not in zone [zone.test_expanded] 03-17 11:17:38.092 6025 16244 D UrlRepository: localUrl is: true, usesInternalSsid is: true, usesWifi is: true 03-17 11:17:38.211 6025 6247 D UrlRepository: localUrl is: true, usesInternalSsid is: true, usesWifi is: true 03-17 11:17:44.537 6025 6025 D IntegrationRepository: isAppLocked(): false. (LockEnabled: false, appActive: false, expireMillis: 1679077053027, currentMillis: 1679077064537) 03-17 11:17:44.600 6025 6025 D IntegrationRepository: isAppLocked(): false. (LockEnabled: false, appActive: false, expireMillis: 1679077053027, currentMillis: 1679077064600) 03-17 11:17:50.424 6025 6035 I mpanion.androi: Background concurrent copying GC freed 154405(5MB) AllocSpace objects, 1(24KB) LOS objects, 49% free, 16MB/33MB, paused 242us total 256.303ms 03-17 11:18:00.442 6025 6247 D UrlRepository: localUrl is: true, usesInternalSsid is: true, usesWifi is: true 03-17 11:18:00.457 6025 6100 I WM-Processor: Moving WorkSpec (679d88c0-7e8c-4d15-a598-e1c99b337884) to the foreground 03-17 11:18:00.468 6025 6025 I WM-SystemFgDispatcher: Started foreground service Intent { act=ACTION_START_FOREGROUND cmp=io.homeassistant.companion.android/androidx.work.impl.foreground.SystemForegroundService (has extras) } 03-17 11:18:00.475 6025 6247 D SensorWorker: Updating all Sensors in foreground. 03-17 11:18:00.487 6025 6247 D UrlRepository: localUrl is: true, usesInternalSsid is: true, usesWifi is: true 03-17 11:18:00.491 6025 6247 D UrlRepository: localUrl is: true, usesInternalSsid is: true, usesWifi is: true 03-17 11:18:00.776 6025 6247 D BluetoothManager: getConnectedDevices 03-17 11:18:00.971 6025 6063 D BluetoothManager: getConnectedDevices 03-17 11:18:00.972 6025 6063 D LocBroadcastReceiver: High accuracy mode enabled, because defined ([74:45:CE:F8:50:7E]) bluetooth device(s) connected (Connected devices: [BluetoothDevice(address=B8:69:C2:1B:C3:0A, name=SANGEAN WR-22, paired=true, connected=false), BluetoothDevice(address=74:45:CE:F8:50:7E, name=WF-C500, paired=true, connected=true), BluetoothDevice(address=08:76:95:72:71:A2, name=ELANTRA, paired=true, connected=false), BluetoothDevice(address=2C:41:A1:E5:5B:E1, name=Bose AE2 SoundLink, paired=true, connected=false), BluetoothDevice(address=D4:2E:95:D5:71:83, name=Inspire 2, paired=true, connected=false), BluetoothDevice(address=F0:98:CC:D7:DF:EA, name=Hue ambiance downlight, paired=true, connected=false), BluetoothDevice(address=CC:F7:FE:CE:D6:5A, name=Hue ambiance downlight, paired=true, connected=false)]) 03-17 11:18:00.973 6025 6063 D LocBroadcastReceiver: High accuracy mode disabled, because not in zone [zone.test_expanded] 03-17 11:18:01.004 6025 6035 I mpanion.androi: Background concurrent copying GC freed 520892(18MB) AllocSpace objects, 33(708KB) LOS objects, 49% free, 15MB/31MB, paused 245us total 242.092ms 03-17 11:18:01.039 6025 6063 D UrlRepository: localUrl is: true, usesInternalSsid is: true, usesWifi is: true 03-17 11:18:01.116 6025 6247 D UrlRepository: localUrl is: true, usesInternalSsid is: true, usesWifi is: true ```
dshokouhi commented 1 year ago

So zones work with geofencing from Google and those updates are part of the Location Zone sensor. We strictly rely on Google to tell us when zone events happen and that does not occur from background updates. Its possible that the geofence event may have been skipped but you need to look at the logs when that happens. You can try to adjust accuracy in the Location Zone setting to see if that helps out. Your logs are also really short so you may want to keep the app open for the test so there is more data to go by.

dshokouhi commented 1 year ago

Another thing you can do for troubleshooting is listen to the zone enter/exit events that we fire to see if you are actually getting those events. This may be easier than trying to rely on the logs. This will also show data for the expanded zones that the app creates.

https://companion.home-assistant.io/docs/integrations/app-events

karwosts commented 1 year ago

Thanks for the tips. I'll close this for now, since based on debug it clearly seems not to be an issue with BT connection which I thought. Thank you for your assistance!

dshokouhi commented 1 year ago

if it was me I would setup automations to listen to those 2 zone events and have it send you a notification or something so you can do a few drive by tests to see how well it works with that detection. The events should have all the data including if its an expanded zone as well as location data such as accuracy etc...