Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pixel 8a only really updates location when app is active and phone screen is on #4679

Open
ChristopheKoeck opened this issue Oct 1, 2024 · 47 comments
Labels
bug Something isn't working location-tracking

Comments

@ChristopheKoeck
Copy link

Home Assistant Android app version(s):
2024.7.3-full
Android version(s):
14 system updated to September 5,2024
Device model(s):
Pixel 8a
Home Assistant version:
2024.9.3
Last working Home Assistant release (if known):
not sure
Description of problem, include YAML if issue is related to notifications:
When the app is in the background, or the screen of the phone is turned off location updates happen very random or not, when the app is active and the screen is on i get updates every minute as expected

Companion App Logs:

There are no logs when the app is running in the background.
I was asked to include screen shots from the Location history in the Android app

Screenshot or video of problem:
Left the house at 2:55pm, arrived at work at 3pm, app didn't update until 3:08pm when i opened the app
Driving - App background - Screen off

Here i left the app open and the screen on, i get an update every minute, left work at 1:25pm, got home at 1:29 and received all expected updates
Driving - App open - Screen on

Here i left the app open and screen on while stationary at work. I again get an update every minute as expected.
Stationary - App open - Screen on

Here the app is running in the background and screen off. I turned the screen off at 4:22pm and turned the screen back on at 4:52pm
Stationary - Screen off

Additional information:

Confirming settings i checked on my Pixel 8a.

  • Home assistant app says it's allowed to run in the background.
  • App has access to location services at all times
  • App battery use is set to Allow background usage and is set to unrestricted
@ChristopheKoeck ChristopheKoeck added the bug Something isn't working label Oct 1, 2024
@dshokouhi
Copy link
Member

@dshokouhi
Copy link
Member

dshokouhi commented Oct 1, 2024

I wonder if #4662 helps this situation more. Will need to wait for the 2024.9.5 beta to be approved by Google to get some valid feedback there. If youd like to provide feedback feel free to join the beta in the play store and wait for the specific version mentioned above to be installed.

edit: beta version is now live in the play store

@yashc18
Copy link

yashc18 commented Oct 2, 2024

can I work on this issue?

@dshokouhi
Copy link
Member

dshokouhi commented Oct 2, 2024

can I work on this issue?

Did you see my comment above? May already have a fix in place. Do you have any other ideas for fixes? Feel free to submit.

Edit: Batching did not correct the issue if you have any ideas please submit a PR so we can review :)

@ChristopheKoeck
Copy link
Author

FYI: Somebody on another forum pointed out they had the same problem, but when they turned on High Accuracy Mode it worked for them. So i tried that and when I turned that on for me i stared getting location updates even when the phone screen was off.
To avoid too much battery drain i set the update interval to 60sec. So far that's been working.

@dshokouhi
Copy link
Member

high accuracy mode actually contains a foreground service which would indeed allow the app to stay active while its going. It also uses GPS directly whereas without high accuracy its using the fused location provider that uses GPS cell and wifi etc...

@ChristopheKoeck can you try the fix in teh beta to see if its working for you?

@ChristopheKoeck
Copy link
Author

@dshokouhi I just installed the app.
I'm at work now, but i'll report back after my lunch break. That gives me two trips to see if it works or not.

@ChristopheKoeck
Copy link
Author

Sadly enough, it still doesn't work :(
I've included another pic from my Location History

I left work at 1:25pm and got home at 1:29pm, it only updated at 1:35pm because i opened the app.
I used my phone a little bit from 1:35 until 2:55 when i left back for work. Got to work at 3pm and on purpose didn't touch my phone until 3:31 when i opened the phone and made the companion app the active app

Latest results

@dshokouhi
Copy link
Member

interesting that the single accurate location shows up on its own almost an hour later at the end, did you by chance send the request_location_update command during that time?

Also can you confirm the settings under the single accurate location sensor to see if the option include in sensor updates is not checked?

settings > companion app > manage sensors > single accurate location > include in sensor update is off

there is also nothing like data saver enabled on the device too?

@ChristopheKoeck
Copy link
Author

yes, i have a motion sensor under my house that triggers a request_location_update, that was one of my attempts to get a quicker location update, but it doesn't work well.

i checked and include in sensor update is off.
data saver is not enabled and i also made sure that the companion app still has full data access even if data saver would turn on

@dshokouhi
Copy link
Member

thanks for checking, I am definitely not seeing those big gaps in my end. Can you try another test for me and see if you enable the Last Notification sensor and grant its special permission not see if the frequency in updates changes? That permission forces the app to remain awake and may help.

a couple random screenshots from my history where the longest gap was a lil over 10 minutes
image
image
image

@ChristopheKoeck
Copy link
Author

i changed the setting you mentioned, i'll see what that does and report back.
On the bottom pic you posted there are also some bigger gaps
2:36:00 to 2:43:32
2:43:32 to 2:56:12

@dshokouhi
Copy link
Member

were not concerned with those smaller gaps actually they are to be expected at times. Its teh 30 minutes or longer gaps as we should not see those. We actually had an issue in the past where location updates would stop entirely until we registered for them again (not the same as this one where updates come when the screen turns on, in the previous case they were at a standstill even when the app was open). That check happens about every 15 minutes or so. Should do the evaluation anytime app sensors update.

@ChristopheKoeck
Copy link
Author

to be clear, if i turn the screen on, but not make the companion app the active app, it still takes a while or i might have to open the app to get the update

@dshokouhi
Copy link
Member

to be clear, if i turn the screen on, but not make the companion app the active app, it still takes a while or i might have to open the app to get the update

Are you seeing other sensor updates during these time gaps?

@ChristopheKoeck
Copy link
Author

you mean any other sensor that's activated in the companion app?
not sure how to check for that.
Could you give an example?

@dshokouhi
Copy link
Member

Do you see the battery level sensor update in the server during the time gap?

@ChristopheKoeck
Copy link
Author

I'll check that and let you know

@ChristopheKoeck
Copy link
Author

ChristopheKoeck commented Oct 3, 2024

Since i enabled the Last Notification sensor i get updates roughly every 5 minutes
I also checked if i would get updates on the battery sensor while the phone screen was off.
I got an update every 15min while the phone was charging, which i guess is normal for that type of sensor.
Here is another Location History log after enabling that sensor
After Enabling sensor

Because of the short distances that i travel, living on a tiny island, i will probably still have to enable High accuracy mode to get the result i want. Can you turn that mode on/off via an automation? I wouldn't need it on while at home, or connected to work wifi, otherwise i would like to turn it on

@dshokouhi
Copy link
Member

Can you turn that mode on/off via an automation?

yes there are several on device automations based around zone and connected bluetooth device, and you can also control it via the server

https://companion.home-assistant.io/docs/core/location#high-accuracy-mode

https://companion.home-assistant.io/docs/notifications/notification-commands#high-accuracy-mode

another thing you can try doing is to increase/decrease your zone sizes to see if that helps your situation

My question regarding the battery level sensor was about before you enabled the other sensors, like when you were experiencing an hour or longer gaps in your tracking history. That was when I was curious to see if it was updating because it woudl tell us if the app were truly asleep or if Google was simply not sending us updates. If the app was truly inactive then you wouldnt see those sensors update either.

@ChristopheKoeck
Copy link
Author

ok, my mistake, i'll turn of the Last Notification sensor again later today when i charge my phone and see what happens

@ChristopheKoeck
Copy link
Author

It looks like other sensors do update with the last notification sensor turned off.
When i got to work and checked on my laptop the wifi status of my phone was already updated, but it took me turning on the screen to get the location update.

@ChristopheKoeck
Copy link
Author

i'm playing around with turning on/off high accuracy mode via automations, but the phone doesn't seem to get those commands until i turned on the screen

@dshokouhi
Copy link
Member

i'm playing around with turning on/off high accuracy mode via automations, but the phone doesn't seem to get those commands until i turned on the screen

make sure to add the critical format to speed up delivery of those commands

https://companion.home-assistant.io/docs/notifications/critical-notifications#android

@ChristopheKoeck
Copy link
Author

I've added the critical format, but it's still very hit or miss if my phone receives the message.
I can look at the traces for the automation and it triggered and send the correct command, but it doesn't seem like the phone receives them.

Would it be possible at some point to have an on device automation that turns on High accuracy mode when not connected to wifi?
That's what i'm trying to do with an automation on the server but it's really not working great.

I also noticed when High accuracy mode is turned on, my Pixel 8a has a message on the bottom of my notifications screen that says the Home assistant App is running in the background, when you turn High Accuracy mode off, the message disappears.

@dshokouhi
Copy link
Member

I've added the critical format, but it's still very hit or miss if my phone receives the message.
I can look at the traces for the automation and it triggered and send the correct command, but it doesn't seem like the phone receives them.

need to see the YAML format to confirm

Would it be possible at some point to have an on device automation that turns on High accuracy mode when not connected to wifi?
That's what i'm trying to do with an automation on the server but it's really not working great.

no this is why we have teh command so users can take their own logic in their own hands, if the app supports all these different methods it will never end.

I also noticed when High accuracy mode is turned on, my Pixel 8a has a message on the bottom of my notifications screen that says the Home assistant App is running in the background, when you turn High Accuracy mode off, the message disappears.

whats the issue here? sounds like its behaving as expected high accuracy mode uses a foreground service so the app can run in the background without interruption.

@ChristopheKoeck
Copy link
Author

This is the action i'm running.
When the screen is on the message gets received pretty much instantly, when the screen is off, it's very hit or miss, but then as soon as i turn the screen on it receives usually receives the message straight away or completely not. It's very confusing
High Accuracy mode automation

@dshokouhi
Copy link
Member

if those commands are not waking the device as they should be then it seems like your device is more aggressive in preventing background apps from running. I am not sure what we can do at this point but I think the focus should be on why the app is not able to run in the background freely

@ChristopheKoeck
Copy link
Author

it's been better since i turned off the adaptive battery setting that was mentioned on the Home Assistant forums..
But i can't say it's running completely perfect.
I guess for my needs i will always need to work with High Accuracy Mode, my travel to and from work is so short that the standard 4-5min update interval is too long for me.
I've used a bunch of triggers to turn on/off High Accuracy mode and set the standard time to 60sec. So far that seems to be working pretty well.

@dshokouhi
Copy link
Member

may or may not have found a potential culprit

https://issuetracker.google.com/issues/370069681

would you say this issue started after the sept pixel update?

@ChristopheKoeck
Copy link
Author

For me it was happening before September, but the description of the problem looks pretty much the same

@dshokouhi
Copy link
Member

yea play services can also be at fault here which is what we depend on for it to work

@didrocks
Copy link

I do confirm (as a Pixel 6a owner) that indeed, position tracking got worse starting september. I think you found a good potential cause! Zones entrance/exit are not detected when the app is in the background.

This was never really precise (I never got background updates event when walking between 1 and 3 minutes interval as described in the documentation even with clear sky, phone in my hand but screen off, so good potential accuracy and didn’t see rejections of location update after opening the app diagnosis). But for a month or so, this really degraded up to 30-40 minutes between location updates, while moving location and entering/exiting 2 zones.

Of course, I double checked many times the instuctions for troubleshooting location and everything (from data sending to background location, battery savings settings…), so it really sounds like an Android update impacted it. The other sensors are synced even in background though.

Thanks for hanging here and being so responsive @dshokouhi! I know all those location issues due to so many different settings and causes are very complex to debug and should be quite repetitive.

@dshokouhi
Copy link
Member

are you guys on the app beta and also updated to android 15 with latest play system updates? the app beta has some location updates and also the OS update could very well impact behavior.

im not seeing very long gaps in time still when i periodically check things.

@didrocks
Copy link

I don’t use any beta version, here are the info on my setup:

  • Home assistant app (2024.9.4-full).
  • Android 14 (Last android update was the 5th of September).
  • Google play service version: 24.41.34. (Apparently latest on the store).

@Logicsystem360
Copy link

Hello guys,

I have the same issue but on my Motorola G24 Power with Android 14 (last update from august), Google play version from 1er september 2024.
App is 2024.10.3-full

You can see here :

image

The only thing did work (but not really) was the persistent notification. But I can't bring back this, I have allowed all the notifications ! Restarted my phone, the app, etc.

Since I have Android 14, the location tracking isn't working very well and all my automation based on the location don't work as they should.

Do anyone have a solution for this ? It's starting to be annoying since I have the issue since severals months now

@dshokouhi
Copy link
Member

@Logicsystem360 have you ensured you have all battery optimizations turned off? I think Motorla may have added some extras

https://dontkillmyapp.com/motorola

the above site may point you i the correct direction to determine if you have the app allowed to run freely in the background.

@Logicsystem360
Copy link

Thanks for your answer. The Home assistant app is already "without restriction" in the parameters. I can't find another parameter which can restrict Home asssitant for saving energy

@ChristopheKoeck
Copy link
Author

I've updated to Android 15 and i'm using HA 2024.10.4 and HA Android app 2024.10.4.full
In general i'm not seeing any issues anymore but then today i had a random gap of 50min.
All my other updates are withing 2-5min

Sadly enough for me that's still not quick enough since i can get from work to home in under 5min, so i'm still using high accuracy mode while not connected to wifi to make sure my updates happen every minute while driving.

I was thinking of putting a location tag on my quad so when my phone is close to it and connects via bluetooth it would turn on high accuracy mode. Would something like that work?

@Tux92
Copy link

Tux92 commented Nov 6, 2024

I update to Android 15 too, but unfortunately no change. I have 10 minutes travel from work to home and the position update only when I arrive and unlook screen

@JoFranke
Copy link

JoFranke commented Nov 7, 2024

Same here, I even bought a Pixel 9 Pro, thinking it would fix the issue with a new phone, so Pixel 7 and Pixel 9 both the same issue (Android 14 and 15 same issue) .

I sometimes dont see location updates sent in the log for a long time (maybe 15 minutes), even though the phone is turned on and the app is in forground. Wired.

Too bad I am also not ablte to turn on the 'last notification sensor' as the companion app keeps asking me to grant permissions, even though I did add HA to the list and granted all permissions for notifications and allowed a few apps in the list.

Hopefully there will be a solution soon. Thanks.

@dshokouhi
Copy link
Member

Sadly enough for me that's still not quick enough since i can get from work to home in under 5min, so i'm still using high accuracy mode while not connected to wifi to make sure my updates happen every minute while driving.

I was thinking of putting a location tag on my quad so when my phone is close to it and connects via bluetooth it would turn on high accuracy mode. Would something like that work?

for your use case i think high accuracy mode may be needed, its a very short amount of time

I have 10 minutes travel from work to home and the position update only when I arrive and unlook screen

you have also confirmed any and all battery saving settings from your manufacturer? For this short time interval high accuracy mode may also be helpful

I sometimes dont see location updates sent in the log for a long time (maybe 15 minutes), even though the phone is turned on and the app is in forground. Wired.

that just means google is not sending the app an update, after about 15 minutes the app will re-register for updates which kicks that off again

Too bad I am also not ablte to turn on the 'last notification sensor' as the companion app keeps asking me to grant permissions, even though I did add HA to the list and granted all permissions for notifications and allowed a few apps in the list.

all you need to do is grant the HA app the permission in the list, as you say you were able to add some apps to the list that means you were able to turn it on. Unless you mean other apps to the notification permission? what device is that? custom ROM? maybe its not translating the permission properly if the app cannot tell its granted. Either way thats a separate issue from here.

............on the subject of zone changes and geofencing i noticed google has some tips here: https://developer.android.com/develop/sensors-and-location/location/geofencing#Troubleshooting

Having Wi-Fi on can significantly improve the location accuracy, so if Wi-Fi is turned off, your application might never get geofence alerts depending on several settings including the radius of the geofence, the device model, or the Android version. Starting from Android 4.3 (API level 18), we added the capability of “Wi-Fi scan only mode” which allows users to disable Wi-Fi but still get good network location. It’s good practice to prompt the user and provide a shortcut for the user to enable Wi-Fi or Wi-Fi scan only mode if both of them are disabled.

I personally am in the habit of turning off wifi scanning so i turned it on to try it out. We dont prompt for wifi currently but a good consideration if that is indeed the issue

for those with a short drive this is a good consideration for high accuracy mode given the below time intervals given (note: first time I've seen actual time estimates, usually their docs are ambiguous with terms like few or several etc...)

Usually the latency is less than 2 minutes, even less when the device has been moving. If Background Location Limits are in effect, the latency is about 2-3 minutes on average. If the device has been stationary for a significant period of time, the latency may increase (up to 6 minutes).

additionally on the same page it has recommended zone radius:

For best results, the minimum radius of the geofence should be set between 100 - 150 meters. 100 is the default for the home zone maybe a slightly larger size is helpful?

@Tux92
Copy link

Tux92 commented Nov 17, 2024

Hi guys, I think I found a solution. Now every 5 minutes I got position update.

Go to Settings > Position > Localisation services > enable Find WiFi Networks and Find Bluetooth Devices

This is a translation because I have Android in Italian language, but I upload all the screen so you can find right menu and options:

IMG_20241117_095607_622~2

IMG_20241117_095607_625~2

IMG_20241117_095607_346~2

@dshokouhi
Copy link
Member

Hi guys, I think I found a solution. Now every 5 minutes I got position update.

Go to Settings > Position > Localisation services > enable Find WiFi Networks and Find Bluetooth Devices

thats exactly what i found and suggested above :)

@Tux92
Copy link

Tux92 commented Nov 17, 2024

Hi guys, I think I found a solution. Now every 5 minutes I got position update.
Go to Settings > Position > Localisation services > enable Find WiFi Networks and Find Bluetooth Devices

thats exactly what i found and suggested above :)

Yes, but I found this setting with search function because I came from OnePlus with a android 10 and there these two setting are under WiFi and Bluetooth area. :)

@didrocks
Copy link

That’s the settings I already have enabled on my Pixel 6a phone since I started to use HA on it, but this didn’t help with the location issue previously described here.

@JoFranke
Copy link

Too bad I am also not ablte to turn on the 'last notification sensor' as the companion app keeps asking me to grant permissions, even though I did add HA to the list and granted all permissions for notifications and allowed a few apps in the list.

all you need to do is grant the HA app the permission in the list, as you say you were able to add some apps to the list that means you were able to turn it on. Unless you mean other apps to the notification permission? what device is that? custom ROM? maybe its not translating the permission properly if the app cannot tell its granted. Either way thats a separate issue from here.

Its a Pixel 9 Pro with stock android. Yes I think it is a seperate issue, too many issues around.

So I switched to an iPhone 16 now, since I need location updates to run stable, and found the iPhone is doing much better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working location-tracking
Projects
None yet
Development

No branches or pull requests

7 participants