I am trying to add a condition template, and it works without the max filter, but not with it.
{{ states('sensor.amelia_sensor_temperature_measurement') > ([states('sensor.upstairs_temperature'), 71] | max) }}```
I have also tried this syntax,
{{ states(‘sensor.amelia_sensor_temperature_measurement’) > max([states(‘sensor.upstairs_temperature’), 71]) }}```
What I am trying to do is turn on a fan, if the temperature in a room is more than the thermostat temp, not set point, but no less than 71.
Travis
I didn’t test the code, but you need to compare an integer to an integer vs a string to an integer
{{ states('sensor.amelia_sensor_temperature_measurement') |int(0) > ((states('sensor.upstairs_temperature') |int(0), 71) | max) }}
It did end up being a type conversion. I am not sure exactly what type states returns, alone when just comparing two the two states it worked fine, so I am assuming its either a float, or there is type coercion.
Anyway, this works.
{{ states('sensor.amelia_sensor_temperature_measurement') | float(2) <= ([states('sensor.upstairs_temperature') | float(2), 71.00] | max) }}
Thanks for the pointers.
123
(Taras)
June 1, 2024, 4:35pm
4
Every entity’s state
value is a string so the states()
function returns a string value.
Therefore your template attempted to compare string to numbers and that’s invalid.
Because it was comparing two strings which is a valid operation but doesn’t necessarily produce the result you might expect if they’re numeric strings.