Template not working as expected

Hello, I was thinking about turning on one of the light in the bedroom with a specific color based on daily temperature.

I made a template to test it and it should return a string value based on outside temperature, here it is:

- platform: template
  sensors:
    rgbtemperature:
      friendly_name: RGB Temp
      value_template: >-
        {% if states('sensor.pws_temp_high_1d_c_2')|float > 28 %}
          Hot
        {% elif states('sensor.pws_temp_high_1d_c_2')|float < 19 %}
          Cold
        {% else %}
          Good
        {% endif %}

Right now the sensor.pws_temp_high_1d_c_2 is at 33 but i keep getting “Cold” as output, why?

2 things I’d test.

  1. parenthesis
  2. I wonder if it’s because it’s that string within a string thing.

What does that return?

- platform: template
  sensors:
    rgbtemperature:
      friendly_name: RGB Temp
      value_template: >-
        {% if (states('sensor.pws_temp_high_1d_c_2')|float) > 28 %}
          Hot
        {% elif (states('sensor.pws_temp_high_1d_c_2')|float) < 19 %}
          Cold
        {% else %}
          Good
        {% endif %}

and if still no good, what does that return?

- platform: template
  sensors:
    rgbtemperature:
      friendly_name: RGB Temp
      value_template: >-
        {% if (states.sensor.pws_temp_high_1d_c_2.state | float) > 28 %}
          Hot
        {% elif (states.sensor.pws_temp_high_1d_c_2.state | float) < 19 %}
          Cold
        {% else %}
          Good
        {% endif %}

Last but not least, to confirm what happens when temp equals 28 or 19? You want it to display “good” right?

Honestly, @lolouk44, I don’t think any of those would be issues.

Seems to me that it’s probably a typo in the sensor entity_id. The states() function will return ‘unknown’ if the entity doesn’t exist. And the float filter will return 0.0 if the input string is not a number, which of course, ‘unknown’ isn’t. So, if there’s a typo in the entity_id, the result of this template would be ‘Cold’.

2 Likes

Wow! looks like @pnbruckner was right. Today everithing is working fine right now is 28°C and output is Good

Thanks @lolouk44 for the help :slight_smile: