Customized format of a sensor date

Hi all,

I wanted to show the timestamp of a sensor date in a customizes format. I found a solution, but this is a vey complicated way. If there is anyone who can shorten my code to better onde, please let me know. I think the part, do extract month, day and year from the sensor is too complicated and needs to be reworked.

Here is what I have:

DST:
{{ now().timetuple().tm_isdst > 0 }}

{%set d=(as_timestamp(states("sensor.daylight_savings_next"))|timestamp_custom('%d'))|int%}
{%set t=(as_timestamp(states("sensor.daylight_savings_next"))|timestamp_custom('%m'))|int%}
{%set y=(as_timestamp(states("sensor.daylight_savings_next"))|timestamp_custom('%Y'))|int%}
{% set dst_date = now().replace(day=d, month=t, year=y)%}
nächste Zeitumstellung:
{{ days[dst_date.weekday()]}}, {{dst_date.day | string }}. {{months[dst_date.month-1]}} {{dst_date.strftime('%Y')}}

Results:
image

For formatting dates, you want the strftime function.

{{ now().strftime("%A, %d. %B %Y") }}

Results in

Thursday, 14. November 2024

More info here.

thanks,

but this is working for now() bit not for a sensor. And I need it in german language

{{states(“sensor.daylight_savings_next”).strftime(“%A, %d. %B %Y”) }}