Location update happens too frequently

Well, usually people complain about too rare location updates. But I’ve faced quite the opposite issue.
One of my phones (Xiaomi Redmi Note 9 Pro, Android 10) started behaving weirdly today.
Usually when you use GPS, location updates are coming every 30 seconds. This is expected as this is the minimum interval set in the location request code (locationRequest.fastestInterval = 30000 // Every 30 seconds).
But today Home Assistant app started receiving location updates every second during GPS usage. This causes significant battery drain and spams my Home Assistant server.
I don’t know why this happened. Everything was working fine for a long time. Everything worked fine yesterday. There were no updates or settings changes. And suddenly today it was broken.
Rebooting the phone didn’t help. Deleting and reinstalling Home Assistant app didn’t help too.
Any ideas on why this could happen and how to fix it?

it technically shouldnt be possible since we dont send an update if its within 5 seconds and not a geofence update

With that said on my end it appears that google is sending updates slightly faster at 20-25 seconds but not every second.

high accuracy mode did not kick in did it? the logs should hopefully give an indication to the issue.

outside of an app issue it could also be caused by a google play services update? we had one library bump for location but that was back in december.

What if the phone was “on the fence”, i.e. switching back and forth between a geofenced location?

Well the logs would definitely indicate if that was happening as we print when we get a geofence update or normal location update. This is why we print everything so we can take a look at the data and see how to work around it.

1 Like

@dshokouhi Actually I use an old version of Home Assistant app without 5 seconds delay that you mentioned. I could install a latest version but I doubt that there will be any difference because the code that registers for location updates is basically the same and 5 seconds delay for sending updates to HA wouldn’t help too much.
The issue is that for some reason the system is sending locations updates to the app every second instead of every 30 seconds. Only one phone is affected and even that phone worked fine until yesterday. And I can’t figure out why this is happening and how to bring back the old behaviour.
These updates are normal location updates (not geofence).
The log looks like this:

01-12 21:37:33.170 D/LocBroadcastReceiver(22528): Received location update.
01-12 21:37:33.171 D/LocBroadcastReceiver(22528): Last Location: 
01-12 21:37:33.171 D/LocBroadcastReceiver(22528): Coords:(55.6377752, 37.3556597)
01-12 21:37:33.171 D/LocBroadcastReceiver(22528): Accuracy: 36.977
01-12 21:37:33.171 D/LocBroadcastReceiver(22528): Bearing: 345.0
01-12 21:37:34.167 D/LocBroadcastReceiver(22528): Received location update.
01-12 21:37:34.168 D/LocBroadcastReceiver(22528): Last Location: 
01-12 21:37:34.168 D/LocBroadcastReceiver(22528): Coords:(55.6377849, 37.3556667)
01-12 21:37:34.168 D/LocBroadcastReceiver(22528): Accuracy: 36.784
01-12 21:37:34.168 D/LocBroadcastReceiver(22528): Bearing: 22.36026
01-12 21:37:35.173 D/LocBroadcastReceiver(22528): Received location update.
01-12 21:37:35.173 D/LocBroadcastReceiver(22528): Last Location: 
01-12 21:37:35.173 D/LocBroadcastReceiver(22528): Coords:(55.6377838, 37.3556904)
01-12 21:37:35.173 D/LocBroadcastReceiver(22528): Accuracy: 35.413
01-12 21:37:35.173 D/LocBroadcastReceiver(22528): Bearing: 90.88143
01-12 21:37:36.164 D/LocBroadcastReceiver(22528): Received location update.
01-12 21:37:36.165 D/LocBroadcastReceiver(22528): Last Location: 
01-12 21:37:36.165 D/LocBroadcastReceiver(22528): Coords:(55.6377827, 37.355701)
01-12 21:37:36.165 D/LocBroadcastReceiver(22528): Accuracy: 33.987
01-12 21:37:36.165 D/LocBroadcastReceiver(22528): Bearing: 96.98896
01-12 21:37:37.178 D/LocBroadcastReceiver(22528): Received location update.
01-12 21:37:37.179 D/LocBroadcastReceiver(22528): Last Location: 
01-12 21:37:37.179 D/LocBroadcastReceiver(22528): Coords:(55.6377822, 37.3557159)
01-12 21:37:37.179 D/LocBroadcastReceiver(22528): Accuracy: 32.967
01-12 21:37:37.179 D/LocBroadcastReceiver(22528): Bearing: 94.43616
01-12 21:37:38.171 D/LocBroadcastReceiver(22528): Received location update.
01-12 21:37:38.172 D/LocBroadcastReceiver(22528): Last Location: 
01-12 21:37:38.172 D/LocBroadcastReceiver(22528): Coords:(55.637778, 37.3557418)
01-12 21:37:38.172 D/LocBroadcastReceiver(22528): Accuracy: 31.025
01-12 21:37:38.172 D/LocBroadcastReceiver(22528): Bearing: 102.25662

in this case its possible a play services update triggered the change…you can try bumping the services to latest version and see if that fixes the issue? Does it keep happening if you force stop the app and it triggers the registration again?

Yes, it keeps happening after triggering registration.

Google Play Services is already the latest version (21.48.15).
I’ve cleared data and uninstalled updates for Google Play Services reverting it back to the stock version. It solved the issue! After a reboot HA app receives location updates every 30 seconds as expected.
I don’t know for how long it helped though because Google Play Services will eventually update itself back to the latest version. But another phones works fine with the same version of Google Play Services so maybe it is just a random bug.
The strange thing is that Google Play Services was updated on January 6 while the bug appeared on January 12.

I’ve just found that today another one phone was affected by this issue. We have 4 phones in our family. Now 2 phones are affected by the issue and 2 phones are not affected. All phones have the same Google Play Services version (21.48.15). It is very strange.
When the one phone was affected I thought it’s just a random bug, but now it doesn’t look like a bug.

On the second affected phone I just cleared the data of Google Play Services without downgrading and it fixed the issue for now. I wonder if it will reappear after some time or not.

@dshokouhi After a few days the issue reappeared. And even more - now it happens on all 4 phones!

I figured out that:

  1. It appears when you have the latest version of Google Play Services (21.48.15)
  2. It appears a few days after the latest version of Google Play Services was installed
  3. Clearing the Google Play Services data fixed the issue, but after a few days it appears again.

I guess some code changes in HA app are needed to mitigate against this issue.

Maybe the delay for sending updates to HA should be increased from 5 to 30 seconds, like this?

        if (now < lastLocationSend + 30000 && !geofenceUpdate) {
                "New location update not possible within 30 seconds, not sending to HA"

Also in the latest versions of HA app a geocoded sensor update is forced each time a location update is received, that is each second. A delay needs to be added to this code too:

    private fun handleLocationUpdate(intent: Intent) {
            if (location.accuracy > minAccuracy) {
                Log.w(TAG, "Location accuracy didn't meet requirements, disregarding: $location")
            } else {
                // Update GeoLocation Sensor (if enabled) with new Location
                val geoSensorManager = SensorReceiver.MANAGERS.firstOrNull { it.getAvailableSensors(latestContext).any { s -> s.name == commonR.string.basic_sensor_name_geolocation } }
                if (geoSensorManager != null) {
                    if (geoSensorManager.isEnabled(latestContext, "geocoded_location")) {
                    } else {
                        HighAccuracyLocationService.updateNotificationAddress(latestContext, location)

This wont work because it will have an impact on high accuracy mode as the default is every 5 seconds.

All this code is doing is updating the database with the value, the value is not being sent to HA at this moment. It gets sent on the next sensor update.

Best course of action would be to file a bug with google and wait for them to fix it. I have not seen this myself and my play services version is the same as the one listed above.

Any ideas about where can I submit a bug report for Google Play Services?
I know about the Android bug tracker but it doesn’t seem to be the right place.

Very strange. For me it is reproducible on 5 different phones.

Please note that this happens only when GPS is in use (for example, when you launch maps, navigation app or just a GPS Test app). GPS updates every second, and HA app starts to receive location updates every second too.
When GPS is not in use, location update interval is normal.

seems like some peopel are filing google bugs here and they are being assigned, I dont see anything direct either


Just tried launching maps for 1 minute and I only see 2 reports which is expected

Thanks for the hint, I’ve just filed a bug report here, let’s wait for an answer.

BTW, I can confirm that this happens on the latest version of HA app (2022.1.1) too (location is received every second and sent to HA server every 5 seconds), so it is not related to the old version of HA app that I use.