Retrieve highest forecasted temperature from a weather entity

I used to be able to retrieve the max forecasted temperature for the current day in an automation by accessing {{ state_attr('weather.openweathermap_2', 'forecast') | map(attribute='temperature') | max }}. But when I try accessing the max forecasted temperature, I am unable to retrieve a value. When opening the weather sensor in the entities view, I am able to view the max forecasted temperature, so this issue should not be related to missing sensor data.

If anyone knows what the right way is to retrieve this data, please help :slight_smile:

The forecast attribute in weather entities has been removed some time ago.
You need to access the data through a service now: Weather - Home Assistant

With the removal of the forecast attribute it does make this a bit harder, but the solution is to use the get_forecasts method to populate a sensor that has a forecast attribute and then you are back to where you were before.

trigger:
  - platform: time_pattern
    minutes: /5
  - platform: homeassistant
    event: start

action:
  - service: weather.get_forecasts
    data:
      type: daily
    target:
      entity_id: weather.openweathermap
    response_variable: owm_daily
sensor:
  - name: Legacy Forecasts
    state: "{{ states('weather.openweathermap') }}"

    attributes:
      forecast: "{{ owm_daily['weather.openweathermap'].forecast }}"

Firstly, thank you both for your help. I think I need some more help. Do I have to create an automation with this configuration:
trigger:

  • platform: time_pattern
    minutes: /5
  • platform: homeassistant
    event: start

action:

  • service: weather.get_forecasts
    data:
    type: daily
    target:
    entity_id: weather.openweathermap
    response_variable: owm_daily
    sensor:

  • name: Legacy Forecasts
    state: “{{ states(‘weather.openweathermap’) }}”

    attributes:
    forecast: “{{ owm_daily[‘weather.openweathermap’].forecast }}”

or do I have to save it in the configuration.yaml? Thanks in advance! :wink:

Hi, welcome to the forum.
You need to create a template.

A little search on the forum reveals the answers Search results for 'forecast weather template' - Home Assistant Community

Neither.
You just need to call the service in the specific automation you use. Creating a separate template sensor and automation defeats the initial purpose why the get_forecasts service was introduced: to only retrieve the data when it is actually needed.

Thanks a lot, I was now able to get my weather forecast up and running :grinning:

From what I understand about the code, we are also getting the forecast when getting the current weather: core/homeassistant/components/openweathermap/coordinator.py at cb97085e48139c77fa6b70ea509aee2271233075 · home-assistant/core · GitHub

So when the user opens the weather card, we are displaying the forecast from our last query: core/homeassistant/components/openweathermap/weather.py at cb97085e48139c77fa6b70ea509aee2271233075 · home-assistant/core · GitHub

So at least for the OpenWeatherMap integration, it made zero sense to remove the forecast values. I suspect that the weather.get_forecasts service uses the same function, so calling it every couple minutes doesn’t increase the API usage but I’ll only be sure once I check my API usage statistics tomorrow.

Would you mind sharing your code for your automation? I’m still stuck on this one.