trying to replace as much custom components/integrations with core as possible, I am stuck here, using the Composite integration which allows me to use an attribute last_seen
and calculate the timezone difference between home and the tracker:
marijn_tz_offset:
friendly_name: Marijn time zone offset
unit_of_measurement: hr
value_template: >
{% set state = states.device_tracker.me %}
{% if state.attributes is not none and
state.attributes.time_zone is not none and
state.attributes.time_zone != 'unknown' %}
{% set n = now() %}
{{(n.astimezone(state.attributes.last_seen.tzinfo).utcoffset() -
n.utcoffset()).total_seconds()/3600}}
{% else %}
undetermined
{% endif %}
I’d love to be able to do this with the person
integration, or the device_tracker I base that on, the now core companion app. Neither of these have an attribute last_seen
though.
Could we use the available attributes to re-create this. Or would a FR for adding last_seen to the companion app sensors attributes be useful.
these are close:
{{ state_attr('device_tracker.me', 'last_seen').astimezone(now().tzinfo) }}
{{ states.device_tracker.calltheboss.last_updated.astimezone(now().tzinfo) }}
but cant be used interchanged
thanks for having a look