Unable to get detailed_description from NWS Weather Forcast

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

Please see the NWS change in the Backward-incompatible changes in the 2024.4 Release Notes.

Yes I’m aware - but the detailed_description is not being pulled as far as I can see.

Looks like there may be a related issue on GitHub

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. :partying_face:

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

Home Assistant Community Post

Title: Issues Storing Weather Forecast Data with New get_forecasts Service

Hello All,

I’m having trouble utilizing the new weather.get_forecasts service with the NWS integration. Historically, I used the old method where the weather entity had an attribute called forecast, which allowed me to drive my automations using weather data. Even though this method was deprecated, I can still see hourly and twice daily data in the UI when I click on the entity.

I understand that the new recommended approach is to use the get_forecasts service. I can successfully retrieve data using this service in the developer console, but I’m struggling to store this data in a way that can be parsed and used in automations.

Here are the steps I’ve tried:

  1. Using input_text Entities:

    • I attempted to write the forecast data to input_text entities.
    • However, this exceeds the 256 character limit, resulting in errors and the state falling back to unknown.
  2. Shell Command to Store Data in a File:

    • I considered using a shell command to write the forecast data to a file and then read it back into Home Assistant.
    • This approach seemed overly complex for what should be a straightforward task.

What am I missing here? How can I write the forecast data returned by the get_forecasts service to an entity in Home Assistant so that I can parse and use it in my automations?

Alternatively, since I can see the data in the NWS entity, how do I now access this?

Thank you for your help!

Did you get the answer you needed? If not this is a solution that has worked for me.

- trigger:
    - platform: time_pattern
      # Get most recent forecast at 5 minutes after the hour
      minutes: 5
  action:
    - service: weather.get_forecasts
      data:
        type: twice_daily
      target:
        entity_id: weather.kmsp_daynight
      response_variable: daily_forecast

  sensor:
    - name: "Daily Forecasts"
      unique_id: "daily_forecasts"
      state: "{{ now() }}"
      attributes:
        forecast_0: "{{ daily_forecast['weather.kmsp_daynight'].forecast[0].detailed_description }}"
        forecast_1: "{{ daily_forecast['weather.kmsp_daynight'].forecast[1].detailed_description }}"
        forecast_2: "{{ daily_forecast['weather.kmsp_daynight'].forecast[2].detailed_description }}"
        forecast_3: "{{ daily_forecast['weather.kmsp_daynight'].forecast[3].detailed_description }}"

This creates a new sensor called Daily Forecasts. The actual sensor data is the date/time of the forecast and each of the attributes contain the textual data. You can then get the data with a state_attr(‘sensor.daily_forecast’,‘forecast_0’), etc

Substitute the kmsp_daynight portion for the weather station you need.

This new sensor is at the top of my templates.yaml file and before all other sensors defined in the file, the sensor section is combined with all the other sensors.

Be aware — the NWS forecast has been erratic lately, and if it stops working all the sensors in the template.yaml will also stop working. Don’t know a work around at this point.

Make sure the rest of the sensors in your templates.yaml file are indented properly or you’ll experience the effect above.

1 Like

With the update to Core 2024.8, detailed_description gets moved per this PR:

What this means is you’ll need to modify your trigger service calls and sensors. Here’s mine (ignore the commented hourly forecasts):

template:
  - trigger:
      - platform: time_pattern
        minutes: "/5"
      - platform: homeassistant
        event: start
    action:
      - service: weather.get_forecasts
        data:
          type: twice_daily
        target:
          entity_id: weather.kxxx
        response_variable: daily
      - service: nws.get_forecasts_extra
        data:
          type: twice_daily
        target:
          entity_id: weather.kxxx
        response_variable: weather_forecast
    #      - service: weather.get_forecasts
    #        data:
    #          type: hourly
    #        target:
    #          entity_id: weather.kxxx
    #        response_variable: hourly
    sensor:
      - name: Daily Forecast
        unique_id: daily_forecast
        state: "{{ now().isoformat() }}"
        icon: mdi:hours-24
        attributes:
          forecast: "{{ daily['weather.kxxx].forecast }}"
      - name: Daily Forecast Extra
        unique_id: daily_forecast_extra
        state: "{{ now().isoformat() }}"
        icon: mdi:hours-24
        attributes:
          forecast: "{{ weather_forecast['weather.kxxx'].forecast }}"
#      - name: Hourly Forecast
#        unique_id: hourly_forecast
#        state: "{{ now().isoformat() }}"
#        icon: mdi:timer-sand
#        attributes:
#          forecast: "{{ hourly['weather.kxxx'].forecast }}"

In addition to sensor.daily_forecast, you’ll see sensor.daily_forecast_extra in your entities. The new entity are where you’ll find the detailed_description and a new attribute, short_description. Of course, you’ll need to appropriately reference the new entities.

1 Like

Thanks for the post, however, I was struggling to get this working. Silly me, my NWS entity was named weather.kbwi_daynight, not weather.kbwi

Also you were missing a quote on this line:

          forecast: "{{ daily['weather.kxxx].forecast }}"

Here is my whole working config to help others:


template:
  - trigger:
      - platform: time_pattern
        minutes: "/5"
      - platform: homeassistant
        event: start
    action:
      - service: weather.get_forecasts
        data:
          type: twice_daily
        target:
          entity_id: weather.kbwi_daynight
        response_variable: daily
      - service: nws.get_forecasts_extra
        data:
          type: twice_daily
        target:
          entity_id: weather.kbwi_daynight
        response_variable: weather_forecast
    sensor:
      - name: kbwi daynight
        state: "{{ states('weather.kbwi_daynight') }}"
        icon: mdi:weather-cloudy
        attributes:
          forecast: "{{ daily['weather.kbwi_daynight'].forecast }}"
      - name: kbwi daynight extra
        state:  "{{ states('weather.kbwi_daynight') }}"
        icon: mdi:weather-cloudy
        attributes:
          forecast: "{{ weather_forecast['weather.kbwi_daynight'].forecast }}"

Thanks!

1 Like

Yes, you’re correct. It needs another quote.

I have it appended to the configuration.yaml file. It will create another entity with attributes for the detailed forecasts.

Although what I posted works, I didn’t realize I could use nested actions. Apparently, this is what’s expected with the deprecation of service.

    action:
      - action: weather.get_forecasts
        data:
          type: twice_daily
        target:
          entity_id: weather.kbwi_daynight
        response_variable: daily
      - action: nws.get_forecasts_extra
        data:
          type: twice_daily
        target:
          entity_id: weather.kbwi_daynight
        response_variable: weather_forecast
2 Likes

Any suggestions on how to get the first three detailed descriptions from the extra forecasts? It used to work for me many months ago and after the recent changes, I cannot get it to work. I’ve tried numerous approaches and have the same issue: I can see the data in the response from the action using Developer Tools (see below), but however I try to access and parse that data, it’s not available. I use the detailed descriptions to show forecast text on my dashboards.

I appreciate any suggestions!


Action:
action: nws.get_forecasts_extra
target:
entity_id: weather.d6637
data:
type: twice_daily

Response:
weather.d6637:
forecast:
- datetime: “2024-12-07T10:00:00-08:00” is_daytime: true
detailed_description: Sunny, with a high near 80. West wind 0 to 10 mph.
short_description: Sunny
- datetime: “2024-12-07T18:00:00-08:00” is_daytime: false
detailed_description: Mostly clear, with a low around 50. Southwest wind 0 to 5 mph.
short_description: Mostly Clear
- datetime: “2024-12-08T06:00:00-08:00” is_daytime: true
detailed_description: Mostly sunny, with a high near 71. Southwest wind 0 to 10 mph.
short_description: Mostly Sunny

Template:
{{ state_attr(‘weather.d6637’, ‘forecast’)[‘detailed_description’] }}

Result:
‘None’ has no attribute ‘detailed_description’

Result type: string

This template listens for the following state changed events:

  • Entity: weather.d6637

Template:
“{{ state_attr(‘weather.d6637’, ‘forecast’) }}”

Result:
Result type: string

“None”

This template listens for the following state changed events:

  • Entity: weather.d6637

Try this:

Add the following below your action template:

    sensor:
      - name: Daily Forecast Extra
        unique_id: daily_forecast_extra
        state: "{{ now().isoformat() }}"
        icon: mdi:weather-sunny
        attributes:
          forecast: "{{ weather_forecast['weather.d6637'].forecast }}"

At this point, you probably need to reload your YAML configuration or perform a restart before looking for the entity sensor.daily_forecast_extra in Developer tools >> states.

Then use the sensor to extract the attribute string:

{{ state_attr('sensor.daily_forecast_extra', 'forecast')[0].detailed_description | truncate(254,true,'…',0) }}

FYI, the truncate is for those times when there are more than 255 characters in the forecast. Otherwise, you’ll get an error.

This works for me:

# Get most recent forecast at 5 minutes after the hour
- trigger:
    - trigger: time_pattern
      minutes: 5
  action:
    - action: nws.get_forecasts_extra
      data:
        type: twice_daily
      target:
        entity_id: weather.kmsp_daynight
      response_variable: daily_forecast
  sensor:
    - name: "NWS Daily Forecasts"
      unique_id: "nws_daily_forecasts"
      state: "{{ now() }}"
      attributes:
        forecast_0: "{{ daily_forecast['weather.kmsp_daynight'].forecast[0].detailed_description }}"
        forecast_1: "{{ daily_forecast['weather.kmsp_daynight'].forecast[1].detailed_description }}"
        forecast_2: "{{ daily_forecast['weather.kmsp_daynight'].forecast[2].detailed_description }}"
        forecast_3: "{{ daily_forecast['weather.kmsp_daynight'].forecast[3].detailed_description }}"

Yields the following:

forecast_0: Partly sunny, with a high near 26. Northwest wind 5 to 10 mph.
forecast_1: Snow showers. Mostly cloudy. Low around 6, with temperatures rising to around 13 overnight. Northwest wind 5 to 20 mph, with gusts as high as 35 mph. Chance of precipitation is 90%. New snow accumulation of less than one inch possible.
forecast_2: Mostly sunny. High near 8, with temperatures falling to around 2 in the afternoon. Wind chill values as low as -18. Northwest wind 15 to 20 mph, with gusts as high as 35 mph.
forecast_3: Mostly clear, with a low around -5. Wind chill values as low as -20. Northwest wind 5 to 15 mph, with gusts as high as 30 mph.
friendly_name: NWS Daily Forecasts

But actually, I’m not using the data because there doesn’t appear to be a way to also put a time period name (ie, Today, Tonight, Monday, etc) with the data without complicated yaml to use the datetime field. Instead I’m now just scraping the data from the NWS web forecast for my area which is essentially the same information.

Using the HACS integration Multiscrape, I use this:

# scrape NWS Local Weather forcast once per hour
- resource: https://forecast.weather.gov/MapClick.php?CityName=Maple+Grove&state=MN&site=MPX&textField1=45.106&textField2=-93.46&e=0
  scan_interval: 3600
  sensor:
    - unique_id: nws_web_forecasts
      name: "NWS Web Forecasts"
      select: "#detailed-forecast-body > div:nth-child(1) > div.col-sm-2.forecast-label > b"
      attributes:
        - name: period_0
          select: "#detailed-forecast-body > div:nth-child(1) > div.col-sm-2.forecast-label > b"
        - name: forecast_0
          select: "#detailed-forecast-body > div:nth-child(1) > div.col-sm-10.forecast-text"
        - name: period_1
          select: "#detailed-forecast-body > div:nth-child(2) > div.col-sm-2.forecast-label > b"
        - name: forecast_1
          select: "#detailed-forecast-body > div:nth-child(2) > div.col-sm-10.forecast-text"
        - name: period_2
          select: "#detailed-forecast-body > div:nth-child(3) > div.col-sm-2.forecast-label > b"
        - name: forecast_2
          select: "#detailed-forecast-body > div:nth-child(3) > div.col-sm-10.forecast-text"
        - name: period_3
          select: "#detailed-forecast-body > div:nth-child(4) > div.col-sm-2.forecast-label > b"
        - name: forecast_3
          select: "#detailed-forecast-body > div:nth-child(4) > div.col-sm-10.forecast-text"

To yield:

period_0: Today
forecast_0: Partly sunny, with a high near 27. Northwest wind 5 to 10 mph. 
period_1: Tonight
forecast_1: Snow showers, mainly before 3am.  Low around 6. Blustery, with a northwest wind 5 to 10 mph increasing to 15 to 20 mph after midnight. Winds could gust as high as 30 mph.  Chance of precipitation is 90%. New snow accumulation of less than one inch possible. 
period_2: Wednesday
forecast_2: A 20 percent chance of snow showers before 7am.  Mostly sunny, with a temperature falling to around 2 by 5pm. Wind chill values as low as -18. Blustery, with a northwest wind 15 to 20 mph, with gusts as high as 35 mph. 
period_3: Wednesday Night
forecast_3: Mostly clear, with a low around -5. Wind chill values as low as -20. West northwest wind 5 to 15 mph, with gusts as high as 30 mph. 
friendly_name: NWS Web Forecasts