Update from using weather attributes with the new service: weather.get_forecasts

Could you please write how did you manage to make ambientweather2mqtt working?
I installed the add-on, my weather station is ws-2902A, I managed to find app and upgrade firmware, enabled custom webserver and entered settings as they are outlined in the ambientweather2mqtt documentation but getting zero data.

Sorry I just saw this
Did you get it going?

@invisible999
I don’t remember
I just followed the instructions and it worked .

Do you see the console in a MQTT explorer?



Yes, this morning it mysteriously started working…

1 Like

Hi,

can you please share your pages.jsonl for your weather forecast widget?

This is already in the original post but
I will copy and paste
For more on my personal openhasp project.
Home assistant Forums Openhasp on a Lanbon L8 and WT32-SC01 Plus
Gethub openhasp-

In original post I Added Forecast sensors from the National weather service integration.
I really like the Forecast Details they give to use for Voice announcements of weather.

A slight chance of showers and thunderstorms before 5am, 
then a slight chance of rain. Partly cloudy. Low around 76, 
with temperatures rising to around 80 overnight. North wind 0 to 5 mph.

That assumes that you find that to be an accurate source of forecast information.

I use both national weather services,
And AccuWeather

update to National weather service template for detailed_description
Only set for twice_daily forecasts. 50% Chance of rain, otherwise partly cloudy with a high of 75F.
the service is now nws.get_forecasts_extra

Action nws.get_forecasts_extra

nws.get_forecasts_extra provides extra data in a form similar to weather.get_forecasts

1 Like

I’m trying to pull the detailed_description from the NWS forecast using the new(ish) get_forecasts_extra. I’ve been tinkering for hours and keep ending up with empty sensors. This is the code I am using in configuation.yaml for the sensors (my NWS weather entity is weather.kbtm).

template:
  - trigger:
      - platform: time_pattern
        minutes: 10
    action: 
      - service: nws.get_forecasts_extra
        data:
          type: twice_daily
        target:
          entity_id: weather.kbtm
        response_variable: twice_daily
      - variables:
          nextday: "{{ twice_daily['weather.kbtm'].forecast[2] }}"
          day: "{{ twice_daily['weather.kbtm'].forecast[0] }}"
          evening: "{{ twice_daily['weather.kbtm'].forecast[1] }}"
    sensor:
      - name: "NWS Detailed Forecast 2"
        unique_id: forecast_detailed_2
        state: "{{ nextday.detailed_description }}"

      - name: "NWS Detailed Forecast 0"
        unique_id: forecast_detailed_0
        state: "{{ day.detailed_description }}"

      - name: "NWS Detailed Forecast 1"
        unique_id: forecast_detailed_1
        state: "{{ evening.detailed_description }}"

If someone could point out what I’m doing wrong, I would be very appreciative! I can see that the template sensors get created, but they just display “Unknown.” Thanks!

I’m not familiar with the new extra
Or the weather services you are using
But I know with my setups I had to see the weather services docs and look at what is being exposed in HA with developer tools to find the data I wanted .

This is what’s been working for me.

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

FYI: NWS integration uses indexed attributes for the forecasts. A sensor template to extract forecast index [0], will return the near-term forecast, day or night. For twice-daily forecasts, the remainder of the indexes will represent day or night forecasts in 12-hour intervals depending on datetime and/or is_daytime attributes. They alternate between day (6 AM to 6 PM) and night (6 PM to 6 AM; which will change the current day at midnight). The behavior might complicate your sensors, however I’m guessing most weather cards use the datetime attribute to determine when each index is valid; it’s doing the work for you.

The two sensors templates I’ve been using populate the entity state with time to indicate when the forecasts change. Except for 6 AM and 6 PM (local time) forecasts, the updates seldom occur at the top of the hour.

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

Please format your configuration properly.

You need to assign an ID for the response variable so you can extract the desired data.

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

To retrieve the first 3 detailed descriptions you would use:

{{ value["weather.d6637"]["forecast"][:3]
| map(attribute='detailed_description') | list }}

Keep in mind that the State of an entity is limited to 255 characters, so 3 days worth of detailed description is highly likely to run over that limit, which will cause the sensor to return unknown. An attribute can hold all 3 values without issue.

Thanks for the quick response and suggestion.

The action works as mine did previously in Developer Tools and provides the response required.

In Developer Tools Template, I get: UndefinedError: ‘value’ is undefined

When I create a Helper Template sensor, data is unavailable.

Am I configuring this incorrectly using your suggestion? Appreciate the help!

Yes, it seems likely.

There is no connection between the Action tool and the Template editor tool. You need to use the “Copy to Clipboard(Template)” button to copy the data and then paste it into the Template editor tool, otherwise the variable value doesn’t contain anything in the Template editor.

When you paste the copied data into the Template editor to test the template for your sensor, it will be pasted in as a set statement using whatever variable ID you assigned the response_variable in the action.

Trigger-based sensors are not supported in Template Helpers, they must be added to your configuration.yaml file (or a properly merged file that has template as the top-level key). Other “advanced” functions like delay_on, availability, and attributes are also only available when configured in YAML.

1 Like

Super helpful! It worked, thanks!!!

Lessons learned for me:

  1. Copy To Clipboard (Template)
  2. Include in configuration.yaml

Over the past year, I have been trying to reduce my configuration.yaml and use more of the new configuration features like Helpers and Templates in HA.

I’ve been searching for a function that does this for months. That said, your Result panel arrangement looks different than mine. Mine is a concatenated string, comma delimited without line breaks between attributes.

Screen shot?