Marck
(Marck)
May 3, 2024, 9:25am
1
In the past I could use this to get the forecast temperature for the day, but that returns a ‘null’ now (note: I’m using a template to get the values):
{{state_attr('weather.openweathermap', 'forecast')}}
In the integration I see a array with forecast and multiple hourly temperatures, but how can I access this? Like this:
Maybe it has something to do with the legacy forecast that was removed here: Remove deprecated forecast attribute from WeatherEntity (#110761) · home-assistant/core@6523090 · GitHub
Or the issues with the configuration itself here: OpenWeatherMap only works on Hourly · Issue #114508 · home-assistant/core · GitHub
Any thoughts?
yes, that method is deprecated.
you need to use get_forecast to fetch it now.
example for how here:
pkscout
(Kyle Johnson)
May 3, 2024, 9:44am
3
I’m using the daily forecast from OpenWeatherMap, but maybe this will help get you pointed in the right direction.
- trigger:
- platform: time_pattern
hours: /1
- platform: homeassistant
event: start
action:
- service: weather.get_forecasts
data:
type: daily
target:
entity_id: weather.openweathermap
response_variable: response
sensor:
- name: Weather Forecast
unique_id: 0a7476cc-d6c1-40ba-8ae1-606518c3497a
state: "{{ now().isoformat() }}"
attributes:
forecast: "{{ response['weather.openweathermap'].forecast }}"
- name: Today High
device_class: Temperature
unit_of_measurement: °F
icon: mdi:thermometer-high
state: "{{ response['weather.openweathermap'].forecast[0].temperature }}"
- name: Today Low
device_class: Temperature
unit_of_measurement: °F
icon: mdi:thermometer-low
state: "{{ response['weather.openweathermap'].forecast[0].templow }}"
7 Likes
Marck
(Marck)
May 3, 2024, 12:26pm
5
Thanks for the pointer, adjusted my automation and works like a charm again
Marck
(Marck)
May 3, 2024, 12:33pm
6
Thanks for the code! I got it working like a charm again.
My code is a bit different, I’m getting the first eight hours of temperature. Maybe it helps someone:
{%- for _ in range(8) -%}
{%- set values = {
"time": as_timestamp(response['weather.openweathermap'].forecast[loop.index0].datetime) | timestamp_custom("%H:%M"),
"temperature": response['weather.openweathermap'].forecast[loop.index0].temperature,
"condition": response['weather.openweathermap'].forecast[loop.index0].condition,
"cloud_coverage": response['weather.openweathermap'].forecast[loop.index0].cloud_coverage,
"humidity": response['weather.openweathermap'].forecast[loop.index0].humidity
} %}
{% if values.time %}🕗 {{ values.time }}{% endif %},
{%- if values.temperature <5 %} ❄️{% elif values.temperature <0 %} ☃️{% else %} 🌡️{% endif %} {{ values.temperature }},
{%- if values.condition == 'rainy' %} 🌧️{% elif values.condition ==
'cloudy' %} ☁️{% elif values.condition == 'partlycloudy' %} ⛅{% elif
values.condition == 'clear-night' %} 🌑{% else %} ☀️{% endif %} {{
values.condition }},
{%- if values.cloud_coverage %} ☁️ {{ values.cloud_coverage }}%{% endif %},
{%- if values.humidity %}💧 {{ values.humidity }}%{% endif %}
{%- endfor %}
Troon
(Troon)
May 3, 2024, 12:38pm
7
Bit shorter:
{%- {'rainy':'🌧️','cloudy':'☁️','partlycloudy':'⛅','clear-night':'🌑'}.get(values.condition,'☀️') %}
1 Like
Marck
(Marck)
May 3, 2024, 12:48pm
8
Hah that’s a better way to do it, thanks!
relout
(Rene Elout)
July 31, 2024, 10:56am
9
Hi Marck,
Ik like this approach a lot, but, where do i add this when i take for example the configuration of pkscout?
Many thanks in advance!
Thank you very much. I would have no Idea how to create this on my own! But really need a forecast sensor for some off my automations.
Having abandonded Accuweather, I’ve signed up for OpenWeather 3.0 and added the integration, as weather.home, but need a bit of handholding to get the forecast data working. Testing through Developer Tools Templates, I get the following error: UndefinedError: ‘daily’ is undefined
I also pasted the following in templates.yaml but the sensor states are “unknown”
- trigger:
- platform: state
entity_id: weather.home
- platform: time_pattern
hours: /1
action:
- action: weather.get_forecasts
data:
type: daily
target:
entity_id: weather.home
response_variable: daily
sensor:
- name: OpenWeatherMap Forecast Cloud coverage
unique_id: openweathermap_forecast_cloud_coverage
state: "{{ daily['weather.home'].forecast[0].cloud_coverage }}"
unit_of_measurement: '%'
- name: OpenWeatherMap Forecast Condition
unique_id: openweathermap_forecast_condition
state: "{{ daily['weather.home'].forecast[0].condition }}"
- name: OpenWeatherMap Forecast Precipitation
unique_id: openweathermap_forecast_precipitation
state: "{{ daily['weather.home'].forecast[0].precipitation }}"
unit_of_measurement: mm
device_class: precipitation
- name: OpenWeatherMap Forecast Precipitation probability
unique_id: openweathermap_forecast_precipitation_probability
state: "{{ daily['weather.home'].forecast[0].precipitation_probability }}"
unit_of_measurement: '%'
- name: OpenWeatherMap Forecast Pressure
unique_id: openweathermap_forecast_pressure
state: "{{ daily['weather.home'].forecast[0].pressure }}"
unit_of_measurement: hPa
device_class: pressure
- name: OpenWeatherMap Forecast Temperature
unique_id: openweathermap_forecast_temperature
state: "{{ daily['weather.home'].forecast[0].temperature }}"
unit_of_measurement: °C
device_class: temperature
- name: OpenWeatherMap Forecast Temperature Low
unique_id: openweathermap_forecast_temperature_low
state: "{{ daily['weather.home'].forecast[0].templow }}"
unit_of_measurement: °C
device_class: temperature
- name: OpenWeatherMap Forecast Time
unique_id: openweathermap_forecast_time
state: "{{ daily['weather.home'].forecast[0].datetime }}"
device_class: timestamp
- name: OpenWeatherMap Forecast Wind speed
unique_id: openweathermap_forecast_wind_speed
state: "{{ daily['weather.home'].forecast[0].wind_speed }}"
unit_of_measurement: m/s
device_class: wind_speed
EDIT: My mistake. My OpenWeather integration entity was actually named weather.weather_home
Recreated the integration using just “home” as the name, thus getting weather.home and all is good!