Am I in the right place in the forum
Hello, for several days I have been trying to resolve the malfunction of this template. I made several versions and carried out numerous tests, but without results. My goal is for the Then or Else switch to work correctly. I need help. THANKS
Purpose of these instructions: to validate whether the automation was executed today. If so, we stop. If not, we continue.
{% set last_run = states(‘input_datetime.last_off_cd_matin_interieur_1er_2e’) %}
{% if last_run == ‘unknown’ or last_run == ‘unavailable’ %}
{{ true }} # Si aucune valeur n’est disponible (cas initial ou erreur), retourner vrai
{% else %}
{% set last_run_date = strptime(last_run, “%Y-%m-%d %H:%M:%S”).date() %}
{% set now_date = now().date() %}
{{ last_run_date != now_date }} # Si les dates ne correspondent pas, retourne vrai
{% endif %}
Looks like TRUE is not considered by IF
Another clarification, the variable “input_datetime.last_off_cd_matin_interieur_1er_2e” is initialized at each execution of the automation by the following instructions:
action: input_datetime.set_datetime
metadata: {}
data:
datetime: >-
{{
(state_attr(‘automation.eclairage_fermeture_luminosite_exterieure_lux_atteint_2’,
‘last_triggered’) | as_datetime | as_local).strftime(‘%Y-%m-%d %H:%M:%S’) }}
target:
entity_id: input_datetime.last_off_cd_matin_interieur_1er_2e