Thanks, I changed it to how you did it and it works.
I did all what you decribed above:
Enered “device_tracker” in dependecies
But, sorry as I expected, got this error:
Error while setting up platform places
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 126, in _async_setup_platform
SLOW_SETUP_MAX_WAIT)
File "/usr/local/lib/python3.7/asyncio/tasks.py", line 416, in wait_for
return fut.result()
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/places/sensor.py", line 312, in setup_platform
add_devices([Places(hass, devicetracker_id, name, api_key, options, home_zone, map_provider, map_zoom)])
File "/config/custom_components/places/sensor.py", line 332, in __init__
self._entity_picture = hass.states.get(devicetracker_id).attributes.get('entity_picture')
AttributeError: 'NoneType' object has no attribute 'attributes'
My manifest:
{
"domain": "places",
"name": "Places",
"documentation": "https://github.com/tenly2000/HomeAssistant-Places",
"dependencies": ["device_tracker"],
"codeowners": ["@tenly2000"],
"requirements": []
}
Obviously, it is not enough to add device_tracker to dependecies
I do get it in a few restarts but ok most of the time.
ok, thanks
Think I’ll just comment out the lines until it’s working properly.
did it as well.
Ok, finally I got it running after commenting out the specified lines.
What I don’t like is this “(since: …)” in the state.
If alexa tells me my location in german, this information sounds strange and is useless.
If I need this information I could get it via “last_changed” anyway.
Is there a chance to get rid of it?
Just tried this and it does get rid of it:
Replace
self._state = new_state + " (since " + current_time + ")"
with
self._state = new_state
yes indeed!! So simple. Do it yourself is the message Thanks
PS: it works
I really like the (since xx:xx) in the state of the Places sensor. I tried to use the last change attribute but it doesn’t represent the same time as the (since xx:xx) in the state. I want to create a TTS voice message using this sensor and the (since xx:xx) but I rather it say “since 2 hr and 15 minutes ago” than the time.
Can anyone help me jinja the (since xx:xx) to “x hrs and x minutes ago”?
I have this so far
Rob is at {%- if (states.device_tracker.life360_rob.state ) == "not_home" %} {{states.sensor.places_rob.state.split(',')[0]}}{%- else %} {{states.device_tracker.life360_rob.state}}{%- endif %} since{{states.sensor.places_rob.state.split('since')[1] | replace(')', '')}}
so this give xx:xx
{{states.sensor.places_rob.state.split('since')[1] | replace(')', '')}}
Is this what you want? (de-personalised)
{% set since_day = as_timestamp(state_attr('device_tracker.life360_me', 'at_loc_since')) | timestamp_custom('%d') | int %}
{% set since_day_name = (as_timestamp(state_attr('device_tracker.life360_me', 'at_loc_since')) | timestamp_custom('%A')) %}
{% if since_day == now().day %}
{% set since_day = '' %}
{% elif since_day == now().day - 1 %}
{% set since_day = ' yesterday' %}
{% elif since_day < (now().day - 6) and since_day > (now().day - 14) %}
{% set since_day = ' last ' + since_day_name %}
{% elif since_day <= (now().day - 14) %}
{% set since_day = ' on ' + as_timestamp(state_attr('device_tracker.life360_me', 'at_loc_since')) | timestamp_custom('%d %b') %}
{% else %}
{% set since_day = ' ' + since_day_name %}
{% endif %}
{% set since_time = as_timestamp(state_attr('device_tracker.life360_me', 'at_loc_since')) | timestamp_custom('%H:%M') %}
{% set composite_state = states('device_tracker.me_composite') | title %}
{% if composite_state in ['Home', 'Zone1', 'Zone2', 'Zone3'] %}
Me has been at {{ composite_state }} since {{ since_time }}{{ since_day }}
{% else %}
{% set place_name = state_attr('sensor.me_places', 'place_name') %}
{% set street_number = state_attr('sensor.me_places', 'street_number') %}
{% set street = state_attr('sensor.me_places', 'street') %}
{% set city = state_attr('sensor.me_places', 'city') %}
{% set postal_code = state_attr('sensor.me_places', 'postal_code') %}
{% set country = state_attr('sensor.me_places', 'country') %}
{% if place_name == street %}
{% set place_name = '' %}
{% else %}
{% set place_name = place_name + ', ' %}
{% endif %}
{% if street_number != '' %}
{% set street_number = street_number + ', ' %}
{% endif %}
{% if street != '' %}
{% set street = street + ', ' %}
{% endif %}
{% if city != '' %}
{% set city = city + ', ' %}
{% endif %}
{% if postal_code != '' %}
{% set postal_code = postal_code %}
{% endif %}
{% set address = place_name + street_number + street + city + postal_code + (', ' + country if country != 'UK' else '' ) %}
{{ address }} (Since {{ since_time }}{{ since_day }})
{% endif %}
For what it is worth, I changed the manifest.json as suggested but didn’t comment anything out in sensor.py and it seems to work for me.
The (since xx:xx) was supposed to represent (and remember) the initial time that the person ARRIVED at that place. The last-changed attribute will not always be the same as it may update any then the user sends a location update - even while at the same “place”.
I would hesitate to remove this completely from the sensor as it is useful as-is for some people. I personally used to use this to tell at a glance what time my son arrived at school - and what time he got home.
However, now that it’s obvious that some people don’t like it - perhaps an option for the sensor display text might be appropriate. “None”, “ArrivalTime” or “Duration” seems like it would cover most use cases.
I found it easiest just to create a new sensor that monitors the state change of the Places sensor and use that to find the time difference from now.
Thanks for the help.
sensor:
- platform: template
sensors:
places_state_change_time:
entity_id: sensor.places_rob
value_template: '{{now() }}'
so this will give the time at the location in Places in minutes.
{{ ((as_timestamp(now()) -as_timestamp(states.sensor.places_state_change_time.state)) / 60) | int }} minutes ago
It turns out that the sensor changes with the attributes and therefor tracks the Places sensor last change and not Places sensor state change. To solves this, i changed it to the following.
sensor:
- platform: template
sensors:
places_state_change_time_rob:
entity_id: sensor.places_rob
value_template: '{{ states.sensor.places_rob.state }}'
and I use
{{ ((as_timestamp(now()) -as_timestamp(states.sensor.places_state_change_time_rob.last_changed)) / 60) | int }} minutes ago
I have the latest version but still getting the error.
2019-08-22 18:57:25 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform places
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 149, in _async_setup_platform
await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
return fut.result()
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/places/sensor.py", line 312, in setup_platform
add_devices([Places(hass, devicetracker_id, name, api_key, options, home_zone, map_provider, map_zoom)])
File "/config/custom_components/places/sensor.py", line 332, in __init__
self._entity_picture = hass.states.get(devicetracker_id).attributes.get('entity_picture')
AttributeError: 'NoneType' object has no attribute 'attributes'
My guess is that the devicetracker id you’ve specified in your config doesn’t exist…
I still get that error so I still need to comment out the entity picture lines
Same here. I have them comment out as well.