Hi,
I want to output a date in a template but always get rendered invalid date.
How must I output my date (in this moment as string like ‘13.05.23’) to match the device_class date and the expected date object?
Thanks, Steffen
Hi,
I want to output a date in a template but always get rendered invalid date.
How must I output my date (in this moment as string like ‘13.05.23’) to match the device_class date and the expected date object?
Thanks, Steffen
Thank you I know the instructions, but I haven’t had any success so far. That’s why I asked here …
My only timestamp template (copied from somewhere ) is:
- sensor:
- name: "Last reboot"
state: "{{ as_timestamp(states('sensor.last_boot')) | timestamp_custom('%d %B %Y at %H:%M') }}"
There’s a bit in the templating docs:
It would help considerably if you shared the template you are using, but basically ISO 8601 format. See the warning box at the end of this section : Templating - Home Assistant
I try many converts but did not find the right one but here is the template, but the only problem is how have the output must format for a device_class date. I think the device_class date must a special format and I do not know how to create it from a simple date string:
sensor:
- unique_id: tmp_nextdate_urlaubskalender
name: tmp_nextdate_urlaubskalender
device_class: date
icon: mdi:calendar-search
state: >-
{% set nextoffset = namespace(found = false, offset = 999, date = '') %}
{% for scheduler in integration_entities('scheduler') %}
{% if 'Urlaub' in state_attr(scheduler,'tags') %}
{% if not (state_attr(scheduler,'next_trigger') in ['unavailable', 'unknown', 'none']) %}
{% set today = as_timestamp(now()) %}
{% set next = as_timestamp(state_attr(scheduler,'next_trigger')) %}
{% set offset = ((next-today)/86400) | round(0,'ceil') %}
{% if offset < nextoffset.offset %}
{% set nextoffset.found = true %}
{% set nextoffset.offset = offset %}
{% set nextoffset.date = next %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% if nextoffset.found == true %}
{{- nextoffset.date | timestamp_custom('%d.%m.%y') -}}
{% else %}
{{- none -}}
{% endif %}
Attention: Not device_class: timestamp only date!
I got is, very simple and I thinking complicated to create a object:
{{- nextoffset.date | timestamp_custom('%Y-%m-%d') -}}