lovelace-template-entity-row icon indicating copy to clipboard operation
lovelace-template-entity-row copied to clipboard

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

Open robertwigley opened this issue 4 years ago • 5 comments

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') }}"

robertwigley avatar Aug 23 '21 15:08 robertwigley

Same issue here, still not fixed

mateuszdrab avatar Mar 27 '22 10:03 mateuszdrab

Doesn't work even for secondary:

Simone

chemelli74 avatar Jan 01 '23 23:01 chemelli74

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.

ildar170975 avatar Jan 01 '23 23:01 ildar170975

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

chemelli74 avatar Jan 01 '23 23:01 chemelli74

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.

ildar170975 avatar Jan 02 '23 00:01 ildar170975