Hi, I have been having great fun setting up presence detection, got it all working pretty well with three inputs (GPS, BT and HomeKit) and a bayesian sensor.
I found a blog post about making presence less binary, incorporating “just arrived” and “just left” states to avoid lights flicking on and off in the event that the presence detection mucks up and thinks I’ve left home for a second. All that is working fine, the post is here: https://philhawthorne.com/making-home-assistants-presence-detection-not-so-binary/
In the comments, someone posted a python script to make a new device tracker based on the status reported by the sensor created in that post, so it can be displayed nicely in Home Assistant. Again, this is working fine.
However, I’d like it to display a picture of the person, rather than just an icon. I customised the entity to include the picture, which works fine until I restart Home Assistant. The device tracker is only created when the status is updated, and so it’s essentially a new entity and the customisation is gone.
I contacted the person who created the script and she said I need to add in the picture when the device tracker is created… and that’s where I’m struggling. Nothing I do seems to work. Can anyone help me figure out what I’m doing wrong?
Here is the automation which grabs data for the script, I added the commented out “meta_pic” bit at the bottom to try to pass the image to the python script:
- alias: Presence update tracker
trigger:
- platform: state
entity_id: input_select.brad_status_dropdown
- platform: state
entity_id: input_select.rob_status_dropdown
action:
- service: python_script.custom_tracker
data_template:
entity_id: '{{trigger.entity_id}}'
meta_entity: >
{% if trigger.entity_id == 'input_select.brad_status_dropdown' %}
Brad
{% else %}
Rob
{% endif %}
# meta_pic: >
# {% if trigger.entity_id == 'input_select.brad_status_dropdown' %}
# 'GRAVATAR URL 1'
# {% else %}
# 'GRAVATAR URL 2'
# {% endif %}
And here is the python script, with my “metaPic” code which was supposed to include the image when the device tracker is created commented out as above:
# Get Data from Automation Trigger
triggeredEntity = data.get('entity_id')
metatrackerName = "device_tracker." + data.get('meta_entity')
#metaPic = data.get('meta_pic')
# Get new state
newState = hass.states.get(triggeredEntity)
newStatus = newState.state
hass.states.set(metatrackerName, newStatus, {
'friendly_name' : data.get('meta_entity')
#}, newStatus, {
# 'entity_picture_template' : 'metaPic')
})