No longer able to pull weather forecasts using the HA REST API

Using the REST API I was able to pull a weather entity state along with the attached forecast. A little while ago (perhaps over the new year) this was removed.

My use case is I have a custom-built dashboard that pulls in state information, including weather over the API.

Here is the weather entity in the UI:

And this is what I get from the API:

{
  "entity_id": "weather.met_office_xxx_daily",
  "state": "partlycloudy",
  "attributes": {
    "temperature": 14,
    "temperature_unit": "°C",
    "humidity": 84,
    "pressure_unit": "hPa",
    "wind_bearing": "WSW",
    "wind_speed": 11.27,
    "wind_speed_unit": "km/h",
    "visibility_unit": "km",
    "precipitation_unit": "mm",
    "attribution": "Data provided by the Met Office",
    "friendly_name": "Met Office xxx Daily",
    "supported_features": 3
  },
  "last_changed": "2024-07-09T19:53:10.313399+00:00",
  "last_reported": "2024-07-09T21:53:10.219105+00:00",
  "last_updated": "2024-07-09T21:53:10.219105+00:00",
  "context": {
    "id": "01J2CQRYJBNX1H4NN4E2GHCX3F",
    "parent_id": null,
    "user_id": null
  }
}

Looking at my implementation there used to be a forecast key under attributes but it has been removed. Any idea how to get this back?

This was change a month or 2 ago. This search will help you find an example that will match your specifics.

site:home-assistant.io weather forecast

This is the weather integration page for further reference.

As this has been discussed at length, please use the forum search as suggested.

Just to get you started, here are two threads:

Sorry, I did try to search but ‘weather rest API’ just gave results about building integrations with external sources. I’d not realised this was more of a core change rather than just an API interface change.

Coming around to actually fix this. This is what I did to restore an API to get weather forecast.

Couple of caveats:

  • Firstly you cannot use POST /api/services/<domain>/<service> to call the weather.get_forecasts service as that API does not support responses. That’s be too easy! This stumped me for a bit as it was just returning a 500 without any detail. There’s a github issue that explains but I’ve closed it already.
  • Use weather.get_forecasts, weather.get_forecast is deprecated.

Define a template sensor. I tried doing this via UI first (helpers tab) and couldn’t get very far, YAML instead:

template:
- trigger:
    - platform: time_pattern
      hours: /1
  action:
    - service: weather.get_forecasts
      data:
        type: hourly
      target:
        entity_id: weather.<YOUR PROVIDER>
      response_variable: hourly
  sensor:
    - name: Weather Forecast Hourly
      unique_id: weather_forecast_hourly
      state: "{{ now().isoformat() }}"
      attributes:
        forecast: "{{ hourly['weather.<YOUR PROVIDER>'].forecast }}"

From Template - Home Assistant

For the first run swap out hours: /1 for minutes: /1 so you have data now rather than on the next hour. Swap back after.

After this call the get sensor API and data is restored!