Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
robertwigley opened this issue Aug 23, 2021 · 5 comments

Comments

@robertwigley
Copy link

robertwigley commented Aug 23, 2021

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
Copy link

Same issue here, still not fixed

@chemelli74
Copy link

Doesn't work even for secondary:

Simone

@ildar170975
Copy link

ildar170975 commented Jan 1, 2023

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
Copy link

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
Copy link

ildar170975 commented Jan 2, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants