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:
status:
value_template: '{{ state_attr("vacuum.xiaomi_vacuum_cleaner", "status") }}'
icon_template: mdi:list-status
unit_of_measurement: ""
friendly_name: "Status"
clean_start:
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"
clean_stop:
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.
Before we begin…
This forum is not a helpdesk
The people here don’t work for Home Assistant, that’s an open source project. We are volunteering our free time to help others. Not all topics may get an answer, never mind one that helps you solve your problem.
[image]
This also isn’t a general home automation forum, this is a forum for Home Assistant and things related to it. Any question about Home Assistant, and about using things with Home Assistant, is welcome here. We can’t help you with eve…
francisp
(Francis)
June 15, 2024, 8:01am
3
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
Test
{{ as_timestamp(states('sensor.xiaomi_vacuum_cleaner_last_clean_start'), 0) | timestamp_custom('%d-%m-%Y %H:%M') }}
Troon
(Troon)
June 16, 2024, 7:27am
6
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: