Google Maps location sharing - New thread

if anyone is interested in trying an alternative, i’ve rebuilt the underlying library from the ground up.

instead of requests, this is based on using selenium and chromedriver to basically drive a headless chrome session. this method is designed specifically for 2FA via device authentication (as any other form of 2FA would probably cause timeouts). on first run, it should ping your device for approval and that should be the end of it.

i’ve got a lot of debugging built in where it’ll dump either raw output or screenshots of the login process along with URLs to files if there are issues, so it should make troubleshooting considerably easier. i’ve also added debug and localization components which can be passed to the component from config.yaml.

if you’re not in the US, hit me up and i can work with you to add localization to the custom component configuration as necessary. i’m sure the URLs are different depending on what server you’re hitting, so while the config allows for localization, it’s not currently populated past US.

at the moment it works with either straight linux installs (pip to system) or docker. there’s setup scripts for ubuntu and centos. i’ve also got a script on how to get this going with docker which generates a Dockerfile and docker-compose.yaml example, builds the Dockerfile, which is basically just vanilla HA with google-chrome-stable slapped on, builds the custom image with label and tags, sets permissions on the HA volume, blah blah blah…

master branch is linux
docker branch is…cupcakes.

if there’s interest, i might actually put this together into a package…somehow…

anyway. here you go.

1 Like

Where is the docker script? Willing to give it a go

setup.sh under docker branch.

Look through the script and make sure you reflect your environment as necessary in terms of paths, variables, dependencies, etc.

For some reason, it started working all of a sudden. I’m very sure I didn’t change anything.
@shr00mie: when it breaks, your library is the obvious next choice!

Ironic.

Been working fine for me for the past year or so.

Upgraded to 90.2 and it stopped working. Deleted the cookie file, to discover I probably should have kept it as a backup. sigh.

If anyone’s curious, here’s what I’ve done in the absence of google maps location tracking:

How can I share google location with my dummy account?? It only lets me to share for 3 days (not until I stop it).

P.S: Is it working for hassio now?

My understanding is that the failure of Google Maps’ location sharing is not on the Home Assistant end, but rather how Google is authenticating their data (see post #159).
It still doesn’t work for me, running Hassio on RPi3.
However, within the Google Maps app there is a location sharing choice on the menu for you to add a user to share with.

the required prep for this component is to share your location with a centralized account. then you’re providing the login and pass for the account you’re sharing location data WITH to this component to pull said data.

regardless, the issues plaguing this component have nothing to do with google. there’s a ton of edge cases which are not accounted for and cause the existing implementation to error.

i’ve covered all the edge cases we’ve seen thus far plus threw in a fuckload of debugging for easier troubleshooting for anything that might crop up in the future.

come to the dark side…

2 Likes

Any plans to support Hass.io?

1 Like

Hi all, I ended up to this thread searching info on why google maps device tracker doesn’t retrieve anymore battery info, so it’s a problem? I recently changed the phone and used same google account, in Hassio google maps device tracker there isn’t battery info such as level or state of charge, so for the moment they don’t work?
I already removed account and stopped location sharing on the old device, deleted entries in knowndevices.yaml (the new phone is present, so it must works), deleted google maps cookies and restart hassio.

Edit
I have done redoing all steps in the new phone, but a friend told me that the second account (or maybe the first) must not be used for anything, even not added to phone’s account, is it right?

Strange: I do get battery levels and state in hassio for both my connected phones.

Do have to admit that the location sharing plugin is a bit of a hit and miss when upgrading or rebooting; sometimes I need to clear the cookie and sometimes it simply continues to work…

Any hint is highly appreciated.

I have two Samsung phones running Android ≥ 9.0 which are tuned to share the location with Google account. Everything worked fine until some time ago (probably until HomeAssistant update), then suddenly both phones stopped reporting the status to HomeAssistant.
First I tried remove/reexport the cookies for the account (file location .homeassistant/.google_maps_location_sharing.cookies.*) but that didn’t help at all.
Then I have removed .homeassistant/known_devices.yaml and one of two phones started to report to HomeAssistant.
Then I have stopped location sharing on the “faulty” phone and re-enabled it again. It didn’t help. So I have one phone which is still not “working” properly.
When I check the phone on the Google Maps of the given Google account then the location is displayed just fine.

What else can I try to make it working?

Thanks in advance!

P.S. HomeAssistant v2021.1.5, locationsharinglib v4.1.0.
Logs (just few records like that):

WARNING (SyncWorker_55) [locationsharinglib.Service] Received response code:500

Stopped working for me as well. Tried to re export the cookie but it hasn’t helped

Actually re-exporting cookies finally worked. I would suggest to use Firefox + plugin as something went wrong with Chrome + plugin (either cookies from several accounts were mixed or…)

I have found this out by looking at the following logs:

DEBUG [locationsharinglib.Service] Getting personal account page and its cookies...
...<div>Google Account</div><div class="gb_nb">Wrong User</div><div>[email protected]</div>...

Actually I have come up with the following minimum list of required cookies (in case someone is interested in a shortened version of cookie file):

.google.com TRUE / FALSE 1675944824 APISID ...
.google.com TRUE / FALSE 1675944824 HSID ...
.google.com TRUE / FALSE 1623866185 OGPC ...
.google.com TRUE / FALSE 1675944824 SID ...
.google.com TRUE / TRUE 1675944824 SSID ...
myaccount.google.com FALSE / TRUE 1675944824 OSID ...
2 Likes

Does it work now for you?

The cookie which was working started to spill out a log as:
“The cookie file provided does not provide a valid session. Please create another one and try again”
So the reason I am starting over with a new cookie, but doesn’t work at all now whatever I do.
No log shown in HA.
Tried with cookies exported with both Firefox and Chrome and no avail.

Cookie with Firefox, the OSID line doesn’t exist.
Chrome does have every line, but doesn’t work.

I checked if I am using the wrong google account, but that is correctly selected.

Yes, it works. I have dumped the cookie in April 2021 and everything works till now (January 2022).

Maybe you have access permission issue for the cookie file and it just cannot be read?

@dma_k
Thank you for replying. Okay, I will continue to check my setup then.

Solved.
I logged out all google accounts and logged in again, exported the cookie with Firefox.
Then the OSID line appeared in the cookie.

@dma_k Thanks for showing us the minimum list of required cookies.
That really helped.

I am starting to get, “Map error: g.co/staticmaperror” on the google map card.
Anybody here have it working now?

[Update] Solved again by turning off location sharing and on in the google account that I want to track.
With this, device_tracker started to track coordinates in device_tracker.google_maps_AAAAAAAAAAA.
Before that, there were no attributes in the device.