Enhanced Google Maps Integration

The built-in Google Maps integration could use some :heart: so I’ve created a custom version to test out some changes I’ve been wanting to make. You can find it here:

pnbruckner/ha-google-maps: Custom Home Assistant Google Maps Integration (github.com)

This is still considered beta quality. I hope to release a 1.0.0 version soon.
Version 1.0.0 has been released! :tada:

Follow the link :arrow_up: to see documentation about how it differs from the built-in integration, how to install it, etc.

Since there are only beta releases available so far, for some reason, HACS does not show tags and release notes, so I’ll provide them in this topic until I release 1.0.0. HACS only shows “commit hashes”, so I’ll list the corresponding hash for each release below as well.

Beta Releases

1.0.0b0 (0a0f235)

  • Initial implementation

1.0.0b1 (dd7d9a0)

  • Add options flow (i.e., CONFIGURE button on Integrations page.)
  • Add or remove device_tracker entity for account based on config option.
  • Fix bug in last_seen parsing on restore due to using an unreleased core feature.

1.0.0b2 (727142e)

  • Add reauthorization flow to handle expired cookies. Currently only notices expired cookies at startup or config reload.
  • Read expiration timestamps of cookies.
  • Show expirations in flows.
  • Create a repair issue for config entries whose cookies expire in the next 4 weeks.

1.0.0b3 (4b21442)

  • Catch requests package exceptions.
  • Check for cookie expiration after each request.
  • Use extra_restore_state_data.
  • Restore state before processing new location data.
  • Use new, inaccurate location data if no previous data or previous data is less accurate.
  • In config flow use link to documentation from manifest.json, which now includes branch/tag.
  • In config flow improve description of “account entity”.
  • Update README.md & info.md.

1.0.0b4 (6d22952)

  • Add detailed, browser specific procedures for getting a cookies file to the config flows.
  • Add the same to the documentation.
  • In the docs, explain how to add Google accounts.

1.0.0b5 (040ecd3)

Previously it only checked to see if the cookies will expire “soon” at startup or when a config entry is reloaded, and if so, it created a repair issue at that time. Now it will also create a repair issue while HA is running when the expiration date is approaching “soon”.

1.0.0b6 (3ac5857)

  • Modified to be compatible with HA version 2023.7.0 or newer.
  • Improve documentation.
    • Add Missing Data for Account Tracker section.
    • Improve Account Strategies section.

If you use it, PLEASE let me know, but more importantly, please provide feedback, good or bad.

11 Likes

The current documentation covers installing the custom integration and the various configuration options, but lacks details about how to add a Goole account for it to use. This is done like any other integration; i.e., go to the Integrations page, click the “+ ADD INTEGRATION” button, click on “Google Maps” in the list, then follow the prompts to configure it.

I’ll add these details to the documentation, but for now, you can click:

Or go to Settings → Devices & Services, click the “+ ADD INTEGRATION” button, find “Google Maps” in the list and click on it.

If you see “Google” in the list, DO NOT click it. That will provide another list of all Google related integrations, and will also contain a “Google Maps” option. But that is for the built-in integration, not the custom one.

UPDATE: The documentation has been updated to add all these details.

1 Like

Sorry, not really familiar with the old integration…

So I can create an HA Gmail account, and then my family can share their location with that account? This sounds exciting! I assume this may be more accurate than the Android companion, or should it be used along side it?

I’ve been using it helping to test the beta’s and it works great.

it still suffers from some of the limitations of the original integration like needing to go thru the (fraught…) process of getting a cookies file and the sporadic location update frequency from the Google Maps app itself but there are definite improvements that make it worthwhile to use this integration instead of the built-in one.

And I’m sure there will be more great improvements to come! :+1:

1 Like

unfortunately in my experience it’s not. I’ve been tracking it and due to the delays in location updates it can be up to over a mile different at times.

but YMMV.

that’s the way I use it.

A big, public THANK YOU for helping with the early releases!

It’s still not clear to me if the location fixes from Google Maps are wrong or less accurate, or if they just update less often, or have more delay getting to HA, than those other trackers.

In my experience, the updates from Google Maps happen more frequently when the device is moving than when it’s not, just like what happened with Life360. Here is some data to show what I mean:

This happens to be for an iPhone. In my experience, Android phones are better.

Anyway, the first graph shows the “age” of the data – i.e., how long it has been since it last updated. Therefore, it is a “saw tooth” pattern. It increases until an update comes, and then it drops.

The second graph is the “speed” of the device (as determined by my composite integration.)

You can clearly see that when the device is moving the updates come much more frequently (every 5 to 10 seconds) than when it is stationary.

BTW, the updates will also be affected by the configured update period of the integration. The default is every 60 seconds, but you can make it much shorter if you want.

Check out the documentation. There is a section that discusses various account strategies and their advantages & disadvantages.

If you already have a Google account that people you want to track have already shared their location with, then you don’t necessarily have to create another Google account just for HA. But, like I said, the doc goes into more detail.

If you are also using other tracker integrations, or plan to, then yes, you can combine multiple trackers for a given person. There are generally two ways to do that. The first is the built-in Person integration. The second is my custom Composite integration. Of course, I’m partial to the latter :rofl: , but either will do the basic job. One thing people often do is use my Composite integration to combine trackers (and possibly other entities), and then use that as the one “input” to the Person integration. Then you get the best of both worlds!

2 Likes

It might be clearer if you gave a more personal name to your integration.

are you using the last_updated attribute in that location age sensor or the last_seen attribute?

Right now there is an 11 minute difference between those two times (last updated is more recent)

I’m going to re-create your charts to see if my results correspond to yours and I want to make sure I’m using the same data. In fact I think I may just create sensors from both attributes either way. More dara can’t hurt.

And TBH, I’m not even sure what the location update is based on - last updated or last seen.

I had intended for this custom integration to effectively take the place of the built-in integration (while installed.) I had done the same thing with the Life360 integration. However, after I set all the wheels in motion, I discovered that somehow all the Google related integrations are grouped in the ADD INTEGRATION menu, which surprised me. Unfortunately, it’s a bit late to change the name of the custom integration.

If one uses the “My” button I provided above and now in the docs, then this isn’t even an issue, since that takes you right to the correct item. But, for those that take the manual route, I figured I needed to at least warn them, so they don’t accidentally pick the wrong item and get confused. (The one for the built-in integration doesn’t do anything, anyway, besides stating it doesn’t support UI-based configuration.)

1 Like

IMHO, last_updated is almost useless for trackers, especially when trying to combine them and use the latest & greatest data at all times, which my composite integration tries to do.

So, my location age template sensors are based on last_seen, not last_updated.

Specifically, here are the template sensor options, including template:

"template_type": "sensor",
"name": "Name location age",
"state": "{{ (now() - state_attr('device_tracker.name', 'last_seen')).total_seconds() / 60 }}",
"unit_of_measurement": "min",
"device_class": "duration",
"state_class": "measurement"

Well, that’s not completely unexpected. As my graphs above show, it’s not uncommon for the age to go up to about 10 minutes or so while the device isn’t moving.

Remember, last_updated will change when anything in the entity’s state changes. For these entities that could be battery level, etc., not just location-specific attributes. Another reason why last_updated isn’t very helpful when trying to understand how long it has been since the location fix has changed.

1 Like

That’s what I figured. Just wanted to be sure.

I set mine to show seconds instead of minutes tho in hopes that resolution might be needed.

@pnbruckner , first let me say that your dedicated work is so very appreciated. I moved over to the official Maps integration after the disappointing Life360 collapse and have been extremely pleased with the results. I was scrambling in search of a replacement so that way I wouldn’t have to rethink and/or rewrite my presence detection.

As of 1 hour ago, I have swapped over to your version and look forward to not having concerns about device tracking/presence or worrying whether or not my door will unlock when my wife or I get home. I can have confidence that my automations will just work. My entire smart home and all of the scripts/automations in one way or another rely on rock-solid presence detection and your work has played an overwhelmingly large role and just wanted to say Thank You again for that.

Chris

2 Likes

Released 1.0.0b4 (6d22952)

  • Add detailed, browser specific procedures for getting a cookies file to the config flows.
  • Add the same to the documentation.
  • In the docs, explain how to add Google accounts.
1 Like

Released 1.0.0b5 (040ecd3)

Previously it only checked to see if the cookies will expire “soon” at startup or when a config entry is reloaded, and if so, it created a repair issue at that time. Now it will also create a repair issue while HA is running when the expiration date is approaching “soon”.

4 Likes

Released 1.0.0b6 (3ac5857)

  • Modified to be compatible with HA version 2023.7.0 or newer.
  • Improve documentation.
    • Add Missing Data for Account Tracker section.
    • Improve Account Strategies section.

Released 1.0.0

First full release.

4 Likes

Phil, this is really nice work. I found it very straightforward to follow the instructions.

One small suggestion for the documentation would be to make it a little clearer that if you choose the 2 account strategy (Pers & Alt account) that the way to execute that is to collect a cookies file for each of those accounts and add the integration twice (or “add entry” within the integration) to upload both cookies files. It took me a minute to realize I just had to add them both separately to get all the shared locations into HA.

Thanks!

I thought the documentation was already pretty clear on that point. Maybe you could submit a PR with a wording suggestion you think would work better. I’m not an English teacher, so I’m not surprised that the wording could be improved! :rofl:

Maybe you could submit a PR with a wording suggestion

Done. I don’t know if I did it right, have never done a PR. Feel free to change or reject it as needed, it won’t hurt my feelings!

1 Like

Hi all! Just wondering how many have tried this out, and more importantly, how it is working for everyone. If you haven’t done so yet, could you please give me some feedback, good or bad? Thanks!