Google Geocode Custom Component - GPS to Street Address

Hi,

awesome work, thanks for that!

Is it possible to show the address instead of the zone? Maybe with a config option?

Thanks in advance!

I had thought of doing that as an option. It is possible just not implemented yet. I’ll add it to the list of additions. Thanks for your input.

My tasker parsing actually cycles through the results to match specific ‘types’ (I just want state/country) because they do move sometimes (at least when I was in Japan they sometimes wound up at a different position in the array - which I think is because different locations don’t have all of the ‘types’ defined.) Below is a subset of the return for NY and Tokyo to see the slight differences. Also if you go the actual complete results people can see all of the options - so they can tweak to their hearts desire for their specific needs. Also at the end is my tasker java scriplet to parse out what I want (state/country)

Empire State Building (https://maps.google.com/maps/api/geocode/json?latlng=40.748817,-73.985428)

         "address_components" : [
            {
               "long_name" : "17-77",
               "short_name" : "17-77",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "West 34th Street",
               "short_name" : "W 34th St",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Midtown",
               "short_name" : "Midtown",
               "types" : [ "neighborhood", "political" ]
            },
            {
               "long_name" : "Manhattan",
               "short_name" : "Manhattan",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "New York",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "New York County",
               "short_name" : "New York County",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "NY",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "10001",
               "short_name" : "10001",
               "types" : [ "postal_code" ]
            }

Tokyo (https://maps.google.com/maps/api/geocode/json?latlng=35.6895,139.6917)

         "address_components" : [
            {
               "long_name" : "Tokyo Metropolitan Government Building",
               "short_name" : "Tokyo Metropolitan Government Building",
               "types" : [ "establishment", "point_of_interest", "premise" ]
            },
            {
               "long_name" : "2 Chome",
               "short_name" : "2 Chome",
               "types" : [ "political", "sublocality", "sublocality_level_2" ]
            },
            {
               "long_name" : "Nishishinjuku",
               "short_name" : "Nishishinjuku",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "Shinjuku-ku",
               "short_name" : "Shinjuku-ku",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Tōkyō-to",
               "short_name" : "Tōkyō-to",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Japan",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "160-0023",
               "short_name" : "160-0023",
               "types" : [ "postal_code" ]
            }
         ],

Here is my Tasker code

var arr = JSON.parse(global("HTTPD"));
for (var i = 0; i < arr.results[0].address_components.length; i++) {
if (arr.results[0].address_components[i].types[0] == "administrative_area_level_1"){
var adminarea1 = arr.results[0].address_components[i].long_name
}
if (arr.results[0].address_components[i].types[0] == "country"){
var country = arr.results[0].address_components[i].long_name
}}

Also just discovered that does need the API key to work

{
   "error_message" : "This functionality is only available if an API key or a client ID is provided: result_type",
   "results" : [],
   "status" : "REQUEST_DENIED"
}

@monkey_of_hill Thanks for checking. I have rewritten the json parser so it does not matter where each of the types are located. I’m working on getting the state and country information added to the sensor. I have managed to do this as additional options. I’m currently adding in attributes so users can use template sensors if they want a particularly formatted address as you would require. I’m out of time tonight but I will continue to work on it over the next few days.

@monkey_of_hill I managed to find some time to created a dev branch on my GitHub page. I have added attributes to the sensor and given another two options to display on the sensor, state and country . I will continue to work on the sensor in depth on Tuesday as I need to update the readme and test a few thing out before merging. If you want to run my dev version you can find it here.

sorry where exactly do i check this ? my android phone ?

I’m also getting the LOGGER error:

2017-07-22 19:52:16 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.brucesg6 fails
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity.py”, line 225, in async_update_ha_state
yield from self.hass.async_add_job(self.update)
File “/usr/lib/python3.4/asyncio/futures.py”, line 388, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.4/asyncio/tasks.py”, line 286, in _wakeup
value = future.result()
File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result
raise self._exception
File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/util/init.py”, line 303, in wrapper
result = method(*args, **kwargs)
File “/home/homeassistant/.homeassistant/custom_components/sensor/google_geocode.py”, line 119, in update
self._origin_entity_id
File “/home/homeassistant/.homeassistant/custom_components/sensor/google_geocode.py”, line 201, in _get_location_from_entity
_LOGGER.error(“Unable to find entity %s”, entity_id)
NameError: name ‘_LOGGER’ is not defined

- platform: google_geocode
  name: brucesg6
  api_key: a_real_key
  origin: device_tracker.google_bruce_g6
  options: both

google_location:
   name: Locations
   entities:
   - sensor.brucesg6
   - device_tracker.google_bruce_g6
   - device_tracker.google_brucesg6

@fvargasfrank @bmorgan Can you have a look in developer tools > states > device_tracker.your_device. Click on the item then check the attributes. Can you paste the results into the comment section and change the numbers from latitude and longitude to protect your location.

What I think is happening is the lattitude and longitude are appearing differently than what I’m expecting. If I can see how they are presented on your tracker I can fix it. Out of interest what app are you using to track your location?

source_type: router (asuswrt)
latitude: 33.123456
entity_picture: /local/geezer.jpg
longitude: -86.123456
gps_accuracy: 0
friendly_name: Bruce’s G6

@bmorgan You attributes look good for lat lon but you are using a router to track your location. Which will only track if you are home or not_home you need a device tracker that is on your phone like owntracks or locative that sends coordinates to home assistant from your actual location. The router option only detects when your device is connected to the network and marks it as home. I would try the component with owntracks or locative and see how you get on.

I used owntracks for a while, but I seldom go anywhere and it got on my nerves. Want to use it for my wife’s phone mostly. She travels a bit. I’ll crank it up on mine again if I ever get another vacation.

Mine says home when I’m out and about. My device tracker appears to be working correctly with long and lat

@nick_12 Can you check if your device tracker says not_home? It sends query when it is sent to not_home. Also check the error log for any issues.

Update for sensor.nick fails
File “/home/hass/.homeassistant/custom_components/sensor/google_geocode.py”, line 189, in update

And it says no home in the device tracker

@nick_12 I think I know what the issue is. Some locations don’t have a route type which causes issues. Im putting out a new release on Tuesday. Which will resolve this issue. Thanks for your feedback it’s really appreciated and will lead to a stable component.

1 Like

Ok awesome.

@nick_12 Out of interest what option are you using? Street, City, Both, Full?

EDIT
Thank you for all your feedback. The response to this component has been amazing. There is a few issues and improvements raised. There will be an update on Tuesday 25th July. This will address the following issue.
Update failing during lookup. This issue is due to google not providing a street name in the response.

Improvements
No need for API key
Sensor attributes
Turn off zone option - display address instead of zone
More sensor options, state, country and formatted address.

If anyone has anything else you would like added please let me know.

1 Like

I’m using Full

Mine was having issues because I had Full instead of full. Once again thank you for your hard work