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

Crazy speed data - like 2,200km/h #66

Closed
jata1 opened this issue Mar 12, 2024 · 86 comments
Closed

Crazy speed data - like 2,200km/h #66

jata1 opened this issue Mar 12, 2024 · 86 comments

Comments

@jata1
Copy link

jata1 commented Mar 12, 2024

Hey @pnbruckner - First of all thanks for this integration.

I have just installed this and I am using it to combine 2 GPS device trackers that both work well (HA companion app and icloud3 integration).

The main reason for using this is to have a speed sensor for my iphone. Generally it works ok but I am getting the occasional crazy speed - like over 2000 km/h :-)

Can you help me to trouble shoot this or is it something I will have to live with (or find a way to deal with the bogus data)?

I need accurate speed data as I am trying to create an open source and data privacy based system for monitoring my teenage son's driving. Basically life 360 but home grown.

@pnbruckner
Copy link
Owner

It does have some minimal filtering. E.g., if two data points are too close together in time (3 seconds for the same input, and 9 seconds for different inputs), it will not update the speed.

The problem may be the types of trackers you are using. Many do not have an attribute that specifies when the location data actually changed (e.g., last_seen.). In this case, the composite has to use when the tracker updated as a backup. Those two can be very different.

Can you share the attributes of the two types of trackers? Obviously, obfuscate any sensitive data.

@jata1
Copy link
Author

jata1 commented Mar 12, 2024

Appreciate the help. I am getting so close to my overall project goal... Accurate speed is my last hurdle.

icloud3 tracker:

source_type: gps
battery_level: 45
latitude: -33.759368896484375
longitude: 151.29751418740335
gps_accuracy: 11
gps: (-33.759368896484375, 151.29751418740335)
"------------------------": "-------------------------"
integration: iCloud3
name: Jago iPhone/jago_iphone
entity_picture: /local/None
picture_file: /local/None
track_from_zones: home
primary_home_zone: Home
away_time_zone_offset: HomeZone
"-------------------------": "-------------------------"
data_source: MobApp
device_status: Online/200
trigger: launch@10:26:23p
zone: home
last_zone: home
from_zone: home
home_distance: 0
zone_distance: 0
max_distance: 3.753
calc_distance: 0.002433
waze_distance: 0
distance_to: ———
zone_changed: "2024-03-12 21:02:20"
last_located: "2024-03-12 22:26:23"
last_update: "2024-03-12 22:26:25"
next_update: "2024-03-12 22:36:25"
"--------------------------": "-------------------------"
icloud3_devices: jago_iphone
icloud3_version: v3.0.rc10.4
event_log_version: v3.0.17
icloud3_directory: /config/custom_components/icloud3
icon: mdi:cellphone
friendly_name: Jago iPhone

and the HA app device tracker

source_type: gps
battery_level: 45
latitude: -33.759368896484375
longitude: 151.29751418740335
gps_accuracy: 11.158759062906178
altitude: 38.62611389160156
vertical_accuracy: 24.223766326904297
friendly_name: Jago iPhone HA

@pnbruckner
Copy link
Owner

Are those the state attributes of the device_tracker entities? The formatting is a bit unexpected, at least for the icloud3 source.

The HA app tracker does not seem to have any sort of location timestamp. That is a shame, but not unexpected. I've tried to convince the powers-that-be how important such an attribute is, but my arguments have fallen on deaf ears.

For the icloud3 input, the opposite seems to be the case. There are several timestamps. Any idea which one, if any, indicates when the GPS fix was taken? If I had to guess, I'd say last_located. I wonder how much that differs from the device_tracker entity's last_updated state field (which is not to be confused with the tracker entity's last_update attribute.)

Maybe you could run the following Jinja template for each of the trackers and post the results here:

{% set state = states.device_tracker.XYZ %}
{{ '{:20}: '.format('last_updated') ~ state.last_updated }}
{% for attr, val in state.attributes.items() -%}
{{ '{:20}: '.format(attr) ~ val }}
{% endfor %}

@jata1
Copy link
Author

jata1 commented Mar 12, 2024

Thanks for this. I will report back later today.

Maybe I could use another app/service with the nevessary gps attributes?

the other thing is that icloud3 uses the gps data from the HA app somehow. So this might explain the issue

@jata1
Copy link
Author

jata1 commented Mar 12, 2024

I have run the Jinja code and it looks like both do have a last_updated timestamp.

Not sure why this attribute was not showing in Developer tools for the HA app entity. Must be a hidden attribute or something.

image

Here is the output for the HA tracker using the jinja above,

last_updated        : 2024-03-12 19:23:47.036138+00:00
source_type         : gps
battery_level       : 100
latitude            : -33.759388704333986
longitude           : 151.29751418740335
gps_accuracy        : 11.158759062906178
altitude            : 43.66053009033203
vertical_accuracy   : 27.649686813354492
friendly_name       : Jago iPhone HA

and for icloud3

last_updated        : 2024-03-12 20:21:15.875056+00:00
source_type         : gps
battery_level       : 100
latitude            : -33.759388704333986
longitude           : 151.29751418740335
gps_accuracy        : 11
gps                 : (-33.759388704333986, 151.29751418740335)
------------------------: -------------------------
integration         : iCloud3
name                : Jago iPhone/jago_iphone
entity_picture      : /local/None
picture_file        : /local/None
track_from_zones    : home
primary_home_zone   : Home
away_time_zone_offset: HomeZone
-------------------------: -------------------------
data_source         : FamShr
device_status       : Online/200
trigger             : FamShr@07:21:14
zone                : home
last_zone           : home
from_zone           : home
home_distance       : 0.0
zone_distance       : 0.0
max_distance        : 0.0
calc_distance       : 0.003511
waze_distance       : 0.0
distance_to         : ———
zone_changed        : 2024-03-13 02:00:26
last_located        : 2024-03-13 07:21:14
last_update         : 2024-03-13 07:21:15
next_update         : 2024-03-13 07:31:15
--------------------------: -------------------------
icloud3_devices     : jago_iphone
icloud3_version     : v3.0.rc10.4
event_log_version   : v3.0.17
icloud3_directory   : /config/custom_components/icloud3
icon                : mdi:cellphone
friendly_name       : Jago iPhone

@jata1
Copy link
Author

jata1 commented Mar 13, 2024

I also have some new data points for us to look at to investigate. Here are the updates that were pushed from HA to my traccar server. Lots of data points look more or less correct but I have highlighted the rows that are rubbish.

I can compare to the native traccar client that I am also using for testing but is not a good long term solution as it is a battery hog.

Files uploaded are ready to assist!

report_trip_composite.xlsx
report_trip_traccar_client.xlsx

@jata1
Copy link
Author

jata1 commented Mar 13, 2024

I have found one error in my work. Traccar is expecting data to be passed in kts and I am using kmh. I think this will partially fix the issue but It is still not right where I have flagged the data in the xls.

Attaching the traccar server log - this is where / how I found the kn v. kmh issue

tracker-server_copy.log

@pnbruckner
Copy link
Owner

I have run the Jinja code ...

Thanks for doing that! I guess I was surprised by those icloud3 attributes, and thought you were originally showing some sort of report or other info and not simply the entity's attributes. Very unexpectedly, that entity has three very unusual and strange attributes whose names and values are a bunch of "-" characters. Weird.

...and it looks like both do have a last_updated timestamp.
Not sure why this attribute was not showing in Developer tools for the HA app entity. Must be a hidden attribute or something.

The last_updated timestamp you see is not an attribute, it is a field of the entity state object. You can see it here:

image

It is not directly set by the integration, but rather by the system when the integration updates the entity. It records when the entity is updated. It is not a direct indication of when the GPS values were obtained at the source (i.e., in the cell phone.)

Those two times (when the GPS values are obtained in the phone, and when the HA entity is updated with those values) can be very different, depending on how those values are transferred to the HA entity. There could be seconds between them. I've even seen with some tracker entities where GPS values are received out of order due to network delays, etc. This is why it is very important (when trying to combine multiple GPS sources and/or trying to calculate speed) to have the data timestamped with when the data was actually obtained at the source.

When this timestamp information is not available, the composite integration does the only thing it can and will use that last_updated field instead, which almost certainly is wrong. Not only that, but it's also using HA's time source, which could be different from the phone's time source (which becomes much more important when combining multiple sources, where some have timestamps from the phone's time source, and others are using HA's time source, although, these days, most of these devices keep their time synced pretty well.)

So, again, the HA tracker has no timestamp for the GPS data. And I have no idea how much delay there may be between when the GPS values are obtained at the source and when the corresponding HA entity is updated, if it's consistent or if there's a lot of jitter, if data can be received out of order, etc. Here the only thing the composite integration can do is to use the last_updated field, with all the caveats mentioned above.

And looking at the icloud3 entity, there are multiple time values, where last_located is probably the correct one to use. But, unfortunately, it's a naive time (i.e., no time zone info.) Comparing it to last_updated (which is time zone aware in UTC), it looks like its offset from UTC is +11:00. That seems to jive with the GPS coordinates. The problem here, though, is, how can the composite integration know what the correct time zone is? It could assume it's "local time" where HA is, but what if the phone is actually in a different time zone? What time zone will the last_located field correspond to? HA? The phone? Yes, composite could use the GPS coordinates to look up the time zone, but I just took those features out of the composite integration.

If you could check with the icloud3 author as to which attribute, if any, records the actual time when the GPS fix was taken, and what time zone it corresponds to, then I could enhance composite to use that data.

@jata1
Copy link
Author

jata1 commented Mar 13, 2024

Thanks for the detailed and very helpful explanation. I will follow up with the icloud3 author and also make a request to HA core team to add the fix time info to the iOS companion app.

Just thinking out loud but I wonder if the HA companion app for android has this attribute

@pnbruckner
Copy link
Owner

also make a request to HA core team to add the fix time info to the iOS companion app.

You can ask, but they'll likely not do it. Even if they add the data, they won't add it as an attribute. I tried to modify the gpslogger integration to do this and it was rejected. They wanted the data in a separate sensor, which is basically useless.

@jata1
Copy link
Author

jata1 commented Mar 13, 2024

Well I will try and ask them.

What is the issue with a separate sensor? Is it related to having gps coordinates and fix time synchronous?

I can’t believe how hard it is to use gps to estimate speed. I thought there would be plenty of integrations. How is life360 doing it?

@jata1
Copy link
Author

jata1 commented Mar 13, 2024

I think I have a possible workaround for my use case. I just need to identify rubbish speed data then not push this to my Traccar database/ststem.

Just need to work out how to identify bogus data on the fly. I think the issue is related to when the composite integration gets twitchy gps data very close together

@jata1
Copy link
Author

jata1 commented Mar 13, 2024

This is data that i am pushing with an automation and REST API from HA to Traccar. While I am sleeping with phone on charge - so not moving. All I need to do is just identify and optionally not push these updates to traccar. Any ideas?

image

@pnbruckner
Copy link
Owner

Yes, in your case, it seems you need to work around the lack of data which is generating incorrect results. The better solution would be to obtain the data you need. For the HA app, I think that is a non-starter. For icloud3, I suspect it's possible. I started looking at the custom integration code, but it's pretty big and will take a bit to get through it enough to try and figure this out myself.

The alternative is to use better data sources. I myself use Google Maps (my own custom version of it), as well as gpslogger (yep, my own custom version of it, too.) You could use either or both of those if you like. The nice thing about Google Maps is, people often already have that on their phones, even Apple phones, and either already have location sharing set up, too, or can easily add it.

@jata1
Copy link
Author

jata1 commented Mar 13, 2024

righto. I will see what I can find out about about icloud3 and I will report back.

I do have google maps on my phone so I will try that integration and also gpslogger too.

I just went to take my son to the dentist then to school and I was driving at 290km/h at one point. LOL

@pnbruckner
Copy link
Owner

I wonder if the outliers are due to the interaction of the two trackers, or if it's mostly from just one. Might be interesting to add two more composite entities, where each uses just one of the two "input" trackers. Then you'd get speed readings for each individually. If those are reasonable, then it's the interaction (which is probably due to lack of proper timestamps for the location data.)

@pnbruckner
Copy link
Owner

pnbruckner commented Mar 14, 2024

I read the icloud3 code some more, and it's quite, um, different. It seems to like to do things the hard way.

Anyway, as best as I can tell, the last_located (and other time attributes) are in the "local" time of the phone HA. If the phone is in a different time zone than HA, then the away_time_zone_offset will reflect that. E.g., when the phone is in the same time zone as HA, that attribute's value will be "HomeZone" (as it is above in your captured output.) But, if the phone is in a different time zone, then it will be "HomeZone X hours", where X is between -12 & 12. Then, when the phone returns to HA's time zone, it ... um ... wait, it should change back to "HomeZone", but I think there's a bug and it will still indicate the offset of the last time zone the phone was in that wasn't HA's time zone. Argh!

Do any of your phones that use the icloud3 integration ever go in a different time zone? It would be interesting to see if I'm reading the code right.

@pnbruckner
Copy link
Owner

Wait. Just realized, if the times are always in HA's time zone, then that should work fine. I'll add support for it. I'll try to check with the author to see if my interpretation is correct.

@jata1
Copy link
Author

jata1 commented Mar 14, 2024

Thanks for such awesome help with this. Above and beyond for sure.

I will try out your google maps integration to see how that works for me. Although probably only for testing.

My project goal is to be able to keep an eye on my son's driving as he is getting to the age where he will be driving and in cars with friends. The snag is the traccar client app is a total battery hog but the location and speed data is OK.

Right now I want to use a combo of GPS device trackers that give me high location accuracy & frequency that do not drain the battery on my phone. Once I get everything working for me then I will setup my son in the same way.

@jata1
Copy link
Author

jata1 commented Mar 14, 2024

Do any of your phones that use the icloud3 integration ever go in a different time zone? It would be interesting to see if I'm reading the code right.

Nope. All local in here in NSW Australia at the moment. Only on my phone currently and I installed it a few days ago so its all quite new.

@jata1
Copy link
Author

jata1 commented Mar 14, 2024

I wonder if the outliers are due to the interaction of the two trackers, or if it's mostly from just one. Might be interesting to add two more composite entities, where each uses just one of the two "input" trackers. Then you'd get speed readings for each individually. If those are reasonable, then it's the interaction (which is probably due to lack of proper timestamps for the location data.)

I have been thinking something similar myself. One feature of the icloud3 tracker is that is already interacting with the HA tracker. I think it uses HA tracker together with icloud to handle location and maybe this is part of the issue.

I will setup a composite just with HA tracker and see how that works but we already know that the HA tracker is missing an important date/time attribute.

GPSlogger is android only so that's not an option.

I have google setup but can't see any location data in the entity so something went wrong with my setup/cookie stuff i think.

@pnbruckner
Copy link
Owner

I have google setup but can't see any location data in the entity so something went wrong with my setup/cookie stuff i think.

Are you using my custom version, and latest version? If so, you should enable debug for it. Then, on the log page, type "custom_components.google_maps" in the search box and click LOAD FULL LOGS. There should be some messages that can give some clues as to what's going on.

@jata1
Copy link
Author

jata1 commented Mar 14, 2024

I am using your google integration and installation / cookie went fine I think.

below are the only logs I can find - with debug on. Looks OK to me. I was expecting to see GPS info in the attributes but there is nothing.

image

2024-03-14 14:45:10.387 DEBUG (SyncWorker_0) [custom_components.google_maps.gm_loc_sharing] [email protected]: Cookies: 1P_JAR: 2024-04-13 11:45:50, AEC: 2024-09-10 11:42:58, SEARCH_SAMESITE: 2024-09-10 11:44:22, NID: 2024-09-13 11:43:33, SIDCC: 2025-03-14 14:43:56, __Secure-1PSIDCC: 2025-03-14 14:43:56, __Secure-3PSIDCC: 2025-03-14 14:43:56, APISID: 2025-04-18 11:45:41, HSID: 2025-04-18 11:45:41, SAPISID: 2025-04-18 11:45:41, SID: 2025-04-18 11:45:41, SSID: 2025-04-18 11:45:41, __Secure-1PAPISID: 2025-04-18 11:45:41, __Secure-1PSID: 2025-04-18 11:45:41, __Secure-3PAPISID: 2025-04-18 11:45:41, __Secure-3PSID: 2025-04-18 11:45:41
2024-03-14 14:45:12.000 DEBUG (MainThread) [custom_components.google_maps.coordinator] Finished fetching [email protected] data in 1.184 seconds (success: True)
2024-03-14 14:47:12.784 DEBUG (MainThread) [custom_components.google_maps.coordinator] Finished fetching [email protected] data in 1.004 seconds (success: True)

@jata1
Copy link
Author

jata1 commented Mar 14, 2024

So just working on the HA side of things. This is data from my latest test drive in the car. Circled in yellow is actual driving. The rest is nonsense. What this is telling me (for this trip/drive) is overall not bad.

no crazy spikes (might be lucky)
HA app data is quite good but low update frequency
icloud not bad but with a few drops (as I didn't stop)
Traccar app was set to 60 second updates and is picking up lots of false movement/speed after the drive

So i'm hoping that with a bit of your help we can create a fairly good speed sensor with icloud and HA app.

I'm going to create a sensor that uses the average for HA and icloud and use this to push into traccar server - even better would be to do this and drop crap data as this will skew the data.

image

@jata1
Copy link
Author

jata1 commented Mar 14, 2024

Just one more update. Went for another drive and it is the icloud3 tracker that keeps generating crazy speed values so I think this is where the root of the issue is that I need to find/fix - or just stop using the icloud3 integration. After all, I am only using it as I thought it would be better and/or combine well with the HA tracker.

It would be good to get the google tracker working then I have something else to compare with...

@pnbruckner
Copy link
Owner

I'm a bit confused about the Traccar data. You keep referring to pushing data to it, but you're also getting data from it??? Is it providing independent GPS data, or is it somehow data derived from the other trackers?

Note that the speed sensor only updates when it gets valid input that represents a new position. If the input(s) aren't changing, or the inputs are being rejected (for various reasons, typically they contain older data than the composite has already seen), then the speed sensor output won't change. That could be why the iCloud spike lasts a while. Also, it won't "drop" due to lack of new data.

Regarding the Google Maps integration, that's very strange. Which account did you add to the integration? Your personal account that is associated with your phone? Given the name of the tracker entity, it does appear you're using the "Account Holder" location. If you're using a different Google account (e.g., one you created just for use with this HA integration), then you should not use the "account holder" tracker, and you need to share your personal Google account's location with the account you add to the HA integration. Hopefully, that makes sense.

@jata1
Copy link
Author

jata1 commented Mar 14, 2024

I'm a bit confused about the Traccar data. You keep referring to pushing data to it, but you're also getting data from it??? Is it providing independent GPS data, or is it somehow data derived from the other trackers?

There is the traccar server and also a client app for ios. In HA there are integrations for both the server and client.

To help with this testing, I have the traccar iOS client app (a GPS tracker) --> Traccar Client in HA -this gives me good test/baseline data for speed.

In addition, I am working with you on other options for GPS tracking for my iphone. In all cases (traccar client or HA/icloud/google) I need to push the data from HA to the traccar server. Pushing the data into the traccar server is all working fine. I have this part working great it can even test speed v. location based speed limit and notifications when speeding.

Guess what? Driving at 2,000 km/h triggers a speeding notification. :-)

@jata1
Copy link
Author

jata1 commented Mar 14, 2024

I am just using my personal google account in 'account holder' mode. For testing this is all I need I think. Issue is I'm not getting any data through this integration... Yet... Not sure what I have done wrong. Your instructions were quite clear and everything seemed to work fine - just not getting data into HA.

@pnbruckner
Copy link
Owner

When you get no location data with the account holder tracker, that generally means it's not linked to an actual device. Do you have Google Maps installed on your iPhone and logged into the same Google account? If you open https://www.google.com/maps in a browser, logged into that same account, can you see your device location?

@jata1
Copy link
Author

jata1 commented Mar 16, 2024

set to query every minute and this is what I see in the logs every minute.

024-03-17 08:18:54.008 DEBUG (SyncWorker_0) [custom_components.google_maps.gm_loc_sharing] [email protected]: Raw data: )]}'
2024-03-17 08:18:54.056 DEBUG (MainThread) [custom_components.google_maps.coordinator] Finished fetching [email protected] data in 0.913 seconds (success: True)

@jata1
Copy link
Author

jata1 commented Mar 16, 2024

I think he means the last_changed or last_updated state fields, not attributes, as we've discussed before. If that's right, then yeah, the data is "timestamped" by when the HA integration sees it and not when the data is first acquired at the source. This could lead to jitter, and when comparing to other data that is properly timestamped, skew, which itself can cause incorrect speed calculations.

and this is why icloud3 setup with HA together is providing the weird data. I think there is an option to setup icloud3 without linking it with HA mobile app. I will try that next

@jata1
Copy link
Author

jata1 commented Mar 16, 2024

So I have changed how icloud3 works so that it does not try to use HA mobile app data. So now I think we have two separate and hopefully clean data sources for location/speed (HA mobile app and icloud3)

I will monitor both of them today and see what I get in terms of consistency etc.

@pnbruckner
Copy link
Owner

So I just tried the extra debug line in my test system and I'm seeing the same thing. Unfortunately, the raw data has line feeds and HA's log page only shows the first line of log messages. Give me a sec and I'll have you try something slightly different (after I try it myself.)

@jata1
Copy link
Author

jata1 commented Mar 16, 2024

all good. I'm so sorry to be causing you all this work / effort - and it is the weekend too.

Is there a way I can say thanks somehow?

@pnbruckner
Copy link
Owner

Ok, try this instead (with the line you added removed, and a different line entered a bit further down):

    def get_new_data(self) -> None:
        """Get new data from Google server."""
        try:
            resp = self._session.get(_URL, params=_PARAMS, verify=True)
            resp.raise_for_status()
        except (RequestException, MaxRetryError) as err:
            raise RequestFailed(f"{err.__class__.__name__}: {err}") from err
        raw_data = resp.text
        try:
            self._data = json.loads(raw_data[5:])
        except (IndexError, json.JSONDecodeError) as err:
            raise InvalidData(f"Could not parse: {raw_data}") from err
        _LOGGER.debug("%s: Parsed data: %s", self._account_email, self._data)  # <<<<< ADD THIS LINE
        if not isinstance(self._data, Sequence):
            raise InvalidData(f"Expected a Sequence, got: {self._data}")
        try:
            if self._data[6] == "GgA=":
                self._dump_cookies()
                _LOGGER.debug("%s: Parsed data: %s", self._account_email, self._data)
                raise InvalidCookies("Invalid session indicated")
        except IndexError:
            raise InvalidData(f"Unexpected parsed data: {self._data}") from None

The added line is actually a copy of the line just like it a few lines down. Just make sure it's indented correctly.

@jata1
Copy link
Author

jata1 commented Mar 16, 2024

so remove the other debug code and use this new one instead?

@pnbruckner
Copy link
Owner

No problem. I'm just sitting around today watching a few Blackhawks games I recorded earlier (ones that they actually won, which doesn't happen very often anymore! 😆 )

@jata1
Copy link
Author

jata1 commented Mar 16, 2024

just to wind you up I am going to say what are the blackhawks :-)

@pnbruckner
Copy link
Owner

NHL hockey team in Chicago.

@jata1
Copy link
Author

jata1 commented Mar 16, 2024

here we go...

2024-03-17 09:01:07.241 DEBUG (SyncWorker_8) [custom_components.google_maps.gm_loc_sharing] [email protected]: Parsed data: [None, None, '0ahUKEwiTlamX5PmEAxWOgIoHHRQgAvgQ8ZABCAE', 'oxb2ZdO3Bo6BquwPlMCIwA8', None, None, 'GkkAhp/Fo1ScmdATdar9q0zY0qMf3bXcUG6aGblRSGRuIW7r37cXjM60A0kfFKkDTSU5b6kHRd2Vvuu/V37YKxj0bUpCTEOD9GtV', 1800, 1710626467101, [None, [None, [None, 151.29751361489295, -33.759368896484375], 1710591060720, 10, '27 Undercliffe St, Dee Why NSW 2099, Australia', None, 'AU', 39600000, 0], 'IObemfbxr6KmkgE']]
2024-03-17 09:01:07.242 DEBUG (MainThread) [custom_components.google_maps.coordinator] Finished fetching [email protected] data in 0.786 seconds (success: True)

@pnbruckner
Copy link
Owner

Ok, thanks, that's more like it. Let me analyze the data...

@pnbruckner
Copy link
Owner

Well, the data looks good for the "account holder", and there is no location data from any shared accounts.

What is the state of the device_tracker entity?

@pnbruckner
Copy link
Owner

Looks like last_seen is 2024-03-16 23:11:00.720000+11:00.

I don't think there's anything wrong with the integration. For whatever reason, google is not being updated with new location data from your phone.

Try opening Google Maps on your phone, then going to Location Sharing. Sometimes if things are messed up it will give you some sort of option to get it fixed. I've seen this happen a few times (mostly on other people's phones), but not very often, and it hasn't happened very recently, so I don't remember the details

@jata1
Copy link
Author

jata1 commented Mar 16, 2024

Entity details below.

I have checked in location sharing for my google account and there was nothing that I could see. My google account is very old (pre google maps) so maybe there is something with this old account. I will investigate further. Maybe create a HA shared account and then share my personal with the HA account.

image

@pnbruckner
Copy link
Owner

Maybe create a HA shared account and then share my personal with the HA account.

Probably worth a try. But if Google isn't getting new data from your phone, I doubt sharing it to another will make a difference. But who knows!

@jata1
Copy link
Author

jata1 commented Mar 16, 2024

so I have created a shared gmail account and shared my personal account with it. Now I am getting these in the logs. Are we onto something here?

2024-03-17 10:00:52.979 DEBUG (SyncWorker_2) [custom_components.google_maps.gm_loc_sharing] [email protected]: Parsed data: [None, None, '0ahUKEwjj-pDF8fmEAxWLjooHHegkB6cQ8ZABCAE', 'pCT2ZeOYM4udquwP6MmcuAo', None, None, 'GkkAhp/Fo2x0+LJAnbUq7qx70FoPw5QzGaMFTDJwr4QDMZJWhgDFKZsfS+2IllQKyGHLFERAMw/7JolHS1XAaiQekZFedqR95+1P', 1800, 1710630052828, [None, [None, [None, 151.29751380671448, -33.759368896484375], 1710630045502, 10, '27 Undercliffe St, Dee Why NSW 2099, Australia', None, 'AU', 39600000, 0], 'IJfI_czVpMjDaw']]
2024-03-17 10:00:52.980 DEBUG (MainThread) [custom_components.google_maps.coordinator] Finished fetching [email protected] data in 0.526 seconds (success: True) 

@pnbruckner
Copy link
Owner

pnbruckner commented Mar 16, 2024

I'm not sure what you mean by "I have created a shared gmail account".

In any case, there is still just data for the "account holder" (i.e., for the account that you added to the Google Maps integration), no data for any accounts shared with that account, but now last_seen is 2024-03-17 10:00:45.502000+11:00.

@jata1
Copy link
Author

jata1 commented Mar 16, 2024

I created a new gmail account for sharing. Then I shared my location from my personal account to the shared account. Then I added the shared gmail account to HA following the normal instructions to get the cookie file.

Going for a drive to see if this does anything interesting now...

2024-03-17 10:42:15.094 DEBUG (SyncWorker_13) [custom_components.google_maps.gm_loc_sharing] [email protected]: Parsed data: [[[['104190018064803656481', 'https://lh3.googleusercontent.com/a/ACg8ocLtwv_zEb1uCCtu0xNANZn04bDBpt4Y3jkf6FUmMgzl=mo', None, 'Jago Taylor', None, None, None, '0ahUKEwihlNnk-vmEAxV_gYoHHTMzAv4QvDgIAygA'], [None, [None, 151.29751380671448, -33.759368896484375], 1710632484510, 10, '27 Undercliffe St, Dee Why NSW 2099, Australia', None, 'AU', 39600000, 0], 1, None, '0ahUKEwihlNnk-vmEAxV_gYoHHTMzAv4Qu4IBCAIoAA', None, ['104190018064803656481', 'https://lh3.googleusercontent.com/a/ACg8ocLtwv_zEb1uCCtu0xNANZn04bDBpt4Y3jkf6FUmMgzl=mo', 'Jago Taylor', 'Jago'], 0, None, None, None, None, None, [0, 90], 3, None, [1], [1], []]], None, '0ahUKEwihlNnk-vmEAxV_gYoHHTMzAv4Q8ZABCAE', 'Vi72ZaGROv-CquwPs-aI8A8', None, None, 'GkkAhp/Fo2+t5vUwYN3xDAKIIl3FtB9lBmn+AW3qSLhmM0FDkpAsI3B97c6rpKGQMCA3fjeZbwPF/b4ZBvTYd8pcOzd51c3q0C8B', 30, 1710632534947]
2024-03-17 10:42:15.095 DEBUG (MainThread) [custom_components.google_maps.coordinator] Finished fetching [email protected] data in 0.587 seconds (success: True)
2024-03-17 10:42:16.148 DEBUG (SyncWorker_1) [custom_components.google_maps.gm_loc_sharing] [email protected]: Parsed data: [None, None, '0ahUKEwiAoJnl-vmEAxULjooHHZuLC1UQ8ZABCAE', 'WC72ZYAUi5yq7A-bl66oBQ', None, None, 'GkkAhp/FoxRrO/Q0Rojzs/ll6m7xxzj8uabq58rwtALw7apgRzdYYLpXSiqVwzRn1BWpXKApGpsT0yJs//rul6/hnLep5BKpS0Af', 1800, 1710632535992, [None, [None, [None, 151.29751380671448, -33.759368896484375], 1710632484510, 10, '27 Undercliffe St, Dee Why NSW 2099, Australia', None, 'AU', 39600000, 0], 'IJfI_czVpMjDaw']]
2024-03-17 10:42:16.149 DEBUG (MainThread) [custom_components.google_maps.coordinator] Finished fetching [email protected] data in 0.521 seconds (success: True)

@pnbruckner
Copy link
Owner

FWIW, those both contain the same data (well, at least taking into account the "account holder" one is missing some attributes, as the docs explain), and last seen is 2024-03-17 10:41:24.510000+11:00, which was just before your post. 🤞

@jata1
Copy link
Author

jata1 commented Mar 17, 2024

Hey Phil (@pnbruckner) - I have some good news and progress.

  1. location sharing from personal google account to the shared account seems to have activated google location sharing
  2. I have tweaked icloud3 so it doesn't use HA mobile app data (as this was causing speed spikes)
  3. Created a composite using HA, icloud and google
  4. noticed that google and icloud data is similar so one or the other will be fine (for me)
  5. tested the composite against the traccar client running with a 2 minute interval

First chart is traccar client, Second is with the composite overlayed. Third is HA, icloud and google separately.

Let me know what you think but I reckon we have a reasonable solution here. Just need to monitor battery drain on my iphone.

Chart 1 - Traccar client app running at 2min interval (gold standard / baseline)
image

Chart 2 - Composite overlayed on Traccar - (this composite is what I will use instead of traccar for my speeding detection)
image

Chart 3 - the three parts to the composite (HA, icloud and google)
image

@pnbruckner
Copy link
Owner

  1. location sharing from personal google account to the shared account seems to have activated google location sharing

That's surprising, but as long as it's working, then that's all that matters. Yay!

Let me know what you think but I reckon we have a reasonable solution here. Just need to monitor battery drain on my iphone.

Sounds good.

I'm going to back out adding last_located as an attribute composite looks for, but I'll keep the change that accepts a date/time string. I'm still considering adding an option for the user to specify the attribute name (in case some other entity has a useful timestamp in an attribute with another name.)

FWIW, thinking about the template idea some more made me realize it's kind of problematic. I won't go into the details here, but if I do add this feature, it will only evaluate when the associated input changes state, and will provide that new state as a variable to use in the template, allowing it to extract the info from any attribute, as well as to convert it as necessary. I'm just not sure how much use it would get, if any, so not sure it's worth the effort of adding.

@gcobb321
Copy link

I don't mean to jump in but have a question:

  • The iCloud account web service discontinued the find-my-friends location source in May, 2023. iCloud3 was using the location of those friends (they are not in the Family Sharing List) as a data source to also track them. Would/Could your Google Maps custom component be used as a data source like the Mobile App is where it's sensors are monitored for location information changes?

A couple of things with the Mobile App:

  • The Mobile App does not seem to take gps accuracy into consideration when reporting a location. I have seen some wild swings in its location with gps accuracy > 200m. This can lead to Home zone exit triggers when the phone is sitting on a table. iCloud3 filters these locations and does not process them.
  • Update/Change datetime - I have not dug into how the Mobile App gets it data (webhook?. cloudhook?) but wonder if there is a 'sent timestamp' on the message that HA receives and uses to update the sensors.

A clarification a couple of things in iCloud3:

  • Away Time Zone - All location times are kept internally on the HA server time. The Away Time Zone adjustment only effects the display of the times in the sensors, attributes and the Event Log. The last_timestamp is still the HA server timestamp. And yes, it is not set automatically since it was done as a quick addon feature.
  • FWIW - I have changed the datetime items in the device_tracker and sensor attributes back to the standard located: 2024-03-17 11:18:50 (Displays as -- Located: March 17, 2024 at 11:18:50 AM). As I recall, the non-standard setup was done a while back to support 12-hour time formatting. Fell into the old code not revisited camp.

Thanks for the info on the Mobile App last_update/_change times. That explained a few things I have noticed but never understood. It seems that the Mobile App update/change times are either fairly close to the FamShr location times or very far off. Or iCloud3 handles trigger changes before a FamShr locate is scheduled so it does not impact the overall tracking.

@jata1
Copy link
Author

jata1 commented Mar 17, 2024

Big thanks from me to you both for helping me with this. I will run my driving/speedlimit tracking project for a week or so and see how it works in real world conditions.

I have created a feature request for HA mobile app to include the fix time as an attribute. If we had this (and icloud3 used this info) I think I could go back to including the HA mobile app GPS data integrated with icloud3.

@pnbruckner
Copy link
Owner

  • Would/Could your Google Maps custom component be used as a data source like the Mobile App is where it's sensors are monitored for location information changes?

I'm not sure of the context of where this information would be used. In the HA integration? Or somewhere on the phone?

FWIW, the entities created by the Google Maps integration are no different from any other entity in HA in that whenever they change, they cause a state_changed event, and any other integration can watch for those events and use the data however they like. Having said that, I'm not sure I understand the use case. The entity is already directly accessible. What advantage would there be for iCloud3 further processing the information? (I haven't really looked into what iCloud3 does since I don't have Apple phones, so maybe I'm missing something.)

  • The Mobile App does not seem to take gps accuracy into consideration when reporting a location. I have seen some wild swings in its location with gps accuracy > 200m. This can lead to Home zone exit triggers when the phone is sitting on a table. iCloud3 filters these locations and does not process them.

Agreed, very inaccurate location updates can cause problems. FWIW, the Google Maps integration (the standard, built-in one, as well as my enhanced custom version of it) does the same thing in that it has a configurable "max accuracy" option, and any updates that are less accurate (i.e., a bigger value) than that will be rejected/ignored.

  • Update/Change datetime - I have not dug into how the Mobile App gets it data (webhook?. cloudhook?) but wonder if there is a 'sent timestamp' on the message that HA receives and uses to update the sensors.

That is a good question. If it did send a timestamp for the location data to the HA integration, it would be very helpful if it put that information in an attribute of the device_tracker entity. Unfortunately, if there isn't one already (and there doesn't seem to be), if it was added, they would probably put it in a separate sensor entity instead of an attribute of the device_tracker, which, IMHO, is almost useless.

  • Away Time Zone - All location times are kept internally on the HA server time. The Away Time Zone adjustment only effects the display of the times in the sensors, attributes and the Event Log. The last_timestamp is still the HA server timestamp. And yes, it is not set automatically since it was done as a quick addon feature.

Sorry, I'm not following you at all here. Where exactly does the value of last_timestamp come from? I thought it ultimately came from the phone and was the time the GPS data was read. Are you now saying it is effectively the last_updated field of the HA entity's state object? If it's the former, then great. If it's the latter, then that doesn't help at all. Hopefully, I'm just not understanding what you're trying to say here.

@gcobb321
Copy link

  1. The last_timestamp is the epoch/unix secs as we discussed. There is no change. Sorry for any confusion.
  2. iCloud use to support tracking friends that were sharing their location but not in the Family Sharing List. Examples are spouses or partners with their own account, close friends, relatives (mon/dad/?, etc). They provide this capability on the FindMy App that is used to track Family members, friends, devices and other items. In May, 2023, Apple removed the web URL that provided the friends location. Only devices and family members can be tracked now. The Mobile App could be used for that purpose but, if the friend does not have the Mobile App installed, which most won't because they probably do not have HA at their home, they are out of luck.

Google maps app might provide a data source for iPhone users not in the Family Sharing List and not using the Mobile App to be located again under the iCloud3 umbrella.

As an aside, I have users were mom and dad have iPhones but their kids do not. The kids have Samsung phones or other Android phones the Mobile App installed. They are being tracked using only the Mobile App as a data source without any problems.

@pnbruckner
Copy link
Owner

The last_timestamp is the epoch/unix secs as we discussed.

I wasn't questioning the format of the data, or how to interpret it, but the source of the data. When you said, "The last_timestamp is still the HA server timestamp", I wasn't sure if you meant the source of the data was now the state object's last_updated field, or if it was still ultimately the time the location data was read on the device. If the latter, then no problem.

Google maps app might provide a data source for iPhone users not in the Family Sharing List and not using the Mobile App to be located again under the iCloud3 umbrella.

That is already possible with the Google Maps integration. It allows one or more Google accounts to be registered. For each, it can show location data for the phone associated with that account, and it can show location data for any other Google accounts that have shared their location with the registered account.

So, I'm still not understanding what added value there would be for iCloud3 to use that data that is already available in HA (as device_tracker entities) when using the Google Maps integration. FWIW, it works with both Android and Apple devices.

@gcobb321
Copy link

  1. The HA no mobile app last_change/las_update State values are used for the Mobile App. The location_timestamp received from Apple with the gps info is used for iCloud data.
  2. The Google maps info would be used by people that can not be located because they are not in the iCloud Family Sharing list of the primary user and they do not have the HA mobile app installed on the phone. It would provide a third location data source. People that have the HA mobile app or are in the Family Sharing list would not be using it since it duplicates location data they are already using.

@pnbruckner
Copy link
Owner

Closing since there hasn't been an update in a couple of months. Not really sure what composite could/should do to consistently & robustly filter/reject large spikes in speed calculation. Feel free to reopen with new data/info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants