HomeHome AutomationGoogle Home - Location Sharing: ETA & distance

Google Home – Location Sharing: ETA & distance

If the human-readable address isn't enough for you, here is the info about the distance and ETA

Google Home – Location sharing tutorial sparked a discussion about what other functions could be added to that system. The immediate response was to add the distance and ETA for each contact and this is the follow-up tutorial which will focus on just that. I would strongly recommend you to read the previous article or watch at least the showcase part of the video below.

Google Home – Location Sharing: ETA & distance

The formula is pretty simple. I’m asking Google Home to get me the location of my friend:

Hey Google, Where is Matt?
***Matt is at James st London, UK
Hey Google, Send directions to my phone!
***OK, check your Google Maps
Hey Google, what’s the distance and ETA?
***Matt is currently 200km away, with ETA of 2h and 6 min

In this part, I’m going to take care of the last question. Please bear in mind, that to keep things simple, I’m going to assume, that you are using a Google Home device, not the assistant on your phone. Trying to query the distances on the go, while it’s possible is not within the scope of this tutorial.

To enable the functionality, we will need the help of the IFTTT and Google Maps API. If you followed the previous tutorial, you have almost everything sorted.

IFTTT – ETA and Directions

To keep things simple, I’m not going to split the information about the distance and the ETA. It’s simple enough to do, I’m sure you will be able to figure it out yourself.  I just need a Google Assistant IFTTT applet liked to the Webhook and configured in the following way:

IF THIS(GOOGLE ASSISTANT)

Commands: What's the distance and ETA
Answer: I'm checking it now for you

THEN THAT (WEBHOOK)

Url: https://NODERED_IP:1880/location/ETA
Method: POST
Content type: application/JSON
Body:

The HTTP POST request needs no data, as we only want to trigger the correct flow. You could ask directly about the distance and ETA without asking for the address, but you have to modify the flow accordingly. I’m trying to introduce as little changes as possible to the previous write-up.

NodeRED – Google Home – Location Sharing: ETA & distance

The Google Home notification node is no longer working, but you can use the cast node for the same effect. See the node-red-contrib-cast for details.

The flow itself is very similar to what I have covered before. We have another Google Maps API link to compose and pass an HTTP GET request. To pass the URL, I’m configuring the function node:

var lat = global.get("locationLat");
var long = global.get("locationLong");
var locationHome = "HomeCoordsLAT,HomeCoordsLONG";

var GoogleKey = "Google Maps API"

msg.url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins="+lat+","+long+"&destinations="+locationHome+"&key="+GoogleKey;
return msg;

Replace the red fields with appropriate values. I’m using stationary coordinates for the Google Home location, you can find them via Google Maps and searching for your location.

The URL is saved as msg.url – and passed to the HTTP GET node. I have reversed the destination/origin order, as I believe in most cases I would be interested in the ETA of my friend. If I want ETA to their location, I already have “Send direction to my phone” command. By default, the ETA and distance are calculated as a metric, driving directions. If you want to change it, please check the Google Maps API for the correct variables.

The HTTP GET request returns a string. This string is formatted as  JSON object, and to use it as such, we have to use the JSON node.

Lastly, I have to format the info stored in that JSON object and pass it as the Google Home response:

msg.name = global.get("locationName");
msg.payload.time = msg.payload.rows[0].elements[0].duration.text;
msg.payload.distance =msg.payload.rows[0].elements[0].distance.text;

return msg;

and use the template node

{{name}} is {{payload.distance}} away. The current ETA is {{payload.time}}

And pass it over to the Google Home node! There you have it!

Conclusion

You can see how to obtain information about the distance and ETA. You can modify the entire set up to give you that information independently, but in this tutorial, you have to query the address first to have the access to the distance and the ETA. I hope you find this helpful!

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.

PayPal

Nothing says "Thank you" better than keeping my coffee jar topped up!

Patreon

Support me on Patreon and get an early access to tutorial files and videos.

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

Smart Ideas with

Automate your space in with these ecosystems and integrate it with other automation services

client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image

Learn NodeRED

NodeRED for beginners: 1. Why do you need a NodeRED server?

0
To server or not to server? That's a very silly question!

Best Automation Projects

Tuya SDK for beginners: Intro to Tuya Cloud API

0
Working with Tuya Cloud API. A guide to Cloud automation for beginners, get started with REST!

NEST your old thermostat under $5

0
Nest-ing up your older thermostat under $5

Nora – Google Assistant in NodeRED

0
Integrate Google Assistant with NodeRED thanks to Nora - NodeRED home automation

DIY Smart Washing Machine – for about 15 bucks!

0
Learn how to add washing machine notifications to your Google Home on the cheap

Sonoff Zigbee Bridge – review

0
Sonoff line up will soon include Sonoff Zigbee Bridge and more Zigbee sensors - here is the first look

Smart Home

Remotes aren’t done with us yet: SwitchBot Remote

0
If you hate having 20 remotes hidden in your sofa, or your parents despise talking to Alexa to turn the lights on - SwitchBot Universal Remote is here to deal with all this!

We’ve seen this before: SwitchBot K10+ PRO

0
This is an odd one. Building on the success of SwitchBot K10+ they released SwitchBot K10+ PRO - but is the experience actually better?

Is this the smart panel we have waited for?

0
ITEAD has released a new smart panel: Sonoff NSPanel Pro 120 - have they learned the lesson from the terrible launch of the original Pro? Let's see what's new.

Aqara FP1E detects motionless humans

0
This isn't exactly a new device, it's an interaction of the original Aqara presence sensor. Aqara FP1E brings Matter, ZigBee and new triggers to your smart home

SwitchBot S10: cleaning re-imagined!

0
SwitchBot S10 promises unattended vacuuming and mopping so you can focus on things you love and care for. Does it deliver?