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

Sonoff R3 DIY mode & why it sucks

0
Long awaited Sonoff R3 DIY mode is even worse than I expected.

IKEA TRADFRI Wireless dimmer in NodeRED

0
Thanks to NodeRED you can use IKEA TRADFRI Wireless Dimmer to interact with everything

Things they don’t tell you about IKEA Trådfri

0
There are things you should know about IKEA Tradfri before you make your purchase

Flashing Tasmota on Sonoff ZigBee Bridge

0
How to flash Tasmota on Sonoff ZigBee Bridge to enable it for NodeRED and Home Assistant

Flashing ESP with Tasmotizer is a dream come true

0
How to flash Tasmota on ESP devices with new Tasmotizer tool

Smart Home

No more hubs: Aqara G2H

0
Aqara G2H brings the power of ZigBee sensors to an IP camera.

Two cool features of Avatar Smart Bulbs

0
Avatar Smart Bulbs come with 2 cool features I wish more smart bulb manufacturers would include in their products.

Shelly 2.5 vs Sonoff DualR3

0
It's time to pitch similar devices against each other and compare their functions: Shelly 2.5 vs Sonoff DualR3

How to flash Tasmota on Sonoff DualR3

0
Make the device yours by flashing Tasmota on Sonoff DualR3. Now with channel control and power consumption

Shelly Duo – going beyond twice

0
Their #ShellyDuo is a WiFi-enabled lightbulb with colour temperature. Plus it comes with 2 features don't often offered by other smart lights.