Google Geocode Custom Component - GPS to Street Address

just added this works really well !

@michaelmcarthur one questionā€¦
In my home i have two cellphones.
1 is mine other is my wife.
I need two apis?

I ask it because i put the same api.
And the home assistant tell me the exacly adress where i am, and my wife also with me and home assisant tell me that she is another street.

You donā€™t need two APIā€™s. The different addresses will be to do with when the last update from the device tracker was sent. Google matches the gps coordinates to the nearest street. You and your wifeā€™s phone will have updated their locations at two different coordinates. You can test it by putting the lat Lon from your device tracker into google maps and see where it thinks each of you are.

2 Likes

is this still custom_component or integrated now?

custom_component

Itā€™s still a custom component. I would love it to be integrated. I built this component to learn python. Iā€™m now struggling to get the component past the formatting rules set out by home assistant. If anyone can help with the submission head over to my github and your help will be greatly appreciated.

1 Like

Great work love this component can see where my wife is on her short walk to the car and reports the location spot on !

Hello @michaelmcarthur!
Thank you for your great work.
Is it possible to customize ā€œoptionsā€ order.
In my country address starts from city, than street and number.

Yep, you can do that by creating a template sensor. Look back in the comments Iā€™m sure someone else asked about this.

Edit. Look at comment 141. You can adapt it to do what you are wanting

Hi @michaelmcarthur

Thanks for this share.

I have 2 device trackers and would like them to work as a single entity showing my location as to where I am. How can I show that?

In othe words what I am trying to ask is that in origin can we use group instead of device tracker?

Thanks.

1 Like

@bachoo786 This is why I love the home assistant community as I would have never of thought to do that. I get why you would want to do it. Itā€™s not possible to get a group location as there is no lat lon coordinates on them. I have an idea how to achieve what you are looking for. You could create a google Geocode sensors for each of the trackers then group the sensors together. The group state should be of the last updated sensor. This is not tested but might work.

1 Like

@michaelmcarthur well I just configured another device tracker and thought of asking you :slight_smile:

so what I did was to use the same google geocode sensor of my first device tracker for my second device tracker and just changed the origin part i.e.

- platform: google_geocode
  name: michael
  origin: device_tracker2.mobile_phone
  options: street_number, street, city
  display_zone: hide
  gravatar: [email protected]
  api_key: XXXX_XXXXX_XXXXX

I then group the 2 sensors in a group say X and then group again the group X into another group say Y.

Everything works fine in group Y except that the state of group Y does not change and remains unknown. However, the state of the 2 sensors do change in group Y according to google geocode.

Do you know what could be the issue?

I had a look into how groups work. They have been coded so if device trackers are in the group they will show the last updated tracker as the group state. If you put a sensor in the group it shows as unknown. But I have a solution. You can create a template sensor.

- platform: template
  sensors:
      my_tracker:
        friendly_name: "My Tracker?"
        value_template: >-
            {% if as_timestamp(states.sensor.tracker_1.last_changed) | float < as_timestamp(states.sensor.tracker_2.last_changed) %}
                {{states.sensor.tracker_1.state}}
            {%- else -%}
                {{states.sensor.tracker_2.state}}
            {% endif %}

This should give you what you are looking for.

1 Like

Please add me as a +1 vote for the Places capabilities.

It would be great to see a restaurant name, shopping mall, store name, etc instead of an address when those things are available.

Iā€™m just in the process of trying to enable the geocode component - so I canā€™t say ā€œgreat jobā€ just yet - but I expect to in the very near future. For now, put me down as a ā€œThank you very much for developing this component!ā€. Even without Place names, this will be so much better than displaying ā€œnot_homeā€ whenever someone is outside of a zone.

If you mean like this. it is in the cookbook

Need help figuring out whatā€™s wrong with this componentā€¦

I followed the instructions on the Github page and copied the component into the config/custom_components/sensor directory. I also made the documented configuration.yaml entries and created a ā€œpeopleā€ group - then restarted Home Assistant.

Everything appears to be working properly - but I know thatā€™s not possible on the first try with a Home Assistant component - so where do I look to find something thatā€™s broken? Seriouslyā€¦ It canā€™t be this easyā€¦ can it?

@michaelmcarthur :smile: Fantastic job with this component. It really is the first component Iā€™ve enabled that has worked perfectly on the first try. Iā€™m amazed at how easy youā€™ve made this! Thank you so much!

  1. put the google_geocode.py in <config_dir>/custom_components/sensor/google_geocode.py

  2. create this in sensor platform

    • platform: google_geocode
      name: michael
      origin: device_tracker.mobile_phone
      options: street_number, street, city
      display_zone: hide
      api_key: XXXX_XXXXX_XXXXX <== from google
      gravatar: [email protected] <== from gravatar
  3. You need to register for an API key. by follow the instruction https://github.com/googlemaps/google-maps-services-python#api-keys

  4. optional for gravatar register link in his github.

@tenly Thanks for your support of this component. The fact that it works first time is due to the people in the home assistant community. It was a big help getting feedback from everyone on the forums.

@michaelmcarthur so I implemented the template sensor you gave and the results are very patchy in the sense that it does not select the last changed sensor.

Could we use binary sensor instead? as template sensors have a performance impact I suppose?

So - now that Iā€™ve added this Geocode component, my device_tracker automations are not firing anymoreā€¦

I have the following automation that worked prior to implementing the Geocode component - but now it doesnā€™t.
Is there a simple explanation? A simple fix to get it to start working again? The only thing I changed was that I added the last parameter to the ā€œmessageā€ to try to get the text to include the formatted address from the Geocode sensor.

- alias: LocateAidan
  trigger:
    platform: state
    entity_id: device_tracker.aidan_iphone
  action:
    service: notify.ios_my_iphone8
    data_template:
      title: Location Alert
      message: >
        Aidan: {{ now().strftime("%Y%m%d-%H%M%S") }} Location changed from {{ trigger.from_state.state }} to {{ trigger.to_state.state }}  ( {{ sensor.G_Aidan.attributes.formatted_address }} )
      data:
        attachment:
          content-type: jpeg
        push:
          category: camera
        entity_id: camera.location_aidan

Thanks in advanceā€¦