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 }}"    

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

1 Like

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