Reverse Geocode Sensor ("Places") using OpenStreetMap - custom component

I have upgrade to 0.78 and I receive many error message, can you pls check

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 224, in async_update_ha_state
    yield from self.async_device_update()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 353, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/util/__init__.py", line 325, in wrapper
    result = method(*args, **kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/sensor/Places.py", line 432, in update
    self.do_update("Scan Interval")
  File "/home/homeassistant/.homeassistant/custom_components/sensor/Places.py", line 676, in do_update
    user_display.append(targetoption)
NameError: name 'targetoption' is not defined

Sure. Can you please share your configuration section for the places sensor?
The error message you posted makes it look like you haven’t configured any display options.

HI, testing your CC, seems to run fine, thanks for this!

please allow me a couple of startup questions…:

  • have 2 sensors created, 1 is home showing home(since9:48) as state, and more-info shows all attributes correctly. the other is not_home, but shows all attributes in the state , an also on the more-info. I would think the state should only show not_home or zone and the time, and not all the rest?

or is this defined in the setting options: ? Thought that to decide which of the attributes were set… if so, maybe rename that to show_as_state: ?

  • how to show generic camera maps of these sensors? I now use this:

     camera:
        - platform: generic
          name: Locatie 
          still_image_url: >
            https://maps.googleapis.com/maps/api/staticmap?center=
            {{ state_attr('device_tracker.life360','latitude') }},
            {{ state_attr('device_tracker.life360,'longitude') }}
            &zoom=13&size=500x500&maptype=roadmap&markers=color:blue%7Clabel:P%7C
            {{ state_attr('device_tracker.life360','latitude') }},
            {{ state_attr('device_tracker.life360','longitude') }}
          limit_refetch_to_url_change: true
    

but obviously like to change that to the openstreetmap api? can’t we use the sensor places for that? like:

   camera:
      - platform: generic
        name: Locatie 
        still_image_url: >
         {{state_attr('sensor.places','map_link')}}

it now shows an empty card…

09

btw if I enter the code in a browser window it shows fine, after clicking yes while it is an https page and needs authorization. The green marker is dearly missed though, couldn’t you add that to the map please?
If I enter the url directly in Apple Maps, all is there, even the blue marker :wink: Now how to get that in HA!

  • (how) can we use the sensor to replace the google or waze travel time sensor, and how to use it in proximity calculations?

also, do you have reasons not to use the openstreetmap itself for the url? Isnt that the most obvious thing to do, all things considered?

feature-request:

please consider adding time_from_home. you already have distance_from_home. Would be a nice addition.

thx!

Hi there,

Give me a few days to digest all of your comments and have some time to test a couple of things.

As for the travel time - that would require another service call which could be subject to API limits - at least with Google - and there are already components that do this pretty well. I didn’t want to add a feature unless I can do it well. But if you can provide me with an OpenStreetMap URL that returns Travel Time between 2 points, I’ll definitely consider adding it.

Can you elaborate on your first question - about what is displayed for “not_home”. You should be able to limit what you see in the state via the options parameter.

yes I am, I simply didnt understand at first what options: meant. I might suggest to use show_as_state instead, which is somewhat more meaningful.

I appreciate your remarks about other services, but they most use device_trackers, while you create sensors, hence my question to provide travel time.

Would be really cool if you’d be able to add a openstreetmap url, next to google and apple.

And, my most pressing question now: how to show the map-url as camera: still_image… I cant get it to show at all. Can only enter the url in Apple maps, outside HA, so thats of no use yet…

thanks for considering!

btw ive also tried http://staticmap.openstreetmap.de and create a camera still image with this code:

 - platform: generic
   name: Locatie M places
   still_image_url: !secret places_m   
   verify_ssl: false
   limit_refetch_to_url_change: true

and the secrets (redacted):

places_m: >
   http://staticmap.php?center=
   {{ state_attr('sensor.m_places','current_latitude') }},
   {{ state_attr('sensor.m_places','current_longitude') }}
   &zoom=14&size=865x512&maptype=mapnik&markers
   {{ state_attr('sensor.m_places','current_latitude') }},
   {{ state_attr('sensor.m_places','current_longitude') }},
   color:lightblue1

but it won’t work. Any thoughts here please?

do you have this running in HA?

you think we could?

no, i am trying to have the map show up with this:http://staticmap.openstreetmap.de

camera wont do it, maybe another way to show that as img. ?

I understand. I think you should have the php file on the server to get this working. your code is refering to : http://staticmap.php?center=

A yes, I see now…
well thats a no go then. Too bad, cause it would really be great if we could show these OpenStreetMap 's instead of the GoogleMaps.

as an update, I have been successful showing the map with Bing static image, had to create a Bing map key here Sign in to your account , and create the camera still image as follows:

  https://dev.virtualearth.net/REST/v1/Imagery/Map/Road/
  {{ state_attr('device_tracker.life360_m','latitude') }},
  {{ state_attr('device_tracker.life360_m','longitude') }}/14?mapSize=500,500&pp=
  {{ state_attr('device_tracker.life360_m','latitude') }},
  {{ state_attr('device_tracker.life360_m','longitude') }};54;
  &key=My_Key

use whatever gps location device_tracker u have of course.

note that /14 is the zoom factor, and 54 is the Pin icon, which can be any of these: Pushpin Syntax and Icon Styles - Bing Maps | Microsoft Learn

HI @tenly,

the automations you provided wont trigger in my setting, And Im not sure I have set it correctly, please help would you?

in the sensor configuration, I have this:

sensor:
#https://github.com/tenly2000/HomeAssistant-Places
  - platform: places
    name: Name places 

the sensor entity_id is sensor.name_places

would I need to set the automation to:
- alias: Locate M
#initial_state: ‘on’
trigger:
platform: event
event_type: places_state_update
condition:
condition: template
value_template: >
{{ trigger.event.data.entity_id == ‘name_places’ }}

shouldn’t the value_template contain the full entity_id sensor.name_places?
btw I’ve changed the original entity in your template to entity_id because entity seemed incorrect? You’re sure that should work?
please have a look. thx!

nevermind, found it… entity is the exact name, case sensitive and with spaces. In my setting entity =='Name places'

now how to prevent it from triggering too often…

sorry to report, i’ve had to disable this component for now.

Running hassio/hassos 0.80.0b0 it causes frequent spontaneous restarts, and upped the battery-drain significantly. Which is too bad, cause I really liked the extra functionality this CC offers, and I had hoped this to be an improvement on the iCloud tracker on exactly that battery-aspect.
Must admit I haven’t played around fully with the extra settings and attributes, which I simply had loaded fully. Taking a few out there could alleviate the street maybe, but as said, I haven’t tested that.

If Ha is on a next release version I will test again, and I hope maybe this component has seen further development and will have improved on the processor/memory usage by then.
Cheers!

for your information. I changed my static map to this site. it’s working fine. 15000 calls a month for free.

Yes thanks , I’ve seen that and tried it . Was a bit hesitant to give my gps coordinate tonyet another ‘free’ service…

Would you know what to do with the built in map urls (Google or apple )? They are fine to load in a separate browser window but do nothing in a camera still image?

Would love to be able to use the apple maps feature like we can use Google maps, but I haven’t been succesful doing so with these urls .
Maybe you know how to?

Hi Marius,

Sorry I haven’t gotten back to you on your other questions - and I doubt I’ll be able to before early November due to an unusually heavy workload at my real job.

However, the Places component does not and can not impact your devices battery life at all. It triggers off of changes reported by DeviceTracker entities - so whatever mechanism you are using to track your location is what is responsible for the battery-drain. I found that to be the case when using the iCloud tracking and ended up implementing a solution using OwnTracks which doesn’t update as frequently - but is still useful. But in any case - the “Places” component does not request updates from your device, it just responds to the updates that your device sends to DeviceTracker.

My static maps (that used to work) also no longer work. I haven’t researched why - but I’d be surprised if it were linked to the HomeAssistant version that you are using. It’s almost certainly linked to a change made by Google.

But regardless as to whether you are still using the component or not, when time permits, I’ll look at your questions and suggestions and try to address them.

1 Like

ok thanks I appreciate that, and am looking forward to the development this component would make, as said I really like its functionality,

About the battery: will investigate further, indeed it seems strange if it only would feed off the devices I already have.

You mention Google, not the Apple map. How could I use that? Should it work in a camera: generic setting? Or is it intended for other use.

thx,
Marius

Hi Marius,

When I created the map links, my intent was to be able to push those links in an email or twitter notification.

I had also created a couple of generic map sensors in the Home Assistant UI, but for those map images, I just googled for the correct URL format and then inserted the latitude and longitude from the device tracker entity - because the DeviceTracker is the authoratative source for lat/long. Places and other sensors may cache that information - but deviceTracker is the right place to pull it from.

Hello. A quick question: I have created large zones in my HA setup to cover entire communities in my area. If I am reading the earlier posts correctly, I will be unable to use this custom component to give me the street address when the device tracker is in a zone? If so, is there a workaround to overcome that? Thanks!

I have recently updated to 0.86.6 and am having issues with the Places Sensor. Specifically I am seeing messages to the effect that update of the sensor failed.

I’ve attached some of the log file showing the messages that are received:

2019-01-04 13:13:20 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.places
2019-01-04 13:13:20 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.places
2019-01-04 13:13:20 INFO (SyncWorker_0) [custom_components.sensor.places] (Alan) DeviceTracker Entity ID is Alan_iphone
2019-01-04 13:13:20 INFO (SyncWorker_4) [custom_components.sensor.places] (Jenny) DeviceTracker Entity ID is jenny_2b6492a72cb74fad9a6ac718fd25c566
2019-01-04 13:13:20 INFO (SyncWorker_0) [custom_components.sensor.places] (Alan) Now subscribed to state change events from device_tracker.alan_iphone_
2019-01-04 13:13:20 INFO (SyncWorker_4) [custom_components.sensor.places] (Jenny) Now subscribed to state change events from device_tracker.jenny_2b6492a72cb74fad9a6ac718fd25c566
2019-01-04 13:13:51 INFO (SyncWorker_1) [custom_components.sensor.places] (alan) Calling update due to Scan Interval
2019-01-04 13:13:51 INFO (SyncWorker_1) [custom_components.sensor.places] (alan) Check if update req’d : device_tracker.arpainter_iphone_
2019-01-04 13:13:51 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.alan fails
File “/config/custom_components/sensor/places.py”, line 432, in update
File “/config/custom_components/sensor/places.py”, line 462, in do_update

I have Version 1.2 of the Places sensor which seems to be the latest version on Github. Any advice as to what I need to update to have this sensor working with 0.84.6?

Can I ask you, how you integrate this to home assistant?