Google maps. Share the location with the smart home.

Igor Mullin
5 min readSep 18, 2021

--

When we leave the house, we usually have our phone with us. Let’s start making “autorun” for home. Only we will manage the heating or air conditioning not by remote control, but by our location.

This is a translation of my article in Zen. Also, do not forget to read us in other services: Instagram, telegram (RU, EN, DE). Medium, LiveJournal, YouTube.

A couple of months ago, I described automation (RU), the trigger of which was visiting a room. Let’s expand the boundaries of our smart home, let it see us on the way to the house. We will also do reverse automation.

To begin with, we will send notifications to telegram. For those who missed the topic — a link to the last article (RU) on the topic. If more is needed, there are links in the publication.

The basic instructions are already available on the Home Assistant website (RU), but from the reviews of people on the sites, you can find out that it does not work for everyone. I also earned it not as in the instructions, but not worse…

Let’s start with the description. We will need a google account with which the geo position is shared. There is a nuance here, if we only have our personal account, with which some people already share coordinates, then they will be displayed in the smart home, but the account owner will not be displayed. Therefore, we will need a second account, it will need to be created, or it may be the account of a person who is already following us. For example, your account and the account of your girlfriend/friend/wife/husband. Simply put, we have two schemes. In the first one, all people share coordinates with one account and we use its data. In the second option, we use two accounts and collect shared geodata from both. I followed the third path… I collected the geodata of all the people from my account, and in order to see myself, I created a second account on my phone and started monitoring it.

Now how it works. When we visit the site in the browser, we download a small piece of data-a cookie. They have all the necessary information to track people. Now we will get these cookies from Google. Using the correct account, we will log in to Google Maps on the computer via Firefox or Chrome. You need to make sure that at the end of the Google site address is .com (for example maps.google.com), otherwise it will not work. After we have logged in to the account, we should see people. The screen is below, I painted over the faces with a blue circle.

Now we will get the required data via Export cookies for Firefox (You need to make sure that the item is not selected “Prefix HttpOnly cookies”) or through the add get_cookies.txt for Chrome or Chromium. I use chrome and clicking a button got all the data.

Now you need to upload the file to the server. This can be done through a file sharing service or create a new empty file inside the smart home and copy the contents from our computer to it by connecting via the terminal. We save our cookie file to the folder with the Home Assistant configuration under the following name: .google_maps_location_sharing.cookies.имя_вашего_почтового_ящика_gmail_com. For example, for a mailbox location.tracker@gmail.com, the file name will look like this: .google_maps_location_sharing.cookies.location_tracker_gmail_com

Now that the file .google_maps_location_sharing.cookies.location_tracker_gmail_com is near the file configuration.yaml, it’s time to edit the configuration. We will add to it:

# Example configuration.yaml entry
device_tracker:
- platform: google_maps
username: “YOUR_EMAIL”

It is better to copy the text from the original site, but I tried to copy it as correctly as possible…

Restart the home assistant and check that in the folder next to configuration.yaml the known_devices.yaml file appeared in with the data of the tracked people. You can open it and check that it is not empty.

Now you can think of automation. Let’s create a new one, enter its name and description. As a trigger, select the “Zone”, select the person to track, select the zone in which the person is being tracked (zone.home is created automatically when we specify our address) and select the condition: “leaves the zone” or “enters the zone”. Well, as an action — a message in telegram.

The result will be messages from the bot in the chat

If you save cookies from another account, then by adding the same other account to the configuration, we will see the coordinates of people from it as well. The maximum number of accounts is not described, but two definitely work.

And that’s all, subscribe, likes, repost…☺

--

--

Igor Mullin
Igor Mullin

Written by Igor Mullin

I´m a Hardware and Software Engineer and a PhD. In my professional activity I focus on such things like smart home systems and electric development.

No responses yet