#What is your goal here
1 messages · Page 1 of 1 (latest)
i have a list of climate entities, i iterate over them and calculate a bolean value true if they need heat and false if they don't
now having this list [true, true, true] i would like to know if any of it is true. i've tried the following
{% set needs_heat = false %}
{% for current in [true, true, true] %}
{% set needs_heat = needs_heat or current %}
{% endfor %}
{{ needs_heat }}
the output is false and i don't know why
You need to use a namespace to use the result of a for loop outside the loop
But you are overcomplicating it
{% set current = [true, true, true] %}
{{ true in current }}
this works
{% set needs_heat = namespace(final_val=false) %}
{% for current in [true, true, true] %}
{% set needs_heat.final_val = needs_heat.final_val or current %}
{% endfor %}
{{ needs_heat.final_val }}
how does {{ true in current }} work? (i'm a developer but i'm new to python / home assistant / templating)
also is there a shorter way if i would like to collapse the list using 'and' operator?
ok so as i understand the in operator tests it the value is in the list