Home Assistant logo

Home Assistant 2024.4 changes weather forecasts – what to do?

3 min read.

This article explains how to fix your template sensors, automations and other functionality that is broken by the 2024.4 update of the Home Assistant platform, where forecasts are removed from weather entities. Fixing the issue requires some YAML, and while you’ll loose debuggability and possibly encounter some performance hits and run awry of your weather provider’s rate limits, what wouldn’t we do to keep up-to-date with the latest community goodness of Home Assistant? 😀

Background

The Home Assistant 2024.4 update introduced some significant changes to how weather forecasts are handled.

Supposedly, these changes are part of Home Assistant’s efforts to provide better organization and functionality, so once you’ve made the necessary adjustments, you should be able to enjoy the improved experience.

I don’t know – seems a bit frustrating to me.

But my opinion doesn’t matter. Let’s figure out how to fix the issue!

Problem

The change makes weather entities lose their “forecast” attribute, and hence breaks all templates, automations, customizations and such that are relying on the attribute.

Hence, any time you’re doing something along the lines of state_attr(‘weather.climacell_daily’, ‘forecast’), your stuff will break. And trust me, I had plenty of sensors like this to enable my automations 😄 And these sensors will simply be unavailable or otherwise broken.

The solution is wordy (you’ll need more YAML than you’ll like), but at least it’s pretty straightforward.

Solution

Here’s a rough outline of what to do (and I’ll share code samples below):

  1. Update Your Configuration: Update your configuration.yaml file to include a new template that triggers the weather.get_forecasts service to fetch the forecasts at your desired interval.
  2. Use the New Service: Replace the deprecated forecast attribute with the weather.get_forecasts service call, which allows you to specify the type of forecast you want, such as daily or hourly.
  3. Modify Your Automations: If you have automations that rely on weather forecasts, you’ll need to adjust them to work with the new service and data structure.
  4. Check the Community Forum: For detailed instructions and community support, visit the Home Assistant Community Forum. There, you can find templates and examples provided by other users who have made similar changes.
  5. Report Issues: If you encounter any problems with the new service not updating information as expected, it’s recommended to log an issue for that integration.

The code samples below are from my Home Assistant’s production configuration (although I did simplify them just a little bit).

Old model

This is the pre-2024.4 version.

# in my sensors.yaml file (mapped to "sensor:")
- platform: template 
  sensors:
    temperature_offset_colder_forecasted:
      friendly_name: "Forecast colder for tomorrow"
      unique_id: sensor.temperature_offset_colder_forecasted
      unit_of_measurement: "°C"
      value_template: >
        {% if (state_attr('weather.climacell_daily', 'forecast')[1].temperature + 5) < state_attr('weather.climacell_daily', 'forecast')[0].temperature %}
          1.5
        {% elif (state_attr('weather.climacell_daily', 'forecast')[1].temperature + 1) < state_attr('weather.climacell_daily', 'forecast')[0].temperature %}
          0.5
        {% else %}
          0.0
        {% endif %}

This doesn’t work anymore.

New model

Below, is my simple and elegant, 2024.4-compatible solution. Don’t you love it, when you suddenly need 3 times more code, that now turns into completely undebuggable, and an extra network roundtrip to achieve the same thing that “just worked” before, only because an open-source dependency (well, a platform, really) decided to introduce breaking changes? 😁

Anyway – essentially, you’ll create a trigger that pulls forecasts any time a weather entity changes. I guess this could lead to you likely hitting rate limits of your weather provider, so make sure to check your statistics and make adjustments if need be.

You’ll store the pulled forecasts into a new, otherwise empty entity (I’ll call mine weather_forecast_daily and weather_forecast_hourly for daily and hourly forecasts, respectively) and replace your earlier entities (like weather.climacell_daily and weather.climacell_hourly) with the newly created ones.

Below, I’ll show you a sample that I found online and adjusted (see “References”).

# In my configuration.yaml file
# Helper entities to fix Home Assistant 2024.4 breaking forecasts
template:
  trigger:
    - platform: state
      entity_id: weather.climacell_daily  # this is my weather provider
    - platform: homeassistant
      event: start
  action:
    - service: weather.get_forecasts
      data:
        type: daily  # change to hourly if you want hourly forecasts
      target:
        entity_id: weather.climacell_daily
      response_variable: fc2
  sensor:
    - name: Weather Forecast Daily
      unique_id: weather_forecast_daily
      state: "{{ now() }}"
      attributes:
        forecast: "{{ fc2['weather.climacell_daily'].forecast }}"    # note the array index with the weather provider name. This is what is different with get_forecasts (plural)

And this is how to use it (instead of the original weather entity):

# in my sensors.yaml file (mapped to "sensor:")
- platform: template 
  sensors:
    temperature_offset_colder_forecasted:
      friendly_name: "Forecast colder for tomorrow"
      unique_id: sensor.temperature_offset_colder_forecasted
      unit_of_measurement: "°C"
      value_template: >
        {% if (sensor.weather_forecast_daily.forecast[1].temperature + 5) < sensor.weather_forecast_daily.forecast[0].temperature %}
          1.5
            {% elif (sensor.weather_forecast_daily.forecast[1].temperature + 1) < sensor.weather_forecast_daily.forecast[0].temperature) %}
          0.5
        {% else %}
          0.0
        {% endif %}

And that should be it.

References

mm
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments