thomasloven / lovelace-template-entity-row

🔹 Display whatever you want in an entities card row.
MIT License
210 stars 16 forks source link

'format' variable ignored for sensors with device_class of 'timestamp' #62

Open robertwigley opened 2 years ago

robertwigley commented 2 years ago

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

image

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') }}"
mateuszdrab commented 2 years ago

Same issue here, still not fixed

chemelli74 commented 1 year ago

Doesn't work even for secondary:

Simone

ildar170975 commented 1 year ago

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.

chemelli74 commented 1 year ago

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

ildar170975 commented 1 year ago

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.