Google Maps location sharing

Could the new Google Maps location sharing feature be used for presence detection?
It looks a lot like the old Google Latitude.

Good thinking!

It would probably need google authentication in same way that gcal does:

If the person you’re sharing with is not in your Google contacts, you can also copy and paste a link and share it to them via text or email. However, these links are restricted to time-based location-sharing for safety reasons; the links will expire once the time is up.

I already have the component for it:

Here is the documentation:

I have been using it since ~November 2016.
(I had submitted a PR but it went nowhere: https://github.com/home-assistant/home-assistant/pull/4870)

4 Likes

Does this still work now that they’ve pulled location out of Google Plus?

Self Mode works!

Location cards still show up in Google Plus. The only thing that changed is that now the location sharing needs to be set up in the google maps app on Android instead of the google plus app. Safe mode works for me.

2 Likes

Yeah, that makes sense. I asked before I actually looked at how you had written it. Nice job, by the way. Would love to see this officially supported. I went with Self Mode to start but I think I will switch to Safe once I can get a dummy account created.

I’m having a little bit of trouble setting this up. I think my url field is wrong. Home-Assistant throws the following error

17-04-18 21:59:30 ERROR (Thread-5) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
File “/usr/local/lib/python3.5/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/device_tracker/gplus.py”, line 95, in get_position
update_data_at()
File “/config/custom_components/device_tracker/gplus.py”, line 90, in update_data_at
data[‘at’] = sdict[‘SNlM0e’]
KeyError: ‘SNlM0e’
17-04-18 22:01:30 ERROR (Thread-5) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
File “/usr/local/lib/python3.5/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/device_tracker/gplus.py”, line 95, in get_position
update_data_at()
File “/config/custom_components/device_tracker/gplus.py”, line 90, in update_data_at
data[‘at’] = sdict[‘SNlM0e’]
KeyError: ‘SNlM0e’

Facing same issue. How did you resolved it

I resolved it by trying everything that i could think of, and there was a lot wrong with my config.
For example: I thought “data_freq” was a time-span to refresh the data, but in fact it is another value from “data?ds.extension”. I am running it in Self-mode now, I wil try Safe-mode later.

> headers = {
>     'origin': 'https://aboutme.google.com',
>     'x-same-domain': '1',
>     'dnt': '1',
>     'accept-encoding': 'gzip, deflate, br',
>     'accept-language': 'nl,en-US;q=0.8,en;q=0.6,fr;q=0.4',
>     'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.138 Safari/537.36 Viv/1.8.770.54',
>     'content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
>     'accept': '*/*',
>     'referer': 'https://aboutme.google.com/',
>     'authority': 'aboutme.google.com',
>     'cookie': 'CONSENT='VALUE'; S='VALUE2'; GMAIL_RTT='VALUE3'; OTZ='VALUE4'; SID='SID-VALUE'; HSID='HSID-VALUE'; SSID='SSID-VALUE'; APISID='VALUE4'; SAPISID='VALUE5'; NID='VALUE6',
> }

> params = (
>     ('ds.extension', '*****'),
>     ('f.sid', '*****'),
>     ('hl', 'nl'),
>     ('soc-app', '***'),
>     ('soc-platform', '*'),
>     ('soc-device', '*'),
>     ('_reqid', '******'),
>     ('rt', 'c'),
> )

> data = [
>   ('f.req', 'A long string of random characters and nulls, lets call this FREQ-VALUE'),
>   ('at', '***'),
>   ('', ''),
> ]

> requests.post('https://aboutme.google.com/_/ProfilesMeUi/data', headers=headers, params=params, data=data)

> #NB. Original query string below. It seems impossible to parse and
> #reproduce query strings 100% accurately so the one below is given
> #in case the reproduced version is not "correct".
> # requests.post('URL-VALUE', headers=headers, data=data)

This is what “data?ds.extension” (“*” is to censor some stuff away) returns, and you need the following values in your configuration.yaml. I put everything between single quotes in my yaml-file and it works that way.

device_tracker 1:

  • platform: gplus
    id: emiel_android
    url: ‘URL-VALUE’
    cookie_sid: ‘SID-VALUE’
    cookie_hsid: ‘HSID-VALUE’
    cookie_ssid: ‘SSID-VALUE’
    data_freq: ‘FREQ_VALUE’
    home_url: ‘https://aboutme.google.com

Thanks for detailed explanation. It’s working for me too. I had problem with home_url parameter.

@aa755 if I want to reduce the interval so I get more real time updates is it just a case of adding this to the config:
interval: 1

Is there any downsides to doing this?

Looking at the code, I think adding interval:1 should work, but I haven’t tested the interval field in the config.
Can you let us know if that worked?

The only downside I see is that there is a chance that Google may ban your IP for sending too many requests. I have no idea how realistic that chance is.

actually from looking at the source code it takes the interval field and doesnt do anything with it. However it does look like it uses the scan_interval field so i passed that it in my config
scan_interval: !!int 1

however it doesnt look like it has any affect :confused:

Hi, i must to put gplus.py in cusom_components ? if not how i must to use it?
thanks

ok, i’ve found the components folder in Python35\Lib\site-packages\homeassistant\components
(i’m a Windows user) and i putted gplus.py in device_tracker folder.
I’ve modified configuration.yalm to include gplus tracker but when i’m running hass i’m getting this log
“ERROR (MainThread) [homeassistant.loader] Error loading homeassistant.components.device_tracker.gplus. Make sure all dependencies are installed”

Also have the same error as virualdo, logs show an error with BeautifulSoup. Any ideas?

  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/gplus.py", line 9, in <module>
    from bs4 import BeautifulSoup
ImportError: No module named 'bs4'
2017-06-11 08:55:56 ERROR (MainThread) [homeassistant.loader] Unable to find component device_tracker.gplus
2017-06-11 08:55:56 ERROR (MainThread) [homeassistant.loader] Error loading homeassistant.components.device_tracker.gplus. Make sure all dependencies are installed

I am going to backup and try this fix, will let you know how I go virualdo:

Well that fixed things, not sure how you would do that on windows sorry virualdo.

New problem is no response received:

2017-06-11 09:30:00 ERROR (Thread-1) [homeassistant.components.device_tracker.gplus] No response received to the location query
2017-06-11 09:30:00 ERROR (Thread-1) [homeassistant.components.device_tracker.gplus] Google didn't send the location. Updating data['at']

All problems fixed. Needed all config entries in single quotes as stated above.