Template sensor takes 40 mins to update

I have a template sensor that returns the lowest of two outdoor Huw Motion Sensor temperatures. I have this as they are located at the front/back of my house and the cooler one is the one out of the sun and therefore measuring ‘air’ temperature.

- name: "Outside temp"
  device_class: temperature
  unit_of_measurement: °C
  state: >
    {% if states('sensor.front_temp') <= states('sensor.patio_temp') %} {{ states('sensor.front_temp') |round(1) }}
      {% else %} {{ states('sensor.patio_temp') |round(1) }}
      {% endif %}

Today I noticed that before 08:52:20, sensor.patio_temp was marginally lower & sensor.outside_temp reflected that correctly at 9.9°C.

At 08:52:20, sensor.patio_temp became warmer but sensor.outside_temp did not flip. sensor.patio_temp continued to rise at a steady rate for the following 40 mins.

At 09:37:15 sensor.patio_temp reported 21.9°C

At 09:41:06 sensor.outside_temp finally flipped to report the cooler sensor.front_temp of 10.3°C

Can anyone help me understand the 40 minute delay given that both sensors update every 5mins and I have other template sensors that respond immediately?

Probably because you are comparing text values.
Make them floats when comparing and it will most likely work as expected.

You could also just make the state:

{{ [states('sensor.front_temp') | float, states('sensor.patio_temp') | float] |min }}
1 Like

thanks! I will give that a go and report back :slight_smile:

edit: I always thought that round(1) resulted in a number and not a text version of a number,

edit: got it - you are referring to the 1st line - thanks!

Perhaps it does…
But this is where you are comparing text:

{% if states('sensor.front_temp') <= states('sensor.patio_temp') %}

2 is less than 9, so it flipped when that happened. You aren’t comparing numbers, but strings like @Hellis81 said.

String comparision starts left and moves right. So the first character is 2 <= 9 is when it would have triggered.

1 Like

You are quite right - I realised it and added an extra edit to my original reply just as you posted this.

thanks, Petro.