Template sensor stops working when updating HA Core

Hi,

I have the following sensor which has been working for months (probably not the greatest way to do it but Im amateur). Currently on version 2024.3.1 but when updating to latest version the sensor no longer returns any values. How can I find out whats causing the problem? Ive restored a backup so working again for now.

Thanks

  - platform: template
    sensors:
        wiser_forecast:
          friendly_name: "Wiser Forecast"
          value_template: >
            {% set time = state_attr('weather.openweathermap', 'forecast')[0]['datetime'] %}
           
            {% if (( time | as_datetime |as_local - now()).seconds / 60) |int >=120 %}
    
            {% set temp = (state_attr('weather.openweathermap', 'temperature') | float + state_attr('weather.openweathermap', 'apparent_temperature') | float) /2 %}
            {% else %}
            
            {% set temp = (state_attr('weather.openweathermap', 'forecast')[0]['temperature'] | float + state_attr('weather.openweathermap', 'apparent_temperature') | float) /2 %}

            {% endif %}
   
            
            {% if temp <= states('input_number.winter_temp') | float %}
            Winter
            {% elif  temp  > states('input_number.winter_temp') | float and  temp  <= states('input_number.autumn_spring_temp') | float %}
            {% set month = now().month %}
            
            {% if month >1 and month <=6 %}
            {% set temp2 = states('input_number.winter_temp') | float  + (states('input_number.autumn_spring_temp') | float - states('input_number.winter_temp') | float )/2  %}

            {% if temp <= temp2 %}
            Early Spring
            {% else %}
            Spring
            {% endif %}
            
  
            {% else %}
            {% set temp2 = states('input_number.winter_temp') | float  + (states('input_number.autumn_spring_temp') | float - states('input_number.winter_temp') | float )/2  %}

            {% if temp <= temp2 %}
            Autumn
            {% else %}
            Early Autumn
            {% endif %}
            
            {% endif %} 
            {% else %}
            Summer
            {% endif %}
          attribute_templates:
            Actual_Temp:  "{{ state_attr('weather.openweathermap', 'temperature') }}"
            Feels_Like_Temp: "{{state_attr('weather.openweathermap', 'apparent_temperature')}}"
            Forecast_Temp: " {{ state_attr('weather.openweathermap', 'forecast')[0]['temperature'] }}"
            Wiser_Forecast_Temp: >
                {% set diff = state_attr('weather.openweathermap', 'temperature') | float - state_attr('weather.openweathermap', 'apparent_temperature') | float %}
                {% set temp = (state_attr('weather.openweathermap', 'forecast')[0]['temperature'] | float +  state_attr('weather.openweathermap', 'apparent_temperature')) /2 %}
                {{ temp | round(1) }}
            Temp_From: >
                {% set time = state_attr('weather.openweathermap', 'forecast')[0]['datetime'] %}
                {% if (( time | as_datetime |as_local - now()).seconds / 60) |int >=120 %}
                Feels Like Temp
                {% else %}
                Wiser Forecast
                {% endif %}

There was a long standing change for the weather providers. The weather entity doesn’t contain a forecast attribute anymore, you’d need to use “weather.get_forecasts”.

Please do a search for “weather forecasts”, as this has been discussed already in multiple threads.

Like this one here:

or this one

Thanks!

Looks like that might be too much for me to figure out. Like I said Im relatively new to HA so dont think Id be able to get that working. Guess I just wont upgrade for as long as possible.

Thanks for the reply

Looking at those or a little bit of searching and you might find some that has shared what you want exactly. I see hundreds of examples here. A search in your search engine like:

site:home-assistant.io weather forcast

Will find a lot to start, tweak the search from there.

Stopping your update cycle cannot end well. You can see it has already broke your system.

Not updating isn’t really an option, as you’ll likely run into problems, rather sooner than later, and you’re missing out on a lot of cool new functions! HA is making big steps in the last months, and will do so in the future. :slight_smile:

So, no, that’s not an option! :slight_smile:

However, where did you even get that code for a template sensor? It seems a little “strange” on a first glance. Strange in the best possible way! :slight_smile:

Maybe you give us an idea, what you really do with this sensor, so we can find an alternative for you. :slight_smile:

From what I see, this is a season sensor, depending on some temperatures. And at the end there are some sensors as well. These are strange as well, as in one sensor something gets calculated, but isn’t used…

Anyway, please give us a good idea, for what you need this, and especially where you use this! Maybe some things in that template sensor aren’t even necessary.