Google Maps location sharing

Deleted it, then deleted pycache too for a fresh start.

Now I get this error:
Could not open pickle file, either file does not exist or no read access.
12:59 custom_components/device_tracker/google_maps.py (ERROR)

The file is there, everyone has the right to read/write/execute also I did the same for folder. It says it can’t find it, but it makes a new pycache folder inside it.

edit.:
Google blocked the authentication, then I allowed it manually (now it says it will show it for 2 weeks for my safety), how can I see what is going on?

edit2.:
Old account still can login and can make new cookie file. How can I prevent google blocking my attempt to log in?

edit3.:
Tried to log in with a 3rd account, It does not login there too same error. I can only login with the absolute first account.

Erorr:
Error setting up platform google_maps

Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/init.py”, line 169, in async_setup_platform
disc_info)
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/homeassistant/.homeassistant/custom_components/device_tracker/google_maps.py”, line 33, in setup_scanner
scanner = GoogleMapsScanner(hass, config, see)
File “/home/homeassistant/.homeassistant/custom_components/device_tracker/google_maps.py”, line 52, in init
hass.config.path(CREDENTIALS_FILE))
File “/srv/homeassistant/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py”, line 179, in init
if cookies_file and self._validate_cookie(cookies_file):
File “/srv/homeassistant/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py”, line 204, in _validate_cookie
raise InvalidCookies(message)
locationsharinglib.locationsharinglibexceptions.InvalidCookies: The cookies provided do not provide a valid session.Please authenticate normally and save a valid session again

Connection lost. Reconnecting…

This idea is amazing, but needs a lot of work before it gets to branch. Or at least tons of information about how it works, because in the current state it is not useful, it is not user friendly. And it is not working, because gmail thinks it is a security breach and blocks the login.

Edit.
With the testing, I finally banned my 1st account too. How can I lift the bann from gmail, and allowing to do whatever I want with my account? :\

Sadly that is google security and there are not many ways around it. One thing you can do to have things working easily from the first time is:

Login to the tracking account through your working computer through a browser and go through the security of google the way you would for anything else. Once that is done and you have logged in your account and the machine is known to google then install the locationsharinglib in a virtualenv on your workstation and connect to your tracking account through that.

Details are http://locationsharinglib.readthedocs.io/en/latest/installation.html

Then through your python console use it:

from locationsharinglib import Service
service = Service(username, password, ‘google_maps_location_sharing.conf’)

once you do that you should have a google_maps_location_sharing.conf file created with the connection cookies. You can move that file to your HA instalation under the config directory and it will happily think that it is your workstation that is connected. Sadly not much can be done since google uses some pretty nifty tricks to keep your account safe.

3 Likes

@costas I just wanted to say that this is working awesome for me. I had in on my rPi3/Hassio set up and migrated it over to my newly setup PC/Docker machine. I love it, it may replace my gpsLogger config altogether.

I’m not familiar with Python. Installed locationsharinglib, and i’m in the python console, but when I try to do what I think I should:
copy paste these:
from locationsharinglib import Service
service = Service(username, password, ‘google_maps_location_sharing.conf’)

I get syntax error

Well, you need to use your username and password .try typing it line by line and in the place of username put in quotes your username and in the place of your password in quotes your password.

If you get an error please paste it here taking care not to reveal your password of course

Syntax for @ in username, also for ’ in the file name.

service = Service(dummy, pass, ‘google_maps_location_sharing.conf’)
File “”, line 1
service = Service(dummy, pass, ‘google_maps_location_sharing.conf’)
^
SyntaxError: invalid syntax

5429

test2
5430

No solution? :\

Please paste in a python terminal the following changing the appropriate values for your gmail username and password. Keep in mind the double quotes.
username=“your_gmail_username_here”
password=“your_gmail_password_here”
from locationsharinglib import Service
service=Service(username, password, “google_maps_location_sharing.conf”)

after that you should have a google_maps_location_sharing.conf file in the location you stated the python interpreter from which you can transfer to your HA installation.

1 Like

actually don’t copy paste because the quote characters are not the correct double quote ones. Please type the above and use the standard double quote character.

Done and done, finally after 10+ hours, it seems to be working properly. I can’t see them on MAP, but at least I can see in the main tab. Name+Picture+coordinates looks nice :slight_smile:
Thank you!

Edit
" Devices that are currently at home won’t show on the map. "
So I guess this is why it doesnt show up on map :slight_smile:

The documentation needs improved a lot. blurred out screenshots of exactly how we’re supposed to pick apart that python request would be very helpful. Could you please make it a little easier to understand exactly which strings and in what format they’re getting copied for people who aren’t familiar with python requests? The data_freq bit specifically is very unclear.

Hi all, I was little bit struggling to get this working, because my Ubuntu server is using a VPN. But after some reading I got it working.

This is what I did to make it work: (reuse from some other posts, credits to them!)

First create a account or a think of account that you want to use to share your location with.

Under your config directory in your home assistant installation create the following structure:
custom_components/device_tracker/
and download this file:
https://raw.githubusercontent.com/home-assistant/home-assistant/c360466817776b2c2c858e3b98a894685d73b8bc/homeassistant/components/device_tracker/google_maps.py18 in there.
Then in your configuration.yaml create the following entry as mentioned in the documentation.

device_tracker:
platform: google_maps
username: [email protected]
password: password

Then create a google_maps_location_sharing.conf config file in your config folder of homeassistant. Start a python terminal. Install locationsharinglib if you don’t have it. Using pip install locationsharinglib. Then type this in the python terminal.
username=“your_gmail_username_here”
password=“your_gmail_password_here”
from locationsharinglib import Service
service=Service(username, password, “google_maps_location_sharing.conf”)

For me the above steps where tricky because of the google security. I needed to install a browser on my Ubuntu server and expose the X11 window to my Windows machine. Then login in gmail. When that was done I could successfully create a google_maps_location_sharing.conf

Hope it can help others to make it work.

1 Like

The easiest way to get the connection cookies is to use your own workstation. You need to connect to the newly created account through your browser and resolve the google challenges provided. Once that is done (quite easy, you need to do the same thing for any connection from a new device) then you can install and use locationsharinglib to get the google_maps_location_sharing.conf. Since the device is already known to google you will probably get no more challenges. Once the connection is established and the file with the cookies is created, you can move that file to your HA deployment which will happily use it thinking that it is your workstation connecting.

Amazing job, thanks!
Did you faced the case when a device flips ‘in and out’ the home?
Happened to me with two different phones, with a 200 meters errors or so, no idea if google maps or the GPS reports them outside home.
Thanks a lot again.

Yeah, has happened to me too, trying to figure out why.

No idea on my end, but I don’t think that the problem is phone related but service related. I’ll check using a more precise coordinates for the zoning.

My case too

How do I get the locationsharinglib if I’m on Hassio?

2018-02-28 22:23:03 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform google_maps
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/__init__.py", line 169, in async_setup_platform
    disc_info)
  File "/usr/lib/python3.6/asyncio/futures.py", line 332, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
    future.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/device_tracker/google_maps.py", line 33, in setup_scanner
    scanner = GoogleMapsScanner(hass, config, see)
  File "/config/custom_components/device_tracker/google_maps.py", line 42, in __init__
    from locationsharinglib import Service
ModuleNotFoundError: No module named 'locationsharinglib'