tarbax
1
my template does not work any idea what i am doing wrong ?
- platform: template
sensors:
vochtshakelaaraan:
friendly_name: "vochtshakelaar aan"
value_template: "{{ ([states.sensor.sn1_humidity.state, states.sensor.sn2_humidity.state, states.sensor.sn3_humidity.state, states.sensor.sn4_humidity.state, states.sensor.sn5_humidity.state] | average - states.sensor.sn8_humidity.state | float) > 10 }}"
petro
(Petro)
2
- You need to be on 2021.11 for average to work.
- average requires numerical values. states are not numerical values, they are strings
- You should use expand instead of states.x.y.state, as that will not error when starting up.
- You should verify that you have all your states before performing the math
- You need to provide default values for when the sensors are unavailable and converting to a float.
value_template:
{% set entities = 'sensor.sn1_humidity', 'sensor.sn2_humidity', 'sensor.sn3_humidity', 'sensor.sn4_humidity', 'sensor.sn5_humidity' %}
{% set sensors = expand(entities) | map(attribute='state') | map('float', none) | reject('eq', none) | list %}
{% set sensor8 = states('sensor.sn8_humidity') | float(none) %}
{% if sensors and sensor8 is not none %}
{{ sensors | average - sensor8 > 10 }}
{% else %}
False
{% endif %}
1 Like