Value template not generating the expected output but doesnt error

I have created a few trigger and value templates in the past and i thought i understood them, but with the current one i am creating i must me missing something and would very much appreciate some assistance in getting it working.

I am trying to check whether the current temperature attribute on my TRV is greater than a numeric helper + offset. The individual lines work in the dev tools template editor however the comparison although doesnt error doesnt calculate correctly as it seems to not use the value of the input_number but instead takes the default value of 0.

{{ state_attr('climate.bedroom_radiator', 'current_temperature')}}
{{ states('input_number.bedroom_heat_temperature') | int + 3}}

{{ state_attr('climate.bedroom_radiator', 'current_temperature') > ( 'input_number.bedroom_heat_temperature'| int(0)) + 3}}

I have also added a screenshot of the current outputs. If i change the 0 in the brackets to 16 then the comparison will go false, leading me to deduce it’s not taking the input number value but just using the default of 0.

What am i doing wrong here?

You’ve missed the states() off the input_number in the comparison, and the brackets are a bit wonky. You want:

{{ state_attr('climate.bedroom_radiator', 'current_temperature') > states('input_number.bedroom_heat_temperature')|int(0) + 3 }}

It didn’t throw an error because it’s not invalid, just not what you want. The |int(0) returns 0 because it’s failed to convert the entity ID string to a number, so the comparison reduces to {{ 18.5 > 3 }} which is true.

Oh man… how did I miss the states… I had it in the separate lines. The reason for the initial wonky brackets was I wasn’t sure if it was calculating something before adding the 3.

Works like a charm.

1 Like