I have a problem with a template. In the events it works correctly and gives me true and false. In the automation, however, the condition always remains true. Do you have any tips?
{% set scenes = [
'scene.wohnzimmer_naturliches_licht',
'scene.wohnzimmer_herzliche_umarmung',
'scene.wohnzimmer_glanz_und_glamour',
'scene.wohnzimmer_disturbia',
'scene.wohnzimmer_suzuka',
'scene.wohnzimmer_lesen',
'scene.wohnzimmer_nachtlicht',
'scene.wohnzimmer_memento',
'scene.wohnzimmer_witching_hour',
'scene.wohnzimmer_ruhephase',
'scene.wohnzimmer_konzentrieren',
'scene.wohnzimmer_energie_tanken',
'scene.wohnzimmer_entspannen',
'scene.sonos_dashboard'
] %}
{% set scene_aktiv = false %}
{% for scene in scenes %}
{% if (as_timestamp(now()) - as_timestamp(states[scene].last_changed)) < 600 %}
{% set scene_aktiv = true %}
{% endif %}
{% endfor %}
{{ scene_aktiv == false }} # Gibt True zurĂźck, wenn keine Szene aktiv ist
That template cannot possibly give the results you are expecting due to how Jinja variable scope works. Whatever variables you change inside the loop will not be visible to the outside. The way around this is to use a namespace(), see âScoping Behaviorâ in the Jinja documentation.
I entered the template in the events. It only gives me false. But the condition is never fulfilled in the automation.
Ergebnis
UndefinedError: 'scenes' is undefined
false
Ergebnistyp: string
Dieses Template abonniert die folgenden Ereignisse zur Zustandsänderung:
Entität: light.hue_play_rl
Entität: scene.wohnzimmer_naturliches_licht
I have this when I activate a scene. Unfortunately, it doesnât trigger the natural light scene because Hue then controls individual light scenes.
You need to combine the first part of your original template, thatâs the part that defines the scenes variable containing a list of scenes, with the template Didgeridrew suggested.
Without your initial definition of the scenes variable, the result of Didgeridrewâs template will be the error message you received.
Post the complete automation showing where you have added the template.
I have now inserted the whole thing. Everything works in the events, but in the automation the condition always remains fulfilled, even though it goes to false.where is my mistake in thinking?
So when I test the template in the template editor, the scenes are set to false, as it should be. But if I use the whole thing as a condition in the AM, it always shows me that the condition is met, even though a scene is active. The motion detector should not change the light if I activate a scene manually. The motion sensor should only be active again when the lights are turned off by the motion sensor, app or switch.
If you mean youâre in the Automation Editor in Visual mode and using the Test button to test the Template Condition, then I suggest you ignore what it reports. It merely checks if the Template Condition is functional.
I check this in editor mode directly in the AM under the conditions. There it always shows me that the condition is met. If I now activate a scene, the motion sensor immediately switches the light back to the standard values.