Hello!
Guys I have this templates sensor:
{{ state_attr('switch.entryway_wired_switch_right','last_seen') }}
= 2021-09-11T19:03:57+03:00
is current attribute value of this switch.
My sensor:
{% set last_seen = (as_timestamp(now())| round(0) - as_timestamp(state_attr('switch.entryway_wired_switch_right','last_seen')) | round(0)) | int %}
{% if last_seen == 0 %}right now
{% elif last_seen < 60 %}{{last_seen}} ago
{% elif last_seen >= 60 %}{{last_seen}} ago
{% elif last_seen >= 3600 %}{{last_seen}} ago
{% else %}unknown
{% endif %}
And my sensor is back 59403 minutes ago
value, what’s wrong? Can someone could explain this, what’s wrong in template? In the end I need x seconds, x minutes or x hours. Thanks.