2025.12 template change issues

I have previously used very simple template to calculate so called heating number, which I use for certain energy related optimizations. However, 2025.12 version of Home Assistant changed the way statistics are collected and saved, and changes were made to templates too, if I have understood it correctly.

The code below output float before 2025.12. After 2025.12, it outputs string and messes rest of template, because one can’t perform math operations with strings, which is logical:
{% set temp_ave = states('sensor.24h_average_outdoor_temp') | default(0) | float %}
sensor.24h_average_outdoor_temp likely to float, because it’s source is HomeAssistant’s builtin Filter (moving average), which in turn receives temp from my EcoWitt weather staion in float/measurement form.

I have tried to study how to correct the code line above to work with current versions. I have tried float/default commands in different order in dev tools, only result being different errors. This is propably very simple thing to fix, but I just don’t know, how to change that line of code. Any help is greatly appreciated!

EDIT
complete template below, as well as error:

      {% if now().month <= 6 and states('sensor.24h_average_outdoor_temp') | float >= 10 %}
        0
      {% elif now().month <= 6 and states('sensor.24h_average_outdoor_tempa') | float < 10 %}
        {{ 17 - temp_ave }}
      {% elif now().month >= 7 and states('sensor.24h_average_outdoor_temp') | float >= 12 %}
        0
      {% else %}
        {{ 17 - temp_ave }}
      {% endif %} 

produces error:
ValueError: Template error: float got invalid input ‘unknown’ when rendering template ‘{% if now().month <= 6 and states(‘sensor.24h_average_outdoor_temp’) | float >= 10 %} 0 {% elif now().month <= 6 and states(‘sensor.24h_average_outdoor_tempa’) | float < 10 %} {{ 17 - temp_ave }} {% elif now().month >= 7 and states(‘sensor.24h_average_outdoor_temp’) | float >= 12 %} 0 {% else %} {{ 17 - temp_ave }} {% endif %}’ but no default was specified

What exactly are the error messages that you’re getting? I tried this with your template and |typeof returned float, so it should be working with any valid numeric string.

{% set temp_ave = '21.5' | default(0) | float %}
{{ temp_ave|typeof }}

It would be more helpful if you shared the whole template/config that is having issues rather than a single line.

There’s nothing particularly wrong with the template you shared, but it would be better to use the default option in the float filter…

{% set temp_ave = states('sensor.24h_average_outdoor_temp') | float(0) %}

Is that a typo, the others don’t have an “a” at the end…?

If it is, you could reduce your template quite a bit and make it a little bit more efficient using a couple variables:

{% set 24h_avg = states('sensor.24h_average_outdoor_temp') | float(0) %}
{% set month = now().month %}
{% if (month <= 6 and 24h_avg >= 10) or (month >= 7 and 24h_avg >= 12) %}
  0
{% else %}
  {{ 17 - temp_ave }}
{% endif %}

There was a typo too, but at the end, float(0) instead of float did the trick!

FYI, float with a default has been a requirement for almost 3 years now. Not sure how you’re just getting this error now.