I’m using the detailed_description data from the National Weather Forcast to create a spoken daily update of the day’s news and weather. With the recent update to HA the data does not seem to be available any longer.
I’ve reverted back to the previous release and will not be upgrading unless there’s a work around or resolution.
An example of the data:
forecast:
- detailed_description: Mostly cloudy, with a high near 50. North wind 10 to 15 mph.
datetime: '2024-04-04T08:00:00-05:00'
precipitation_probability: 0
is_daytime: true
condition: cloudy
wind_bearing: 0
temperature: 50
dew_point: 31
wind_speed: 12.5
humidity: 72
MaxK
(Mark)
April 4, 2024, 2:38pm
2
Yes I’m aware - but the detailed_description is not being pulled as far as I can see.
MaxK
(Mark)
April 4, 2024, 7:40pm
4
Looks like there may be a related issue on GitHub
opened 03:32AM - 04 Apr 24 UTC
integration: weather
integration: template
integration: nws
### The problem
I have a local weather station so I use a weather template to c… ombine NWS forecasts with my local data. After upgrading to 2024.04, the ([still documented](https://www.home-assistant.io/integrations/weather.template/#forecast_template)) `forecast_template` property was forbidden to be set so I had no weather.
I figured out how to make a template sensor that saves the result of making the `weather.get_forecasts` service (why can't the template just delegate it's service handler to a different service?), but my forecasts weren't showing up even though I could copy the template into the template editor and see the expected result.
`template.weather` validates the contents of the forecast, and it discards your forecast if it contains any keys that aren't on a whitelist: https://github.com/home-assistant/core/blob/841d3940d1a8edf4ad0fcf6d605fde313ccb874e/homeassistant/components/template/weather.py#L427-L461
The NWS integration adds its own key `detailed_description` which isn't on the whitelist: https://github.com/home-assistant/core/blob/56d0ad27f0dc67a66eb0568a78453b0e42f35b1f/homeassistant/components/nws/const.py#L30
So if you try to use NWS with a template, you get no forecasts unless you do something like this:
```yaml
forecast_twice_daily_template: |-
{% set forecast = state_attr('sensor.weather_forecast_twice_daily', 'forecast') %}
{% set clean = namespace(forecast=[]) %}
{% for f in forecast %}
{% set clean.forecast = clean.forecast + [dict(f | items | selectattr('0', 'ne', 'detailed_description'))] %}
{% endfor %}
{{ clean.forecast }}
forecast_hourly_template: |-
{% set forecast = state_attr('sensor.weather_forecast_hourly', 'forecast') %}
{% set clean = namespace(forecast=[]) %}
{% for f in forecast %}
{% set clean.forecast = clean.forecast + [dict(f | items | selectattr('0', 'ne', 'detailed_description'))] %}
{% endfor %}
{{ clean.forecast }}
```
All together, this turns what used to be a simple 2 line delegation from the template to the NWS weather entity into 48 lines of YAML and a lot of time spent troubleshooting.
### What version of Home Assistant Core has the issue?
core-2024.4.0
### What was the last working version of Home Assistant Core?
_No response_
### What type of installation are you running?
Home Assistant Core
### Integration causing the issue
nws
### Link to integration documentation on our website
https://www.home-assistant.io/integrations/nws/
### Diagnostics information
_No response_
### Example YAML snippet
_No response_
### Anything in the logs that might be useful for us?
```txt
Error validating template result '[{'detailed_description': '', 'datetime': '2024-04-03T22:00:00-04:00',…}]' from template 'Template<template=({{ state_attr('sensor.weather_forecast_hourly', 'forecast') }}) renders=6>' for attribute '_forecast_hourly' in entity weather.local validation message 'Only valid keys in Forecast are allowed, unallowed keys: ({'detailed_description'}), see Weather documentation https://www.home-assistant.io/integrations/weather/'
```
### Additional information
_No response_
knemo
April 5, 2024, 10:16pm
5
I’m seeing the same behavior - the detailed_descriptions are no longer being populated. Validated this on my test Home Assistant install - 2024.3 works correctly; 2024.4 does not.
I’ve been informed by developers that since the weather.get_forcast service call has been deprecated the National Weather Service integration will not be providing the STATES information any longer. Instead we’ll have to do service calls for weather:get_forcasts to get the information. Meaning that we’ll have to do some creative scripting to first get the information then extract it for our needs.
I’m fairly new to Home Assistant, so apologies if I’m restating something that’s already been said in this thread. I’ve been trying to get this to work as well. I have a template sensor that uses get_forecasts, and it works properly:
- trigger:
- platform: time_pattern
hours: /1
action:
- service: weather.get_forecasts
data:
type: twice_daily
target:
entity_id: weather.khio
response_variable: daily
sensor:
- name: Daily Forecast
unique_id: daily_forecast
state: "{{ now().isoformat() }}"
icon: mdi:hours-24
attributes:
forecast: "{{ daily['weather.khio'].forecast }}"
And here’s what the sensor data looks like:
The issue is how to get the detailed_description back out. I don’t yet know enough to do the “creative scripting”. Has anyone gotten a working solution for this?
FYI - I was continuing to research this, and came across a similar post for different data that provided the solution. Here’s what I’m using:
{% set forecast = state_attr('sensor.daily_forecast','forecast') %}
{{ forecast[0].detailed_description }}
Now I can get the forecast in my morning voice briefing.
This works for me:
- trigger:
- platform: time_pattern
minutes: 10
action:
- service: weather.get_forecasts
data:
type: twice_daily
target:
entity_id: weather.kmsp_daynight
response_variable: daily
sensor:
- name: "Day Forecast 1"
unique_id: "day_forecast_1"
state: "{{ daily['weather.kmsp_daynight'].forecast[0].detailed_description }}"
- name: "Day Forecast 2"
unique_id: "day_forecast_2"
state: "{{ daily['weather.kmsp_daynight'].forecast[1].detailed_description }}"
- name: "Day Forecast 3"
unique_id: "day_forecast_3"
state: "{{ daily['weather.kmsp_daynight'].forecast[2].detailed_description }}"
- name: "Day Forecast 4"
unique_id: "day_forecast_4"
state: "{{ daily['weather.kmsp_daynight'].forecast[3].detailed_description }}"
Replace the weather.kmsp_daynight service with your weather service sensor.
I have a separate templates.yaml folder, this goes at the top.
1 Like