A lot has changed in Home Assistant since April 2020. The most important is that a Template Sensor no longer supports the entity_id
option.
In other words, this:
entity_id: sensor.date
can be safely removed because it is ignored by Home Assistant.
Another change is that Template Sensors support the now()
function. If it is present in the template, it causes the template to be evaluated every minute.
Whereas in the past, the examples shown above would be evaluated only when sensor.date
changed state, in other words at the start of every new day (midnight), they are now evaluated every minute because they include the now()
function. Instead of being evaluated once a day, at midnight, it is now evaluated 1440 times a day.
The most recent version of Home Assistant (2021.4) introduced the concept of Trigger-based Template Sensors. It allows you to use a trigger to specify precisely when a Template Sensor should be evaluated.
The original example can be redesigned as a Trigger-based Template Sensor like this:
template:
- trigger:
- platform: time
at: '00:00:00'
- platform: homeassistant
event: start
sensor:
- name: 'Jour FR'
state: >
{% set jours = ["Lundi", "Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche"] %}
{{ jours[now().weekday()] }}
It will be updated only at midnight and whenever Home Assistant starts.
Your example can also be redesigned as a Trigger-based Template Sensor (see documentation):
template:
- trigger:
- platform: time
at: '00:00:00'
- platform: homeassistant
event: start
sensor:
- name: 'Date du jour'
icon: mdi:calendar-today
state: >
{% set months = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"] %}
{% set days = ["Montag", "Dienstag", "Mittwoch", "Donnestag", "Freitag", "Samstag", "Sonntag"] %}
{{ days[now().weekday()] }}, der {{ now().day | string }}. {{ months[now().month-1] }}