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

No code changes were made, just moved the repo, so that is expected

It is owned by the community now, so PRs from anyone are welcome.

problem seems to be with latest hassio release wherein dependencies are not being loaded correctly mentioned in manifest.json file

Thanks @Holdestmade Was getting issues on update to 0.96 too and this fixed it

For info the actual line numbers in sensor.py below:

line 263
ATTR_PICTURE = 'entity_picture'
line 332
self._entity_picture = hass.states.get(devicetracker_id).attributes.get('entity_picture')

lines 382-385

@property
def entity_picture(self):
#   """Return the picture of the device."""
    return self._entity_picture

line 411
ATTR_PICTURE: self._entity_picture,

Cheers

mb

Yes, that’s the same as I posted above

1 Like

Sorry i didn’t see the actual line numbers :slight_smile:

I think this is failing because when the places component is being set up at start up, the device tracker entity is not ready.
I have added a check in the sensor.py to check rather than fail and that seems to work and not produce any errors but the entity_picture is not updated once the component is up and running, which is what it should do I guess ?
Not a programmer by any means so am just trying what works, has anyone else has any ideas to update the entity_picture when the rest of the data is updated ?
Other alternative if no-one needs the entity-picture is just remove that part of it, as we have been doing so far

1 Like

If that is true, than putting “device_tracker” at the dependencies section of the manifest should do the trick.

{
  "domain": "places",
  "name": "Places",
  "documentation": "https://github.com/tenly2000/HomeAssistant-Places",
  "dependencies": ["device_tracker"],
  "codeowners": ["@tenly2000"],
  "requirements": []
}

This will make sure the device_tracker component is started before this integration. This however does not take into account that the specific GPS based device_tracker is working, properly configured or available.

1 Like

@j1nx Big thanks, this works !

Added to the manifest.json and starts up fine, no errors, takes a bit to wait for my GPSLogger device tracker to come online and then it grabs the enitity_picture from it and adds it to the sensor.

1 Like

Indeed, you have to wait till the whole device_tracker section is fully loaded. Takes a bit more time for the places sensor to come up, but it will not error out because of a missing picture anymore.

I see, sounds logical. Thanks again

Works Perfect!

I’m wondering how it can work without commenting out the lines mentioned above.
As I look into the entity device_tracker. there is not attribute entity_picture.
So that will lead to an error anyway, right?

Yes, Ican add it via customizing.
But when I do not have the need to do that, it will still run on an error in my opinion.

hass.states.get(devicetracker_id).attributes.get('entity_picture')

Will only give the error AttributeError if the entity_id does not exist.
If the entity is missing the entity_picture attribute, it will simply return None.

If the manifest trick fails it can be solved like this:

try:
    self._entity_picture = hass.states.get(devicetracker_id).attributes.get('entity_picture')
except AttributeError:
    self._entity_picture = None

I actually changed mine like this:

devicetracker = hass.states.get(devicetracker_id)
if devicetracker is None:
    raise PlatformNotReady
self._entity_picture = devicetracker.attributes.get('entity_picture')

Raising the PlatformNotReady exception makes it retry later if the device_tracker doesn’t exist. But I did this before I was aware of the trick with the manifest.

I tried removing the entity_picture from the device tracker and still no errors

Hmm… that’s interesting.
Thanks a lot for your support

Putting

in to manifest is working without commenting out enitity_picture lines.

It took me a little to figure this out but to add more than one person, I had to create two custom components with different names.

In the custom component folders, I added folders

places_name1
places_name2

with the same contents in them.

In configuration.yaml, I added

sensor:
  - platform: places_name1
    name: name1_place
    devicetracker_id: device_tracker.life360_name1
    options: place
    map_provider: google
    map_zoom: 17
    home_zone: zone.home
    api_key: !secret client_secret
  - platform: places_name2
    name: name2_place
    devicetracker_id: device_tracker.life360_name2
    options: place
    map_provider: google
    map_zoom: 17
    home_zone: zone.home
    api_key: !secret client_secret

Hi there,

I have two people in one component?

#CC HomeAssistant-places
  - platform: places
    name: Jakki Places
    devicetracker_id: device_tracker.life360_jakki
    options: place,street,city
    map_provider: google
    map_zoom: 19
    api_key: xxxxxxxxxxxxxxx
    home_zone: zone.home
  - platform: places
    name: Mark Places
    devicetracker_id: device_tracker.life360_mark
    options: zone,place,street,city
    api_key: xxxxxxxxxxxx
    map_provider: google
    map_zoom: 19
    home_zone: zone.home

What error did you get on two people from the same component?

mb

1 Like