I would like to use today's forecast maximum temperature from OpenWeatherMap v3 integration (as displayed on the standard Home Assistant Weather card) but can't seem to get it. I have tried multiple approaches from the forums and wider, including automation to get the forecast and then try to store the value in a helper - but none of these approaches work, most of which simply don't see any values whatever way I look to get them!
There surely must be a simple way to access the information that is already there in the current Weather card?
I know this is quite an open question, but I have spent the last 4 hours trying to get this sorted with so many different approaches from so many places (too many to list or remember now) - and hope that there is a simple (and simple to implement) way to get this value to be used in automations.
Can you show what you already tried?
You'll need to use the weather.get_forecasts action, and then use the action response in a jinja template to get today's maximum temperature.
If you show your automation attempt, we can probably point out where it went wrong
BTW instead of an automation, you could also use a triggered based template sensor. The logic will basically be the same in the end.
For info (and in case it's really obvious what I was doing wrong), I had an Input Number Helper (input_number.forecast_max_day_temp) to store the value and the following automation:
It does try to set the value which I can then use later:
The working approach was to add the following to /homeassistant/templates.yaml (and adding template: !include templates.yaml in the configuration.yaml file)
# Sensor to fetch and store the DAILY weather forecast
- trigger:
- platform: time_pattern
hours: "/1" # Update every hour
- platform: homeassistant
event: start
action:
- service: weather.get_forecasts
data:
type: daily
target:
entity_id: weather.openweathermap
response_variable: forecast_daily
sensor:
- name: "Weather Daily Forecast"
unique_id: weather_daily_forecast
state: "{{ now().isoformat() }}"
attributes:
forecast: "{{ forecast_daily['weather.openweathermap'].forecast }}"
# I replaced this with max_temp as that was all I needed and made the helper even easier
max_temp: "{{ forecast_daily['weather.openweathermap'].forecast[0].temperature }}"
Then, for my use, I setup a template number helper with the following template: {{ state_attr('sensor.weather_daily_forecast', 'max_temp') | round(1)}}
but could also do this with if the forecast attribute was there (which has loads of other things) {{ state_attr('sensor.weather_daily_forecast', 'forecast')[0].temperature | round(1)}}
The examples you posted indicate they are executing weather.get_forecaststwice.
In the Trigger-based Template Sensor, where the action’s response is used to create values for two attributes: forecast and max_temp.
In the automation, where the action’s response is not used. This is what I had mentioned in my previous post. It’s unnecessary to use weather.get_forecasts in the automation because it’s getting its value from the Trigger-based Template Sensor.
In fact, the automation is unnecessary because you can use the number.set_value action directly within the Trigger-based Template Sensor (immediately after executing weather.get_forecasts).