Starting getting: UndefinedError: 'dict object' has no attribute 'forecast'

I have a sensor that gave me a detailed weather forecast in its attributes. It stopped working 2 weeks ago, and I have been trying to resolve the issue ever since. Whenever it tries to update every 15 minutes, I get this in the log:

Logger: homeassistant.helpers.sensor
Source: helpers/trigger_template_entity.py:204
First occurred: 12:45:00 AM (40 occurrences)
Last logged: 10:30:00 AM

Error rendering state template for sensor.nws_daily_forecasts: UndefinedError: 'dict object' has no attribute 'forecast'

This is the sensor in my configuration.yaml:

template:
  - trigger:
      - platform: time_pattern
        minutes: "/15"
    action:
      - service: nws.get_forecasts_extra
        data:
          type: twice_daily
        target:
          entity_id: weather.klqk_daynight
        response_variable: daily_forecast
    sensor:
      - name: "NWS Daily Forecasts" 
        unique_id: nws_daily_forecasts 
        state: >
          "{{ now() }}"
        attributes:
          forecast_0: "{{ daily_forecast.forecast[0].detailed_description }}"
          forecast_1: "{{ daily_forecast.forecast[1].detailed_description }}"
          forecast_2: "{{ daily_forecast.forecast[2].detailed_description }}"
          forecast_3: "{{ daily_forecast.forecast[3].detailed_description }}"

If I go to Developer Tools>Actions and paste:

service: nws.get_forecasts_extra
data:
  type: twice_daily
target:
  entity_id: weather.klqk_daynight
response_variable: daily_forecast

I get this response:

weather.klqk_daynight:
  forecast:
    - datetime: "2025-02-16T09:00:00-05:00"
      is_daytime: true
      detailed_description: >-
        A chance of rain showers and patchy fog before 11am. Mostly sunny. High
        near 58, with temperatures falling to around 51 in the afternoon. West
        wind 14 to 18 mph, with gusts as high as 38 mph. Chance of precipitation
        is 40%. New rainfall amounts between a tenth and quarter of an inch
        possible.
      short_description: Chance Rain Showers then Mostly Sunny
    - datetime: "2025-02-16T18:00:00-05:00"
      is_daytime: false
      detailed_description: >-
        Mostly clear, with a low around 27. West wind 3 to 13 mph, with gusts as
        high as 25 mph.
      short_description: Mostly Clear
    - datetime: "2025-02-17T06:00:00-05:00"
      is_daytime: true
      detailed_description: Sunny, with a high near 52. South southeast wind around 2 mph.
      short_description: Sunny
    - datetime: "2025-02-17T18:00:00-05:00"
      is_daytime: false
      detailed_description: Mostly clear, with a low around 30. East northeast wind around 1 mph.
      short_description: Mostly Clear
    - datetime: "2025-02-18T06:00:00-05:00"
      is_daytime: true
      detailed_description: Mostly sunny, with a high near 55. East southeast wind around 3 mph.
      short_description: Mostly Sunny
    - datetime: "2025-02-18T18:00:00-05:00"
      is_daytime: false
      detailed_description: >-
        A slight chance of rain showers between 1am and 3am, then a chance of
        rain and snow showers. Mostly cloudy, with a low around 34. Chance of
        precipitation is 40%.
      short_description: Mostly Cloudy then Chance Rain And Snow Showers
    - datetime: "2025-02-19T06:00:00-05:00"
      is_daytime: true
      detailed_description: >-
        Rain and snow showers. Mostly cloudy, with a high near 42. Chance of
        precipitation is 80%.
      short_description: Rain And Snow Showers
    - datetime: "2025-02-19T18:00:00-05:00"
      is_daytime: false
      detailed_description: >-
        A chance of rain and snow showers before 3am. Mostly cloudy, with a low
        around 26. Chance of precipitation is 50%. New snow accumulation of less
        than half an inch possible.
      short_description: Chance Rain And Snow Showers
    - datetime: "2025-02-20T06:00:00-05:00"
      is_daytime: true
      detailed_description: >-
        Sunny, with a high near 46. New snow accumulation of less than half an
        inch possible.
      short_description: Sunny
    - datetime: "2025-02-20T18:00:00-05:00"
      is_daytime: false
      detailed_description: Mostly clear, with a low around 21.
      short_description: Mostly Clear
    - datetime: "2025-02-21T06:00:00-05:00"
      is_daytime: true
      detailed_description: Sunny, with a high near 47.
      short_description: Sunny
    - datetime: "2025-02-21T18:00:00-05:00"
      is_daytime: false
      detailed_description: Partly cloudy, with a low around 25.
      short_description: Partly Cloudy
    - datetime: "2025-02-22T06:00:00-05:00"
      is_daytime: true
      detailed_description: Mostly sunny, with a high near 48.
      short_description: Mostly Sunny
    - datetime: "2025-02-22T18:00:00-05:00"
      is_daytime: false
      detailed_description: Partly cloudy, with a low around 27.
      short_description: Partly Cloudy

Can someone please help me determine what I am doing wrong? I assume I am not extracting the items from the dictionary list using the proper format.
Maybe something changed in the data format returned from the NWS because it was working for quite a while as is. Thanks!

Your templates are missing weather.klqk_daynight.

forecast_0: "{{ daily_forecast['weather.klqk_daynight'].forecast[0].detailed_description }}"
1 Like

Thank you very much for you help. That was it. I’m extremely confused on why I thought it was working before unless something changed with an HA update in last the 2-3 weeks. I guess I could have changed the code when I was experimenting with getting that first detailed forecast in the state of a second sensor called “current_forecast”.