I’ve been trying to solve this but could not succeed.
I want to calculate state only of the templated sensor only if the states of all of the 3 sensors are 20 or more, otherwise the templated sensor must be 0 (zero)
Only if the sum is greater than 20. Otherwise report 0.
state: >
{% set total = expand('sensor.dng0a4702r_pv2_watt', 'sensor.cmg4bd702g_pv1_watt', 'sensor.dng0a4702r_pv1_watt')
| map(attribute='state') | map('float', 0) | sum | round(0) %}
{{ iif(total >= 20, total, 0) }}
Only if each sensor’s value is greater than 20. Otherwise report 0.
state: >
{% set total = expand('sensor.dng0a4702r_pv2_watt', 'sensor.cmg4bd702g_pv1_watt', 'sensor.dng0a4702r_pv1_watt')
| map(attribute='state') | map('float', 0) | list %}
{{ iif(total | min >= 20, total | sum | round(0), 0) }}