Home Assistant Android version:
2.3.3-full
Android version:
10 (OnePlus 8Pro)
10 (Pixel 3)
9 (Joying JY-HOS02N4GS-1 (car stereo running android))
Phone model:
OnePlus 8Pro
Pixel 3
Joying JY-HOS02N4GS-1 (car stereo running android)
Home Assistant version:
0.114.4
Last working Home Assistant release (if known):
probably never
Description of problem:
The GPS speed which is reported by the app is not accurate, in fact it is too low. I'm using a mariadb instance for home assistant and dug around a bit.
_Selection criteria_
_What I found_
Considering the fact that I live in germany and drive on the autobahn you can see why a maximum speed of 56 has to be a mistake :joy:
Traceback (if applicable):
Screenshot of problem:



Additional information:
There is already one topic on the home assistant forum (couldn't find an issue here on github related to this)
Like I mentioned on the forum, I search through this repo looking for the locaton update functionality and all I could find was the declaration for the speed variable as type int and then the locationupdate/locationdata from Android itself. So as long as android delivers the correct raw data for GPS, we should be fine. That's at least my uneducated interpretation of it. The thing is though, the GPS speed on my devices is accurate, at least when using other apps utilizing GPS; Waze for example. I'll install an additional GPS data logger in my car tomorrow, this way I should have two datasets that can be compared.
One thing to note about the device tracker is that if your reported accuracy is greater than 200m then we will actually not send that value over. That could be a reason why you don't see the speed the way you expect.
In terms of raw GPS that requires the app to support it and currently we use google location services for tracking
That's a good point. I checked for accuracy as well with the same search criteria. Out of the 28k entries, 2 were over 200 and ~600 over 100. When combining the criteria gps_accuracy and speed, it's even less like that the gps_accuracy is the culprit.
Entries with speed > 0 and and gps_accuracy > 200 = 0 That does make sense, if the accuracy is bad, speed is most likely unreliable as well.
But entries with speed > 0 and gps_accuracy > 100 were only 41.
google location services still utilizes GPS though, right? I thought it is a combination of celltower, wifi and GPS (when available) for the location. So I would expect the location.speed to be fed by GPS only. Is that assumption correct?
google location services is an API that does all of that calculation on their own, we just use the API and retrieve the data:
https://developer.android.com/reference/android/location/Location#getSpeed()
That link contains the answer to our questions (and in hindsight is VERY obviuos)
getSpeed()
Get the speed if it is available, in meters/second over ground.
So if we convert the maximum value 56 and multiply it by 3,6 (conversion from meters/second to kilometer/hour) we get 201,6km/h, which matches the maximum speed for that tour.
Would it be possible to update the companion documentation to leave an additional hint that gps speed is measured in meters/second. Could save someone an hour or two.
One thing I fogot though. The google documentation mentions gps_speed defined as float. Shouldn't HA use float as well instead of integer?
Would it be possible to update the companion documentation to leave an additional hint that gps speed is measured in meters/second. Could save someone an hour or two.
We actually link to the docs page when we discuss about the entity attributes under location: https://companion.home-assistant.io/docs/core/location#entity-attributes
I know easy to miss! If you feel it can use some touch please feel free to click on "edit this page" at the bottom and submit an update so we can add it! Anyone is free to submit updates to the docs :)
One thing I fogot though. The google documentation mentions gps_speed defined as float. Shouldn't HA use float as well instead of integer?
I am not sure what the specific reasons were for using an integer there
No, I actually think this is the right place. No idea why my google skills failed me so miserably this time.
I would still propose to use float for speed in HA since the input is float as well and loosing the floating precision (I guess max difference of 0.4 through rounding) which matters even more since either kmh or mph have to be multiplied and the difference becomes even bigger. But granted, this is more of a cosmetic enhancement in my opinion.
Should I close this issue or leave it open for the float to int discussion?
Maybe @JBassett can help here since he is the contributor for UpdateLocationRequest.kt
Any reason why val speed is set to int and not float since google location services returns float
The mobile_app integration expects it to be positive integer: https://github.com/home-assistant/core/blob/dev/homeassistant/components/mobile_app/webhook.py#L313
And why it's in m/s: https://developers.home-assistant.io/docs/api/native-app-integration/sending-data#update-device-location
Alright, that settles it then. I'll close the issue and thank you @JBassett and @dshokouhi for your time and explanations.
Have a good one! :)
Most helpful comment
The mobile_app integration expects it to be positive integer: https://github.com/home-assistant/core/blob/dev/homeassistant/components/mobile_app/webhook.py#L313
And why it's in m/s: https://developers.home-assistant.io/docs/api/native-app-integration/sending-data#update-device-location