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 }}"
3 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,'☀️') %}
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!