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

Sept 2023 Ha announced that the use of weather attributes will be depreciated in March of 2024 I did not have time to fix this issue until now.
Weather forecast service

If you use the old way of using the weather attributes in a template they would no longer work.

OLD WAY

 - obj: "p5b51" # Forecast time +8h
      properties:
        "text": >
          {%- if not is_state('weather.barb_s_place_hourly','unavailable') %}
          {%- set update = states('sensor.date') %}
          {%- set midnight = now().replace(hour=0, minute=0, second=0, microsecond=0).timestamp() %}
          {%- set event = as_timestamp(strptime(state_attr('weather.barb_s_place_hourly','forecast')[8]['datetime'], '%Y-%m-%dT%H:%M:%S%z', default='2020-01-00T00:00:00+00:00')) %}
          {%- set delta = ((event - midnight) // 86400) | int %}
          {%- if delta == 0 %}
          Today
          {%- elif delta == 1 %}
          Tomorrow
          {%- endif %}
          {{- event | timestamp_custom(" %-I %p") }}
          {%- endif %}

    - obj: "p5b52" # Forecast temp +8h
      properties:
        "text": "{{ state_attr('weather.barb_s_place_hourly','forecast')[8]['temperature'] if not is_state('weather.barb_s_place_hourly','unavailable') else '-' }}"

    - obj: "p5b53" # Forecast condition +8h
      properties:
        "src": >
          {%- if not is_state('weather.barb_s_place_hourly','unavailable') %}
          L:/w-32-{{ state_attr('weather.barb_s_place_hourly','forecast')[8]['condition'] }}.png
          {%- endif %} 

Solution:

Create a Hourly weather sensor. sensor.weather_hourly useing the service: weather.get_forecasts

This does not work for accuweather I needed to use the Meteorologisk institutt (Met.no) integration.
Just for less confusion I created a new weather service called home forecast
then created new sensor sensor.weather_hourly in my template.yaml

hourly forecast sensor

#weather forcast hourly sensor 
- trigger:
    - platform: time_pattern
      minutes: /1

    - platform: homeassistant
      event: start
  action:
    - service: weather.get_forecasts
      data:
        type: hourly
      target:
        entity_id: weather.home
      response_variable: hourly

  sensor:
    - name: Weather Hourly
      state: "{{ states('weather.home') }}"
      attributes:
        temperature: "{{ state_attr('weather.home', 'temperature') }}"
        dew_point: "{{ state_attr('weather.home', 'dew_point') }}"
        temperature_unit: "{{ state_attr('weather.home', 'temperature_unit') }}"
        humidity: "{{ state_attr('weather.home', 'humidity') }}"
        cloud_coverage: "{{ state_attr('weather.home', 'cloud_coverage') }}"
        pressure: "{{ state_attr('weather.home', 'pressure') }}"
        pressure_unit: "{{ state_attr('weather.home', 'pressure_unit') }}"
        wind_bearing: "{{ state_attr('weather.home', 'wind_bearing') }}"
        wind_speed: "{{ state_attr('weather.home', 'wind_speed') }}"
        wind_speed_unit: "{{ state_attr('weather.home', 'wind_speed_unit') }}"
        visibility_unit: "{{ state_attr('weather.home', 'visibility_unit') }}"
        precipitation_unit: "{{ state_attr('weather.home', 'precipitation_unit') }}"
        forecast: "{{ hourly['weather.home'].forecast }}"    

Here is another one using the National weather service integration twice daily.
For testing I recommend changing the

  - platform: time_pattern
    hours: /1 

to minutes or seconds so you don’t have to wait for data update then change back to at 1 hour or more


Below has been edited for USE with the National weather service forecast
action:
- service: nws.get_forecasts_extra
from
action:
- service: weather.get_forecasts

#My templet for weather forecast
#national weather service 
- trigger:
  - platform: time_pattern
    hours: /1
  action:
    - service: nws.get_forecasts_extra
      data:
        type: twice_daily
      target:
        entity_id: weather.pg425
      response_variable: twice_daily
    - variables:
        nextday: "{{ twice_daily['weather.pg425'].forecast[2] }}"
        day: "{{ twice_daily['weather.pg425'].forecast[0] }}"
        evening: "{{ twice_daily['weather.pg425'].forecast[1] }}"
  sensor:
    - name: "Forcast next morning Details NWS"
      unique_id: next_morningdetailed_descriptions
      state: "{{ nextday.detailed_description }}"

    - name: "Forcast TODAY Details NWS"
      unique_id: morningdetailed_descriptions2
      state: "{{ day.detailed_description }}"

    - name: "Forcast evening Details NWS"
      unique_id: eveningdetailed_descriptions2
      state: "{{ evening.detailed_description }}"       

    - name: "Forcast Eve temperature NWS"
      unique_id: eveningtempNWS
      state: "{{ evening.temperature }}"     

    - name: "Forcast today's temperature NWS"
      unique_id: todaytempNWS
      state: "{{ day.temperature }}" 
      
    - name: "Forcast Today chance of rain NWS"
      unique_id: todaychanceofrain
      state: "{{ day.precipitation_probability }}"       
    - name: "Forcast Evening chance of rain NWS"
      unique_id: eveningchanceofrain
      state: "{{ evening.precipitation_probability }}"     
     
    - name: "Forcast Today condition NWS"
      unique_id: todaycondition
      state: "{{ day.condition }}"       
    - name: "Forcast Evening condition NWS"
      unique_id: eveningcondition
      state: "{{ evening.condition }}"
      
    - name: "Forcast Today wind_speed NWS"
      unique_id: todaywind_speed
      state: "{{ day.wind_speed }}"       
    - name: "Forcast Evening wind_speed NWS"
      unique_id: eveningwind_speed
      state: "{{ evening.wind_speed }}"         

New yaml for plates for my openhasp +8 hour data to be displayed. Basicly replace all weather.barb_s_place_hourly' with sensor.weather_hourly

yaml

    - obj: "p5b51" # Forecast time +8h
      properties:
        "text": >
          {%- if not is_state('sensor.weather_hourly','unavailable') %}
          {%- set update = states('sensor.date') %}
          {%- set midnight = now().replace(hour=0, minute=0, second=0, microsecond=0).timestamp() %}
          {%- set event = as_timestamp(strptime(state_attr('sensor.weather_hourly','forecast')[8]['datetime'], '%Y-%m-%dT%H:%M:%S%z', default='2020-01-00T00:00:00+00:00')) %}
          {%- set delta = ((event - midnight) // 86400) | int %}
          {%- if delta == 0 %}
          Today
          {%- elif delta == 1 %}
          Tomorrow
          {%- endif %}
          {{- event | timestamp_custom(" %-I %p") }}
          {%- endif %}

    - obj: "p5b52" # Forecast temp +8h
      properties:
        "text": "{{ state_attr('sensor.weather_hourly','forecast')[8]['temperature'] if not is_state('sensor.weather_hourly','unavailable') else '-' }}"

    - obj: "p5b53" # Forecast condition +8h
      properties:
        "src": >
          {%- if not is_state('sensor.weather_hourly','unavailable') %}
          L:/w-32-{{ state_attr('sensor.weather_hourly','forecast')[8]['condition'] }}.png
          {%- endif %}

For more on my personal openhasp project.
Home assistant Forums Openhasp on a Lanbon L8 and WT32-SC01 Plus
Gethub openhasp-

sources
Weather forecast service
HA dev Weather forecasts

Unsure How To Use Hourly Forecast Information (Since 2024.3.0) #112628

4 Likes

Thanks for the heads-up. I didn’t see this before, even though apparently it’s been deprecated for a while.

I’ve made a note to check my weather displays when I update to 2024.3.x. Frankly HA isn’t my primary source for weather information, so it’s not that big a deal for me. I do use outside temp in a couple of calculations though.

Am I understanding correctly that the weather data are being moved out of attributes? That would make sense, if the goal is to make better use of the Recorder database. Currently all attributes are stored in a new state_attributes record any time any of them change. That includes not only the values, but the attribute field names, as well. In JSON format. Obviously that’s a lot of duplicated data for all those weather attributes. I’ve had to exclude my weather entities and just extract what I need with templates.

For me it really only screwed up my hourly forecast stuff that came from accuweather and met.no sources . My temps and local stuff is all local from my own weather station and using the Local MQTT AmbientWeather2MQTT to draw from my console . I kept seeing the warnings but did not have time to figure out till it stopped LOL

saved my day after 2024.4 :pray:

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