How to migrate from weather integration approach to new weather.get_forecast service?

I recently made a change from using “forecast” to “forecasts” in my configuration, following the suggestions from Taras and ValMarDav also adding ‘weather.forecast_home’ to the attribute definition. However, it seems like the sensor broke again, and I’m encountering an error stating that “hourly” is not defined.

- trigger:
    - platform: time_pattern
      hours: /1
  action:
    - service: weather.get_forecasts
      target:
        entity_id: weather.forecast_home
      data:
        type: hourly
      response_variable: hourly
  sensor:
    - name: Wetter Vorhersage Stündlich
      unique_id: weather_forecast_hourly
      state: "{{ now().isoformat() }}"
      attributes:
        condition: "{{ hourly['weather.forecast_home'].forecast[0].condition }}"
        temperature: "{{ hourly['weather.forecast_home'].forecast[0].temperature }}"
        wind_bearing: "{{ hourly['weather.forecast_home'].forecast[0].wind_bearing }}"
        cloud_coverage: "{{ hourly['weather.forecast_home'].forecast[0].cloud_coverage }}"
        precipitation: "{{ hourly['weather.forecast_home'].forecast[0].precipitation }}"
        humidity: "{{ hourly['weather.forecast_home'].forecast[0].humidity }}"

If I call the service in the developer tools, it pulls the data, so it should be the sensor definition where I made a mistake.

Hi, I tried your code and it works. The only thing I changed is the weather entity.

Hi, thank you for tying it out. I restarted Homeassistant a couple times and now it somehow works. I did not change anything, but now the response variable is recognized. No idea, why it works now, but it works :-). Thank you for your support.

Hello,
I have the same problem. I also restarted teh Homeassistant a couple times, but not solved.

One possible thing to look at, is whether your weather integration has been updated to support the new methods for getting forecast data.
One quick way to check is to goto UI->Developers tools->Services tab and enter something like:

service: weather.get_forecasts
data:
  type: daily
target:
  entity_id: weather.your_weather_entity

If it returns forecast data, then that part is good news.

Can anyone help me how to use forecast with a weather card?

I had a forecast shown on a dashboard for the next 8 hours.
When I use dev tools to check my weather entity, I can see lots of data.

  forecast:
    - condition: cloudy
      precipitation_probability: 0
      datetime: "2024-04-05T18:00:00+00:00"
      wind_bearing: 212
      cloud_coverage: 98
      temperature: 17.3
      pressure: 1016
      wind_speed: 8.75
      precipitation: 0
      humidity: 75

However, when I use a weather card, it does not matter which one, I only see the upcoming temperature but never precipation and preciptation probability.


forecast2

Why does non of my weather cards use that data to show it?

I post this here because the error only come up after updating to 2024.4.

First try the standard Lovelace weather card just to rule out the Lovelace card.

I am having a similar error to @Michael_K001 in that I get the error:
‘UndefinedError: ‘daily’ is undefined’

I’ve put this in my configuration.yaml based on the responses here:

template:
  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecasts
        target:
          entity_id: weather.home_2
        data:
          type: daily
        response_variable: daily
    sensor:
      - name: Daily Weather
        unique_id: weather_forecast_daily
        state: "{{ now().isoformat() }}"
        attributes:
          condition: "{{ daily['weather.home_2'].forecast[0].condition }}"
          temperature: "{{ daily['weather.home_2'].forecast[0].temperature }}"
          wind_bearing: "{{ daily['weather.home_2'].forecast[0].wind_bearing }}"
          cloud_coverage: "{{ daily['weather.home_2'].forecast[0].cloud_coverage }}"
          precipitation: "{{ daily['weather.home_2'].forecast[0].precipitation }}"
          humidity: "{{ daily['weather.home_2'].forecast[0].humidity }}"
          uv_index: "{{ daily['weather.home_2'].forecast[0].uv_index }}"
          templow: "{{ daily['weather.home_2'].forecast[0].templow }}"
          apparent_temperature: "{{ daily['weather.home_2'].forecast[0].apparent_temperature }}"

The service definitely has daily available:

This is using Accuweather. I’ve tried restarting a few times. Not sure what to do next!

It seems OK, so I’m taking a guess, but change the name of your response variable to oh say daily_response and see if that works.

I have tried that one as well. It is the one I used as a temporary replacement.
The humdity that is shown is from current data, not forecast data. :confused:

It looks to me like the standard Lovelace weather card is working… you get forecast (cloudy, sunny), forecast temperature… although its not full featured so I don’t think that card shows daily precipitation probability and others.
As for the Hourly Weather Card, just at a glance looking at the code on github, the author has updated it for the new subscribe weather forecast, so I’m not really sure what to tell you.

BTW when you say dev tools shows lots of data, did you use get_forecasts service call to get that data?

I know that forecasts in general is working, since the non standard weather card also shows the temperature. However, even when selecting precepitation amount, nothing comes up. I don’t think that’s normal, is it? I have not found anyone else with that problem while looking for it online.

I use the service tab so it should be fine I think?

Ok, that looks correct to me. Maybe ask the author of the Hourly Weather Card for help on its github.
The only other thing I could suggest is to try this Animated Weather Card. I use it, it supports the new methods for getting forecasts and it works for hourly (as well for daily).

Ironically, that’s the card I have been using this whole time, until the error started. :frowning:

Thanks for your help though. I appreciate it.

Just to make sure, that card was updated back in December 2023, have you updated it since then?

I hadn’t. However, after it didn’t work anymore I had deleted it and just redownloaded. The other weather cards were all downloaded yesterday so at least one of them should have been up to date.

I’m having the same problem, both with hourly or daily. Did you figure it out?

I’m finding the cards work ok but I can’t get a forecast temperature for tomorrow as a sensor. I use it for my energy consumption prediction to help set battery charge levels. I’ve tried several things (just about everything I can find in the community) and I either get “unavailable”, “unknown” or the current value. It’s probably me missing something. But all I’ve done is change the weather entity to suit my config.

Thanks for your suggestion, that didn’t work unfortunately.

No unfortunately not! I think it must be a bug? Are you using the Accuweather integration as well?