Timestamp template not working as sensor, but works in template editor

I do try to create a timestamp template sensor.
This is working in the template editor, but not as sensor.
What am I doing wrong?

the sensor:

as sensor in sensor.yaml:

      value_template: '{{ state_attr("vacuum.xiaomi_vacuum_cleaner", "status") }}'
      icon_template: mdi:list-status
      unit_of_measurement: ""
      friendly_name: "Status"

      value_template: '{{ as_timestamp(states("sensor.xiaomi_vacuum_cleaner_last_clean_start")) | timestamp_custom("%d-%m-%Y %H:%M") }}'
      icon_template: mdi:clock-start
      unit_of_measurement: ""
      friendly_name: "Starttijd"

      value_template: '{{ as_timestamp(states("sensor.xiaomi_vacuum_cleaner_last_clean_end")) | timestamp_custom("%d-%m-%Y %H:%M") }}'
      icon_template: mdi:timer-off-outline
      unit_of_measurement: ""
      friendly_name: "Stoptijd"

the result:

Good it be that creating : sensor.xiaomi_vacuum_cleaner_last_clean_start is delayed after startup and not existing trying to make a template?

Please post your templates using the community standards. It allows folks to test your code without rewriting from a pic.

Please don’t post code as an image. People trying to help have to type it over.

1 Like

Thanks. I will change the question


{{ as_timestamp(states('sensor.xiaomi_vacuum_cleaner_last_clean_start'), 0) | timestamp_custom('%d-%m-%Y %H:%M') }}

Requirement for timestamp device class is:

  • timestamp: Datetime object or timestamp string (ISO 8601)

Yours is neither of those. Use the isoformat() filter to get an ISO8601 string that can be classified as device_class: timestamp.

Also, you are creating legacy-config template sensors (under sensor: domain heading). You should consider rewriting in modern configuration (under template:) — or create them via the UI under Helpers and not have to worry about YAML:

Thanks for the answer