Google Maps Device Tracking Setup?

Thanks! Have you put in a PR to update this with Home Assistant?

For anyone else struggling with this – I forgot that if you don’t update requirements_all.txt and components/google_maps/manifest.json to use locationsharinglib==4.0.1 before you replace the cookie file – the old version of the library will overwrite your cookie file and you’ll have to do it again. That’s why I was still getting a InvalidUser error.

@dennyreiter’s custom component works well and survives container updates, but @costas is there a PR coming to include this in the regular Home Assistant code?

Please use version 4.0.2 since that has a fix for specific handsets that were breaking since they were missing info for battery status and percentage. I don’t have anything to do with @dennyreiter 's custom component and great work there! and as far as I understand he feels a bit daunted in making this an official PR for the main line. Anyone here that would be willing to help him moving this forward so everyone benefits?

@costas, is there a specific reason why we can not keep api the same between older (3.x) and newer (4.0.x) version of the locationsharinglib? as far as i can tell, i needed the custom gmaps component only because the new version wants two variables, something like (cookies, username) while older version was looking for three (username, password, cookies).

i know password is no longer required when we pre-make the cookies with mapcookiegetter, but wouldn’t it be easier to just keep the same API and ignore that “password” var? this way we won’t have to worry about modifying google_maps component, and no PR would be needed.

also under hassio, locationsharinglib does not upgrade automatically despite the requirements/manifest files. at least it didn’t work for me… it had to update it manually.

You would still need a PR to update the requirements to 4.0.2. I can put the PR in, but @costas is there still a need for v3 or should everyone move to v4? If v3 still works for some, can we update v4 to only attempt to login v3 style if a specific cookie file is not present or if a password is?

It’d also be nice if the mapscookiegetter could output the name of the file expected by locationsharinglib so the user doesn’t have to rename it, it’s just a drop in.

It would be great if you could put the PR in! We should drop v3 because although it does work for some people it is not clear who it works for so cannot really document it and it feels like a very nasty surprise when it does not work. I think that documenting the usage of the mapscookiegettercli project as a requirement on the PR would be a much better way forward.

PRs have been added:

2 Likes

You sir, rock!

Hi all. I have been leeching in the forum for a couple of weeks now and I have to say this is a very impressive community indeed. Thank you everyone who makes it possible for new people like myself to learn how to use the amazing Home Assistant and Appdaemon! My way of saying thanks is to post a little log for how I got Google Maps working. I am a complete noob when it comes to HA, Python and Linux so I have been banging my head against various walls lately.

Anyway, I wanted to use my family members’ location to do various automations in HA and Appdaemon so this is what I did:

  1. Get a good cookie for the Google account you want to use to follow the other Google Maps users. This was the difficult part which required a LOT of trial and error because I am all new to this.
  • I set up a new Google account for a ”fake” family member. Let’s call it for example [email protected]. This account needs to share location with all devices (family members) you wish to track.
  • Finding a way to extract the cookie using the maps-cookie-getter (below) was the biggest problem. I spent a long time trying to get this to work on a Raspberry Pi but there is no Chrome available and the Firefox-ESR didn’t work with maps-cookie-getter. I didn’t have any other Linux computer at hand and I didn’t even try to get it to work on Windows. I ended up installing a fresh Ubuntu desktop in my virtual environment. (I use VMWare vSphere and downloaded an ISO from https://ubuntu.com/download/desktop. I used 25G disk (lazy provision), 2GB RAM and 2 cores. When you tell vSphere to use the ISO as boot CD, don’t forget to check ”connect at power up”.)
  • When the Ubuntu machine is up and running make sure you have Python3 installed (which you probably already have). In a console window type ”python3 –version” to verify.
  • Install the wonderful ”mapscookiegettercli” package. In a console window type ”pip3 install mapscookiegettercli”.
  • In the console window navigate to ”/.local/bin” under your users home folder by typing ”cd /.local/bin”. This is a hidden folder so you may want to hit ctrl+h in the file browser if you want to see it (you don’t need to do that in the console window though).
  • Check that you have the file ”maps-cookie-getter” file by typing ”ls”. If you see it you are in the right place. Otherwise, if you are new to this like I am, you can type ”find / -name ’maps-cookie-getter’” in the console to locate it.
  • In the console write ”python3 maps-cookie-getter”. The magic should now happen and the Firefox browser should open up and you just log in with the ”[email protected]” account you created in the beginning. Once done Firefox will close.
  • Now get the file ”location_sharing.cookies” from the same folder where ”maps-cookie-getter” is located. This file needs to go to the Home Assistant machine, under the ”config” folder (where your ”configuration.yaml” is). Rename the file to ”.google_maps_location_sharing.cookies.jeeves_knows_gmail_com” (obviously replace ”jeeves_knows” with your own account name). There is no ”@” in the file name.
  1. In Home Assistant do this:
  • Adapt and add this to ”configuration.yaml”:
map: #This shows the map in the main menu in HA
device_tracker:
- platform: google_maps
  username: '[email protected]'
  password: 'YOUR PASSWORD'
zone:
- name: 'Sanders Bay'
  latitude: 36.322460
  longitude: -75.810741
  radius: 1000
  icon: mdi:suitcase
- name: 'School'
  latitude: 57.347743806844274
  longitude: 18.04327196432862
  radius: 250
  • Restart Home Assistant
  • Wait a couple of minutes. In a web browser, go to google and login with your email account you setup earlier and click on the ”Google Accounts” button and go to the security page and confirm that the unknown login that happened recently was by yourself.
  1. You should now be able to see your devices in the map in Home Assistant (in the main menu). You should also find your tracked devices in the ”States” view, named ”device_tracker.google_maps_NUMBER”. Voila – you are done! Next step is to create automations based on the new device trackers.

I considered using various Chrome plugins to extract the cookie but since I didn’t know what the cookie file should look like it was impossible to find a solution. I also considered inline proxies like Fiddler and Charles but failed for the same reason. I also wrote a Windows application that downloads the data from Google from another machine but found it difficult to ”force feed” that into Home Assistant without causing a lot of extra issues.

Thank you @costas for creating the mapscookiegettercli!

4 Likes

You are welcome! One small correction, you shouldn’t have to call the tool with python, nor to be in the bin directory. That directory is part of your path and calling “maps-cookie-getter” from anywhere in your system should work just fine. Also as you read above @shbatm made a PR that bumps the dependency library in the component so pretty soon, when it is out, you should not specify “password” in your configuration. Great write up, thanks!

For some reason I wasn’t able to call maps-cookie-getter without python or without being in the bin directory. There is probaby something wrong with my path but not sure what it could be since I just installed the machine. This is what it looks like:

claes@ClaesUbuntu:/$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Shouldn’t there be a mention of “/.local” in the path somewhere?

Yeah, ~/.local/bin should be there. It’s fine since you got it working :slight_smile:

@costas the cookie files lasted exactly 14 days and expired. Today it stopped working after 14 days. Any work around for this ?

I am sorry, but no. Apparently it is location specific since I am still using a cookie I have setup like almost a year ago. Maybe while logging in there is an option to “stay logged in” that you are overseeing? I think that google presents such an option. Just logged in and sadly there is no such option. The only work around would be a selenium/mechanize based solution that would detect the expiration and try to automatically re authenticate, which would bring us again to square one for 2fa and captcha based interactions and of course would again be extremely locale specific. Short answer :poop:

That is weird though, because I think that for personal accounts google sessions do not expire. That’s how you are always automagically logged in and they track everything you do. Which browser did you make the cookie with and does your account have anything special? Maybe it is worth checking out your security settings?

Could it be that the account you are using to share is a gsuit managed account? Those do have a default expiry setting of 14 days.

It is gsuit account. I cant find anywhere hv default 14 days expiry. Probably I would need to change this to Gmail I believe. Thanks for the reply. I will dump another Gmail cookies and wait another 14 days.

https://support.google.com/a/answer/7576830?hl=en

Kinda clear. Make a simple gmail account and use that.

Thanks, I moved to Google account… hopefully this is 1 off job this time :D. Can we put a note for 14 days expirygsuite account on the google location page ?

1 Like

Please edit the page the way you see fit and make an MR to the developers.