lovelace-template-entity-row
lovelace-template-entity-row copied to clipboard
'format' variable ignored for sensors with device_class of 'timestamp'
When templating a (device_class) timestamp sensor to make the icon active within a set time period, in this case 30 days before car insurance due date, the format variable is ignored and it only shows the actual state, instead of relative, total, date, time and datetime formatted options that are available in a regular Template Entities Card.
# Ignores formatting
- type: custom:template-entity-row
entity: sensor.car_insurance_due
name: Insurance Due
format: relative
active: >-
{%- if (as_timestamp(states('sensor.car_insurance_due')) - as_timestamp(now())) <= 2592000 -%}
True
{%- else -%}
False
{%- endif -%}
# Adheres to formatting
- entity: sensor.car_insurance_due
name: Insurance Due
format: relative

YAML for template sensor being referenced, which is just referencing a input_datetime helper.
template:
- sensor:
# Car Insurance Due sensor
- name: Car Insurance Due
device_class: timestamp
icon: mdi:card-account-details-star-outline
state: "{{ states('input_datetime.car_insurance_due') }}"
Same issue here, still not fixed
Doesn't work even for secondary:
Simone
Why do you think that the format option must be supported?
It is not mentioned in the docs.
The state’s format is supposed to be defined by a user explicitly inside a state option.
You are mixing the custom card with a conventional row.
Indeed, didn't investigate enough.
Just found a open issue and commented. As it was not closed as "not supported", I was tricked into looking at it.
Fixed using following code:
{{ states(sensor) | as_datetime | relative_time + ' ago'}}
Simone
As it was not closed as "not supported", I was tricked into looking at it.
The author probably has no enough spare time to resolve all open issues. Many users do not read docs with an attention and open “bug” issues instead of asking questions in the Community.