Ability to discard bogus locations

Google geolocation on Android devices is not ideal. In some conditions it reports a location miles away from your actual location, reporting it as a high accuracy one.
This may happen in a subway, shopping mall, rural area (Google uses nearby Wi-Fi hotspots to determine location and this may happen if someone has relocated their Wi-Fi hotspot without letting Google know it).
Also there are military jammers which “teleports” you to an airport or even different country.

My suggestion is to enhance mobile_app. Add a new optional configuration option where a user can add the list of such bogus locations. This should a system-wide config, not tied to a specific device. If mobile_app component receives location update and it matches a bogus location from the list, this location update should be ignored.

Example of such bogus location from Home Assistant log (I’ve enabled homeassistant.components.mobile_app.webhook: debug in logger settings):

{‘location_name’: ‘’, ‘gps’: [55.7158481, 37.8178985], ‘gps_accuracy’: 20, ‘speed’: 0, ‘altitude’: 171, ‘course’: 0, ‘vertical_accuracy’: 5}

Just entered the subway and Google shows me 30 miles away in this specific location with accuracy = 20.

Are these bogus locations actual locations where one could be expected to be there or are they in the middle of nowhere? If they are actual locations, you need some logic there as well. Are the bogus locations always the exact same coordinates or do they vary a bit from one time to the next time?

Are these bogus locations actual locations where one could be expected to be there or are they in the middle of nowhere?

Some of them may be actual locations, some of them may be in the middle of nowhere.

Are the bogus locations always the exact same coordinates or do they vary a bit from one time to the next time?

I assume the coordinates are always exact same. Could not double check that because the log was deleted after home assistant restart :frowning: The proposal is to filter out this exact coordinates.

Are the bogus locations always the exact same coordinates or do they vary a bit from one time to the next time?

Hmm… unfortunately it seems they vary a bit. So a simple list won’t work.

I’ve got some examples:

These are bogus locations.

2020-08-09 15:57:21 {'location_name': '', 'gps': [55.7158481, 37.8178985], 'gps_accuracy': 20, 'speed': 0, 'altitude': 171, 'course': 0, 'vertical_accuracy': 5}

2020-08-12 11:55:15 {'location_name': '', 'gps': [55.8258158, 37.6261062], 'gps_accuracy': 42, 'speed': 0, 'altitude': 178, 'course': 0, 'vertical_accuracy': 0}

2020-08-12 12:14:43 {'location_name': '', 'gps': [55.7155337, 37.8182906], 'gps_accuracy': 21, 'speed': 0, 'altitude': 164, 'course': 0, 'vertical_accuracy': 0}

2020-08-12 12:15:24 {'location_name': '', 'gps': [55.7151351, 37.81871], 'gps_accuracy': 21, 'speed': 0, 'altitude': 167, 'course': 0, 'vertical_accuracy': 0}

This is a real location where the user actually is at this time.

2020-08-12 12:20:27 {'location_name': '', 'gps': [55.8079095, 37.46499], 'gps_accuracy': 41, 'speed': 0, 'altitude': 189, 'course': 0, 'vertical_accuracy': 0}

So I don’t know how to filter them out. :frowning: And yes, this bogus location is the actual location at the opposite side of the city where one could be expected to be there, just 15 miles away from the real location. And another one a few miles away too, at the middle of a residential district.

Just blame Google and live with it? :frowning:

This is how it looks like on the map. Insta-teleportations to the different part of the city.

This is how it ideally should look like without this bogus locations. I’ve drown the red line in Paint.

So, any ideas? Or just blame Google and live with it? :frowning:

May be calculate distance and time from previous location update and discard new location it if it is unrealistically too far away (assuming we don’t use home assistant geolocation in an airplane :slight_smile: )?

However if location updates are happening every 15 minutes, one can really get 20 miles away in this time. :frowning:

I was forcing more frequent location updates for testing, but by default they happen every 15 minutes if the app is closed.

With varying locations and the bogus locations being real locations, where you can even go there in the time between GPS updates, I’d say your feature request is extremly hard if not impossible to fulfill.
You may try other GPS apps like e.g. GPS Logger

May be implement this? This will filter at least a part of this bogus locations if location updates are happening more frequently than 15 minutes (and they should happen more frequently, it’s a bug that subscription for location updates vanishes after some time, bug #698).

I can even explain why this bogus locations happen in my case and why this is not fixable by Google itself.

Subway trains (trains! not the stations!) are equipped with Wi-Fi hotspots. Most of the stations are underground and GPS is not working here. But there is a small section of the line where it goes on the ground, not under it, and GPS does work here.
So an Android user while being here sends geolocation to Google, and Google binds that Wi-Fi hotspot to this specific location.
When a user encounters this Wi-Fi hotspot under the ground without GPS available, Google thinks he is in that location, resulting in wrong position.

I would not be surprised if location is taking into account Wifi SSID that are seen and giving the “estimated” gps location for that SSID.

If you make this trip with Wifi disabled, I wonder if the results will be the same?

Yes, exactly this. Just a little correction. It is taking into account Wifi BSSID, not SSID.

But this mechanism in general improves geolocation a lot, so it is undesirable to disable Wi-Fi.
With multi-storey buildings having tens of Wi-Fi hotspots each this gives pretty accurate location in the city even without GPS. Without this either the location will be done by cell towers and will be very inaccurate (and discarded by Home Assistant Android app btw, I had to make my own custom build to overcome this), or you need to keep a GPS navigation app open which will vastly drain the battery.

Note that you should not only disable Wi-Fi, but also disable background Wi-FI scanning which is in geolocation settings and works even when Wi-Fi is disabled.

Sorry for my bad English if any. I hope you understood what I mean.


This would assume that you never travel by plane. I mean let’s imagine that you fly from Moscow to Rome, your location would always be the airport of Moscow, because the filter would leave out your location in Paris as you travelled there “too fast”.
In addition, what happens when the bogus location is in a reasonable distance from the actual location, so that the filter would not discard it?

Yes, that’s true.

At least we will discard the locations that are too far away. Better than nothing.

I’ve seen many bug reports about incorrect locations miles away from actual place. This might fix it.

Any other suggestions?

Unfortunately not, I’m sorry. I never thought about it, I don’t care so much about my location outside the home, only about entering/leaving zones and this works fine for me.

There is also proposal from user klejejs in Incorrect current location and geocoded location · Issue #661 · home-assistant/android · GitHub

What if the app would collect all locations but then remove the unlikely ones from history?

For example, what if it would work like this:

First (legitimate) location is received and it shows on map.
Second (bogus) location is received after 15 minutes and it also shows up on map but it is 20km away.
Third (legitimate) location is received and it is the same as the first one. It is also shown on map but at that point the second one is calculated to be unlikely one and it is deleted from the history.

Yes, at some point the bogus locations would be showing up on map, but they would at least be deleted from history and the history view would be correct.

In that case the fix should be implemented in HA Core.

What do you think of the solution? Is it valid? Should it be looked into?

One implementation: You could set a limit of speed, so if the user travels too fast, it moves at max speed towards that location.