You don’t need a data template, just the value template. Since now() has a weekday() method, you can use that to directly map into a list of abbreviated localized weekday names:
We simply prepend the mapped localized day name to the custom timestamp here.
The weekday() method of a Python date or datetime object returns the day of the week as an integer, where Monday is 0 and Sunday is 6. Thus, it can be easily used as a list index for the days list (lists start with index 0).
Here’s a little challenge: Try to rewrite the above so it returns the abbreviated German weekdays plus a German month name, like Fr 31. Juli.
Hints:
Set up a list called months with the German month names.
now() also has an instance attribute called month → now().month. It returns the month numbers 1–12.
Remember, list indexes start at zero.
The ~ operator in Jinja (the templating engine) concatenates strings, converting values to type string on the fly.
Have fun!
Edit: Strictly speaking, it is not necessary to update a date info every minute, as we do by specifying sensor.time as entity ID to watch.
So if you have sensor.date defined, use that instead. It will update only once per day, at midnight. This will save another few of the precious CPU cycles …
The problem is it gives me the wrong Month (1 Month ahead) and there are also brackets.
(‘22’,‘Dezember 2020’)
Do you know any Solutions?
I’m new to HomeAssistant and have no idea how to solve it.
Kind regards
Hannes
i tested the code that you posted, the list says when i use for example %A for the weekday he takes my selected language in HA, but he always make the weekday english, my language is german.
this gives me the day as number, i think this is needed for the days variable. (its one day to much but i think i can adjust it with -1 because he counts from 0)
I tried my best knowledge, I don’t want to let anyone do the work for me here, or annoy me. but I needed the missing hint, what I just don’t know I can’t conjure up. that’s how you learn. I think that’s what the forum is for. nevertheless thank you very much
Wrap the sensor’s entity_id in quotes (without the quotes it’s handled as the name of an undefined variable) and remove device_class: timestamp (a timestamp sensor’s value must contain the date and time and this template is only providing the time).