Google maps location sharing problems

For last 6-8 months onwards, google map location sharing has started to not updating the location randomly (at least it seems random).
I would copy the cookies and it would work for some time and then it would stop working again.
It has persisted through multiple different version of Haas. I am currently on

Home Assistant 2023.7.3
Frontend 20230705.1 - latest

I see in my logs that sometimes it throws the error

[homeassistant.components.google_maps.device_tracker] The cookie file provided does not provide a valid session. Please create another one and try again

But I cookie file was valid when I put fresh cookies and Haas was able to get location too at that time. It would just stop working randomly after some time. Not sure what could be wrong or what I can do to keep it working. It worked for more than year first time I enabled google maps but last 6-8 months it has been very unreliable and cause my location based automations to fail (including in home/out home detection)

Same here. Iā€™ve been trying to debug it using the python lib that HA uses. It appears the cookie file is read once, at HA start time. So if you are seeing that error you probably restarted HA with an invalid cookie file. You donā€™t see it until you restart

Iā€™ve also discovered you only need 3 cookies for it to work :

__Secure-1PSID	
__Secure-3PSID	
__Secure-1PSIDTS

Itā€™s the last one Iā€™ve found to be problematic. If you open a maps browser window, hit F12 to examine the cookies and refresh after about 20mins, that cookie will have changed (and the HA location tracking will then stop) I found the same when testing the python lib in a loop, after about 20mins that cookie is no longer accepted.

I spoke to the python lib dev on github who recommended creating a new google account, get your family to share location with that account and use that accounts cookie. But Iā€™ve not got around to trying that out.

Thatā€™s all I have :slight_smile:

2 Likes

FWIW, still working fine for me (through a ā€œdummyā€ account).
I actually never update the cookie file, and wonder how it still works :wink:

i read that cookies change value often. I am wondering if locationsharing lib (i assume thatā€™s the one handling this) can store value of new cookies when refreshed. not sure how creating a new account will help with this ?

just curious, do you log into your dummy account from browser or use that account ? I am wondering if using google for any other purpose (outside maps) may be updating the cookies. In that case we will need to create a throwaway account fully isolated (and un-used otherwise) for it to work consistently.

can you share which github repo/developer account is used for this feature ? Maybe it will be help to have an official answer/workaround for this to work consistently.

No, not at all. That account is used only as a ā€œrecipientā€ for the locations of the different people, and I never log in nor use it for any other purpose.

@carefulcomputer GitHub - costastf/locationsharinglib: A library to retrieve coordinates from an google account that has been shared locations of other accounts.
@koying I think yours will stop working eventually, there is a 12 month expiration on the cookie (its in clock ticks since epoch)

1 Like

if it works, i would be okay updating cookies once a year. so here is what i did, i installed a browser extension called ā€˜editthiscookieā€™.

  1. I logged into common google account
  2. Exported the cookies
  3. Used extension editthiscookie to delete all the cookies for google.

I am hoping this will make sure that cookies do not get updated but are still valid. So far (in about 16 hours) location tracking seems to be working okay. Will update how it goes over next few days.

nice work, thanks. I did the same and noticed this time that I donā€™t get a __Secure-1PSIDTS (which was the problematic one) Iā€™ve restarted my test code and Iā€™ll know in 20mins if this fixed it.

Interestingly, the python lib only mandates :

VALID_COOKIE_NAMES = {'__Secure-1PSID', '__Secure-3PSID'}

Edit : @koying could you check if your cookie file contains __Secure-1PSIDTS ? Thanks.

if the lib only loads these two cookies, then wouldnā€™t other cookies (including __Secure-1PSIDTS) in file be immaterial ?

No, it checks those two are present (and errors if they are not) but uses the whole file.

makes sense. I am wondering if the lib could update the file with new cookies in file when it receives them as part of response.

I have both.
If the timestamp is to be believed, the cookies will expire May 10th, 2024.

@koying You say you have __Secure-1PSID', '__Secure-3PSID ? But do you also have __Secure-1PSIDTS ? (That seems to be the problematic one)

Ah, no, I donā€™t have that one.

Good stuff. Thanks

@carefulcomputer do you happen to have an old cookies file (where it stopped working) ? If so, check for __Secure-1PSIDTS - if its there I think itā€™s a reasonable workaround to proactively removed it when the cookies are extracted.

unfortunately I didnā€™t save old file. my current cookies file with __Secure-1PSIDTS is still holding fine for more than a day. BTW in my file I see that __Secure-1PSIDTS and __Secure-3PSIDTS both have exact same value.

in my cookie file I see my cookies expire in feb,24 (generated in aug few days back). So doesnā€™t seem like a full year.

So it sounds like the solution is to remove the problematic cookie entry?

Seems like we want to delete all cookies EXCEPT for __Secure-1PSID and __Secure-3PSID from the cookies file?

Historically I just dump the cookies and copy the file into the hass directory but the last few weeks this only works for ~1 day then it stops working.

I will try this suggested method.