Google Geocode Custom Component - GPS to Street Address

@nick_12 Thank for letting me know what was wrong. I will build into the code the ability to use upper, lower or mixed case. It will help other users from having the same issue as yourself.

I am using the HomeAssistant ios app @robbiet480 for my Zones will this need to be updated or do i have to use Owntracks?

@cameron Thank you for showing interest in my component. The home assistant ios app should work. If you check its attributes in developer > states. If it has a lattitude and longitude attribute then it will be able to track your location.

If you want to wait 24hours. I will have an updated component on GitHub with no need for a api key and that will deal with a few issues that people are having.

Great thanks
I do have Latitude and Longitude GPS coordinates so look forward to trying your new code.

I use owntracks and the iOS app.

I set my iOS ā€œdevice trackerā€ as the origin and it works perfectly!

1 Like

Hi, I having the Issue of show unkown when not in a zone. let me make sure I done this right

I created a folder called custom_components
inside that folder I created another folder called sensor
and pasted google_geocode.py in it

in my sensor.yaml I added

  • platform: google_geocode
    name: me
    api_key: !secret jizarkey
    origin: device_tracker.jizar_jizar
    options: both

Let me know if I missed something.
I can see my location and my kids at zone.home or if im at work I can see me at zone.work
but anywhere else that is not a set zone. it show unknown
on my owntracks shows not_home

edited: ps my device tracker shows:

friendly_name: Jizarā€™s Phone
longitude: -845.5465465454 (changed for security)
battery: 56
entity_picture: /local/png/jizar.png
gps_accuracy: 73
source_type: gps
latitude: 200.5004756 (changed for security)

@Jizar_Stoffel I have a fix in the works for this issue. It will be out tomorrow. I have found that google does not present the json info in the same way in different countryā€™s. Can I ask which country you are from and I will test it before I release the new version tomorrow?

Florida, USA
Iā€™ll do what I can to help

1 Like

Hi,

I have the same ā€œunknownā€ problem. I am from germany.

@dermicha Check my GitHub tomorrow and it will be fixed. Iā€™ll also check to see how google formats the German results.

I have a big update to the component today. I have taken on board all the issues and features that have been suggested and fixed or implemented them. There is still some great ideas that are not added on yet but I will be working on throughout the coming days. If anyone has anymore ideas please add them to this forum. If there is any further issues could you add them to my GitHub issues page and I will fix them as soon as I can. Thank you for your support.

Update the sensor by downloading the now code on my GitHub page

New Features

No need for a API key.
This is a big one for a user experience. Thanks to @monkey_of_hill for bringing this to my attention.

Sensor Attributes
The sensor will now display attributes when you click on it. The current attributes are Street, City, Postal Town, State, Country and Postal code. These can be used alongside a sensor template to display any combination of these attributes. @monkey_of_hill This should allow you to display State and Country.

More options - State and Country
I have added two more options and had to remove full as it was causing the sensor to fail. I will be working on a solution for this. @nick_12 sorry that I have removed this feature but it will be back as soon as I work out how to make it stable.

Awaiting Location
Im working on getting to sensor to update when home assistant starts but for now I have added Awaiting Location to the sensor until the first update occurs.

Scan Interval
Scan interval can now be used. The default is 60 seconds but I wouldint go below 30 seconds as the sensor takes about 10 seconds to process the info to the front end at times. Thanks @nick_12 for requesting this.

Fixes

Better Street recognition
Thanks to @monkey_of_hill for this. I have searched around the world for different json formats that google provides. If anyone else wants to check out different json formats that are different from the standard ones please feel free to post your results. See this post for further details of what Iā€™m looking for.

Unnamed Streets
If street is not available Unnamed Street will be used. Some searches do not contain any street information This has caused sensors to fail. This will resolve this issue.

JSON dic not found error fixed
I have rewritten the json function to search rather than look for a particular item. @jizar_soffel @dermicha this should fix your problems

User entered options are now not case sensitive
Thank you @nick_12 for pointing this out. Now users can enter in any format of words as an option and it will not stop the sensor from working.

Breaking Changes
Read the updated readme on GitHub
You will need to remove the api_key from your sensor.yaml file.
The full option has been temporally removed. Please use another option.

5 Likes

Hi,

installed and works, but it shows the wrong street.

54.9089,8.3093

The component shows ā€œWesterlandā€ as street, but it is a part of ā€œSyltā€, no street". In owntracks, the street is shown as ā€œAndreas-Nielsen-StraƟeā€.

@dermicha Thanks for pointing this out. This was a fix to allow for json data from Japan to show correctly but it is taking the place of your street name. Iā€™m working on a fix.

@dermicha I have fixed your problem and the Japan fix works alongside it. My fix shows ā€œStltā€ as the City as its a small island. The way that google has encoded ā€œWesterlandā€ is as an area of a city. If I change that It will break most other users sensors. You can get the updated code by following this link.

Would this be something worth adding as an option for device trackers with an additional parameter?

    - platform: owntracks
      max_gps_accuracy: 200
      geocode: true
1 Like

@kylerw That is an fantastic idea. It would also be the most simplistic. Have you got an example of where something like this has been done before?

I donā€™t have an example, unfortunately. My assumption would be that it may have to be an update made to each device tracker that can/should support it which is why I said ā€œwould it be worth itā€.

I imagine using a common import of your code could make it quite simpleā€¦ but still extensive since there are quite a few lat/long device trackers available.

Works great.

Looks cool; Iā€™ve gotta play with this soon. Of course, I have to leave the house first.

1 Like

Great project. I installed it and it works quite good. I only have repeating errors in the log file. Is this repairable?

2017-07-25 16:49:59 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.wilfred 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 132, in update
    url = "https://maps.google.com/maps/api/geocode/json?latlng=" + lat
TypeError: Can't convert 'NoneType' object to str implicitly
2017-07-25 16:51:00 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.wilfred 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 132, in update
    url = "https://maps.google.com/maps/api/geocode/json?latlng=" + lat
TypeError: Can't convert 'NoneType' object to str implicitly