Google Geocode Custom Component - GPS to Street Address

Device trackers are great! They can tell us if we are in a zone but what if we are not it displays as not_home. I wanted to change this and I have with my component. Google Geocode is the process of converting device tracker location into a human-readable address.

This will display a trackers location as a street name, a city or both.

You can try out the component by following the instructions on GitHub

It takes 60 second to take the first reading. It will display a zone name if you are in a zone. So if you are at home go for a walk and watch the sensor change to the name of the street you are on. Or if you do not want to go for a walk simply change the device trackers location to not_home.

I would love to get feedback on this component. What additional features would you like to see? Is there any issues with it? The aim for this project is to get it added to Home Assistant in a future release. All feedback will be valuable and appreciated.

52 Likes

As we already spoke I would like full address support and closest intersections and maybe a donation location. Once again thanks for all of the help.

Done just check the latest commit on GitHub.

This is great! One question – how do you set it up to work on two origins?

Another option would be to make the street name / address clickable, which would open up in, say, Google Maps, which is much more robust than OpenStreetMap.

I would also love to be able to detect when a device_tracker is in significant motion (like jumping further than X km over Y time) versus mostly in the same location.

1 Like

Like this

- platform: google_geocode
  name: Michael
  api_key: XXXX_XXXXX_XXXXX
  origin: device_tracker.mobile_phone
  options: both
  
- platform: google_geocode
  name: Donna
  api_key: XXXX_XXXXX_XXXXX
  origin: device_tracker.mobile_phone_2
  options: full
3 Likes

Brilliant idea! Have you seen that done in another component? If so which one. I can’t think how to do it of the top of my head but if another component had it I could work out how to do it.

I haven’t! But I asked earlier today here if anyone had any ideas: Location sensing: moving between zones

Also can you make the home has a capial H? Also I know with the old script it would update with automations how does this one update and how often? I’m sorry for all of the questions :slight_smile:

2 Likes

This looks really interesting. Unfortunately I need to secure my owntrack setup before I can try this, but I sure will!

As for features, I would like to see just the city unless it’s in my “known cities” (a list?) where showing only the street is sufficient. When abroad, just city and country :wink:
I can also see the usefulness of a “current speed” as an indication of “in transit”.

By secure what do you mean? Just out of curiosity.

I’ll fix the capitalisation issue in home tomorrow.

The sensor updates every 60 seconds. It checks if you are in a zone. If you are it will display the zone name. If you are showing as not_home it will take the gps coordinates and query google. Then on the next pass it will check if the coordinates have changed. If they have it will query google again. This really save on api calls I use about 30-40 calls a day for each sensor. Out of 2500 potential calls. I’m tempted to change the update frequently to 30 seconds. Do you think the update frequently needs to be quicker than 60 seconds?

IDK yet. I was just curious. It’d be nice if there was a way to manually specify, but default to 60.

The global scan_interval option will give the user the option to make it update quicker. It won’t work in my component at the moment but I’ll add it in tomorrow.

Works like a charm on first attempt, thanks for sharing!

Great Job! Works like a charm! I was just thinking of doing the same, and you beat me to it and saved me time :slight_smile:

Wrong wording, securing my mqtt broker, not owntrack :wink:
I have a mosquitto broker on my local LAN that uses the default settings with no encryption so I’m trying to setup bridging using an extra Mosquitto broker with TLS, certificates and passwords before letting anything in through the firewall.

Just an FYI that you can run this without an API key by using maps.google.com instead of maps.googleapis.com. I have no idea what this impacts otherwise but it’s how I use it via tasker on my phone. From what I can tell it’s the older v2 of the API that’s been retired. And then just delete the API reference everywhere in the .py script. (and you’ll notice I also dropped the " + “&result_type=street_address” + “&key=” + api" off as well.

url2 = "https://maps.google.com/maps/api/geocode/json?latlng=" + lat

I have posted a new commit to GitHub. It has fixed the zone capital letter issue and added in the option to use scan_interval. Keep the ideas coming and I will see what I can do.

I found using this option gave me the same results in the correct positions every time. Not having it in some locations changed the order of where street and city was. I’ll have a look at not using a api key. It will make the user process a whole lot easier and make it more accessible. Thanks for pointing this out.