PocketablesGoogleTaskerTutorials

Google Home – Location Sharing

When it comes to location sharing, Google Maps got you covered. What if you don’t fancy taking your phone out then navigating through the menus?  Good news for you, I figured out how to do all the Google Home – Location Sharing, without actually sharing the location information with Google! Interested?

Google Home – Location Sharing

The entire setup works on both Google Home and Google Assistant. Let me preemptively dismiss your arguments here. Yes I know about Google Maps location sharing feature, In fact, I use it myself. Google Home isn’t handling this, so I thought I will find a workaround.

google home location sharing 1024x650 - for some reason we don't have an alt tag here It’s so much easier to say: “Where is Matt?” and get the approximated address spoken to you. And should you desire the Google Maps pin, I made the option available for you, so you could send it via voice command to your phone.

There are also additional benefits:

  • Location is not shared with Google (even though I’m using Google Home!)
  • It’s harder to disable Google Home – Location Sharing as it uses Tasker
  • It’s just better!

To enable Google Home – Location Sharing I’m going to use the following services:

  1. NodeRED server (I’m  running it on a $5 Raspberry Pi Zero)
  2. IFTTT – a free account
  3. Tasker with AutoRemote plugin installed on the target device
  4. Google Maps API key

To make the Google Home – Location Sharing work for you, you will need to create a small Tasker profile on each Android phone you want to monitor this way. In addition to this, If you want to get the directions sent to your phone, another Tasker profile has to be created on your personal device.

Google Home – Location Sharing – IFTTT

ifttt - for some reason we don't have an alt tag hereTo send the voice commands to Google Home or Google Assistant – I’m using IFTT service. I have 2 commands, one to request the location from a specific contact, and one to send me the coordinates to my mobile.

IFTTT “Where is $?”

Feel free to modify the questions to your liking, I used the following configuration:

IF THIS(GOOGLE ASSISTANT)

Commands: Where is $, Find $ for me
Answer: Give me one second, I'll go and ask

THEN THAT (WEBHOOK)

Url: http://NODERED_IP:1880/location/person
Method: POST
Content type: application/JSON
Body: {"name":"{{TextField}}"}
IFTTT “Directions”

To get the directions I need another voice command that will trigger the correct flow in the NodeRED, this one is configured as follows:

IF THIS(GOOGLE ASSISTANT)

Commands: Send the directions to my phone
Answer: Check Google Maps for details

THEN THAT (WEBHOOK)

Url: http://NODERED_IP:1880/location/send
Method: POST
Content type: application/JSON
Body:

This request doesn’t need the body, as we only need to trigger the flow, no actual data is passed back to the server.

Google Home – Location Sharing – TASKER

Tasker Material 512px - for some reason we don't have an alt tag hereGoogle Home – Location Sharing requires 2 profiles. Once on each target device, and one on your personal device if you want to get the coordinates sent to you.

Target Device – Get Location
TASKER PROFILE - Get Location
Profile: Get Location 
	Event: AutoRemote [ Configuration:location ]
Enter: Get Location 
	Abort Existing Task
	A1: Get Location [ Source:Any Timeout (Seconds):30 
	    Continue Task Immediately:Off Keep Tracking:Off ] 
	A2: Variable Set [ Name:%loc To:%LOC 
	    Recurse Variables:Off Do Maths:Off Append:Off ] 
	A3: Variable Split [ Name:%loc Splitter:, 
	    Delete Base:On ] 
	A4: Flash [ Text:%loc() Long:On ] 
	A5: HTTP Post [ Server:Port:%MyNodeRED 
		Path:/location 
		Data / File:lat=%loc1
			    long=%loc2 
	    Cookies: User Agent: Timeout:10 
	    Content Type: Output File: Trust Any Certificate:Off ] 

You will need to obtain the AutoRemote key for each device. The plugin is used to issue the request via NodeRED. When the “location” AR event is received, Tasker will grab a set of current coordinates, split them into separate variables (%loc1,%loc2) and sends it back to NodeRED using HTTP post:

HTTP post
Server:Port:%MyNodeRED
Path:/location 
Data / File:
   lat=%loc1 
   long=%loc2
Your Device – Get Directions
TASKER PROFILE: Display Directions
Profile: Display Directions 
	Event: AutoRemote [ Configuration:GHLOCATION (case ins) ]
Enter: Open Location 
	A1: Open Map [ Mode:Point 
		Address: Lat,Long:%arcomm Zoom:1 Label: ] 
This profile installed on your Android device will wait for the coordinates sent by the NodeRED and will open Google Maps pointing you to the destination. This is a very simple profile with a single action Open Map.

Google Home – Location Sharing – NodeRED

node red hexagon - for some reason we don't have an alt tag hereEverything is handled by the NodeRED server. The Google Home – Location Sharing setup is split into 3 flows. Before I share the details, be sure to obtain the following information:

  1. AutoRemote Key for yours and target device
  2. Google Maps API key
  3. Your NodeRED external IP

FLOW: Request Location

request location 1024x176 - for some reason we don't have an alt tag hereThe HTTP POST request to “/location/person” starts the flow. I’m expecting a name in a JSON from {“name”: “Matt”} in msg.payload.name . Before I do anything with this information, I want to store it for later. To store the variable and make it available globally, we can use this script:

global.set("locationName",msg.payload.name);
return msg;

Note that this function won’t change the payload, we will be able to use it later in the switch node.  The switch node checks the value of the payload against the known contacts. In this example, I’m using “Matt” so I’m checking against the stored names and send the outcome to the correct output.

Since I need the AR Key to send the location request to the correct person, I assign the correct AutoRemote key to each name and set it as msg.payload.

Lastly, I combine the information with the AR URL with the message=location:

https://autoremotejoaomgcd.appspot.com/sendmessage?key={{payload}}&message=location

and save it as msg.url (important) – which is used in the HTTP POST node finishing the flow.

FLOW: Announce Location

announce location 1024x166 - for some reason we don't have an alt tag hereTasker submits the coordinates back to NodeRED as 2 entries:

  • msg.payload.lat
  • msg.payload.long

As before, I want to store the coordinates for the later use – I’m using the Function node which is configured:

global.set("locationLat", msg.payload.lat);
global.set("locationLong", msg.payload.long);
return msg;

At the same time, I’m passing the needed coordinates to the Google Maps API link which will translate the coordinates into the human-readable address. The template node is great for that. Don’t forget to add your API key obtained from Google!

https://maps.googleapis.com/maps/api/geocode/json?latlng={{payload.lat}},{{payload.long}}&key=GOOGLEAPIKEY

I’m saving this link again as msg.url which will be passed over to the HTTP GET request.

This request will return several matches stored in a JSON format. I know that the closest address will be stored as the 1st entry inside that array. I will need another function node to process this information and add the name of the person that shared the location with us:

msg.payload = msg.payload.results[0].formatted_address;
var x = global.get("locationName");
msg.name = x;
return msg;

I’m storing the name in msg.name and the address in the payload. Lastly, I need to format the correct reply and pass it over to the Google Home Node (node-red-contrib-google-home-notify).

{{name}} is near {{payload}}, let me know if you need the directions.

 

FLOW: Send Location

send location 1 - for some reason we don't have an alt tag hereThis is optional, but if you want to have directions on your phone, you will need another HTTP POST node “/location/send” which will trigger a function:

var lat = global.get("locationLat");
var long = global.get("locationLong");
var name = global.get("locationName");
var ARkey = "ARKEY"
var ARmessage = "GHLOCATION=:="+lat+","+long;
msg.url = "https://autoremotejoaomgcd.appspot.com/sendmessage?key="+ARkey+"&message="+ARmessage;
return msg;

I’m retrieving the information about the name and coordinates, and send it back to my phone (using AR Key for my personal mobile) – this URL has to be stored as msg.url to the HTTP POST node could issue the notification back to the Tasker.

Conclusion

It’s pretty fun to add the functions that are not present in  Google Home. I’m sure, that once I learn how to make Alexa speak in the similar matter, entire Google Home – Location Sharing setup could be used with Amazon Echos instead. Let me know what do you think about it! If you want to use ready made files, please click here for the file download. I write for pocketables.com for free, if you enjoy my content you can buy me a coffee via PayPal or join one of Patreon Rewards tiers.

Pocketables does not accept targeted advertising, phony guest posts, paid reviews, etc. Help us keep this way with support on Patreon!
Become a patron at Patreon!

Mat Zolnierczyk

I am passionate about technology, cycling, and art. This would explain why my bike has more computing power than your average office. I own notenoughtech.com and I write for xda-developers.com and pocketables.com NotEnoughTECH | Facebook | Twitter |YouTube |Instagram | Google+ |Donate |Patreon

Avatar of Mat Zolnierczyk