Help needed with my temperature state template

Hi, I have made a template for status of our Sauna based on the temperature sensor. I just figured out the templates so I’m very new with these. I just don’t get why this is not workin properly:

sensor:
  - platform: template
    sensors:
      sauna_status:
        friendly_name: "Sauna status"
        value_template: >-
          {% if states('sensor.sauna_temperature') | float < 28 %}
            Cold
          {% elif states('sensor.sauna_temperature') | float >= 28 and states('sensor.sauna_temperature') | float < 65 and is_state('sauna_lampenee','on') %}
            Warm up
          {% elif states('sensor.sauna_temperature') | float >= 28 and states('sensor.sauna_temperature') | float < 65 and is_state('sauna_lampenee','off') %}
            Cool down
          {% elif states('sensor.sauna_temperature') | float >= 65 %}
            Warm
          {% endif %}
         
binary_sensor:
  - platform: trend
    sensors:
      sauna_lampenee:
        entity_id: sensor.sauna_temperature

So the problem is that the states “Warm up” and “Cool down” never become true. I have checked that the temperature value will exeed the limits and the trend sensor becomes on. The state of the template is blank when this condition is on.

Just wondering is there anybody who could tell whats wrong in my code?

1 Like

Here’s some tips before I start trying to fix this:

  • You can split if statements across multiple lines, to increase code readability
  • You can preview templates in the Template part of developer tools.

Now the main thing that pops up is:

and is_state('sauna_lampenee','on')

Try making that is_state('binary_sensor.sauna_lampenee', 'on') and vice versa for the opposite.

2 Likes

If you’re interested, here’s a streamlined version of your Template Sensor.

sensor:
  - platform: template
    sensors:
      sauna_status:
        friendly_name: "Sauna status"
        value_template: >-
          {% set t = states('sensor.sauna_temperature') | float %}
          {% if t < 28 %} Cold
          {% elif 28 <= t < 65 %}
            {{ 'Warm up' if is_state('binary_sensor.sauna_lampenee','on') else 'Cool down' }}
          {% else %} Warm
          {% endif %}
2 Likes

Also what actually turns on the binary sensor you created?

I see no mechanism for that sensor to ever do anything.

One problem at a time. :wink:

1 Like

Hi,

thanks for all of you!

The code was missing “binary_sensor.”:

Also the tips were very useful. I didn’t know the meaning of Template part in developer tools. That will make testing and debugging much easier as you don’t have to reboot the whole system all of the time.

Next i will make the code little bit shorter with your example.

Sauna_lampenee is a binary sensor using trend platform. When the value of sensor.sauna_temperature is increasing the binary sensor is on and when decreasing it’s off. I haven’t used any parameters as I think it’s ok with default configuratuon. Future show is there something to tune.

You don’t even need to reboot the whole system when you have completed your template sensor. You can just reload that template components over the server control.