Template works under developerstool but not in helper

I have a simple template:

{% if states("sensor.ute_norr_temperature")| float < -10 %}
{{ 150 }}
{% elif states("sensor.ute_norr_temperature")| float < -8 %}
{{ 120 }}
{% elif states("sensor.ute_norr_temperature")| float < -5 %}
{{ 90 }}
{% elif states("sensor.ute_norr_temperature")| float < -3 %}
{{ 60 }}
{% elif states("sensor.ute_norr_temperature")| float < -2 %}
{{ 45 }}
{% elif states("sensor.ute_norr_temperature")| float < 3 %}
{{ 30 }}
{% else %}
{{ 0 }}
{% endif %}

It works with the template tool.
But when I create a Number Template Helper, ther result of the helper is Unknown

{{ states("number.car_preset") }}

I can’t figure out what’s wrong, the temperature has changed and it says it is dependent of the sensor…

Am I blind or missing something?

You probably want a “sensor” template helper. A “number” template helper is for a very specific case where you want to be able to control the value (like a volume control).

1 Like

Oh, that simple ?
I’ll try it.
I thought it was pure logic to use a number…

If you’re interested, here is another way to compose the template (using a dictionary).

{% set t = states('sensor.ute_norr_temperature') | float(99) %}
{{ {        t < -10: 150,
     -10 <= t < -8:  120,
     -8  <= t < -5:   90,
     -5  <= t < -3:   60,
     -3  <= t < -2:   45,
     -2  <= t <  3:   30
   }.get(true, 0) }}
2 Likes