Forecast Depreciation

Hi,

I hope you can help; I am at a loss.

Over a year ago I setup a sensor that picked up the weather condition, temperature and precipitation for the next day. I would then pull this information to run various automations.

Since the 2024.4 update where I understand the forecast attribute has become deprecated, the function no longer works. Fair enough. Not complaining.

However I have quite forgotten how I set it up in the first place and not able to update it. I have the following in my sensors.yaml file which is correctly referenced from the configuration file.

Can anyone kindly remind me how I did this?!

Many thanks in advance.

image

-   platform: template
    sensors:
      forecast_total_precipitation_tomorrow:
        friendly_name: "Forecast Precipitation Tomorrow"
        value_template: "{{state_attr('weather.home', 'forecast')[0].precipitation}}"
        unit_of_measurement: "mm"
        device_class: precipitation
        
-   platform: template
    sensors:
      forecast_condition_tomorrow:
        friendly_name: "Forecast Condition Tomorrow"
        value_template: "{{state_attr('weather.home', 'forecast')[0].condition}}"

-   platform: template
    sensors:
      forecast_temperature_tomorrow:
        friendly_name: "Forecast Temperature Tomorrow"
        value_template: "{{state_attr('weather.home', 'forecast')[0].temperature}}"
        unit_of_measurement: "C"
        device_class: temperature

Create the following Trigger-based Template Sensor.

template:
  - trigger:
      - platform: time_pattern
        hours: /1
      - platform: event
        event_type: event_template_reloaded
    action:
      - variables:
          entity_id: weather.home
      - service: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: "{{ entity_id }}"
        response_variable: daily
    sensor:
      - name: Daily Weather Forecast
        unique_id: daily_weather_forecast
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: "{{ daily[entity_id]['forecast'] }}"

Modify your existing Template Sensors to get forecast data from sensor.daily_weather_forecast.

-   platform: template
    sensors:
      forecast_total_precipitation_tomorrow:
        friendly_name: "Forecast Precipitation Tomorrow"
        value_template: "{{state_attr('sensor.daily_weather_forecast', 'forecast')[0].precipitation}}"
        unit_of_measurement: "mm"
        device_class: precipitation
        
-   platform: template
    sensors:
      forecast_condition_tomorrow:
        friendly_name: "Forecast Condition Tomorrow"
        value_template: "{{state_attr('sensor.daily_weather_forecast', 'forecast')[0].condition}}"

-   platform: template
    sensors:
      forecast_temperature_tomorrow:
        friendly_name: "Forecast Temperature Tomorrow"
        value_template: "{{state_attr('sensor.daily_weather_forecast', 'forecast')[0].temperature}}"
        unit_of_measurement: "C"
        device_class: temperature

On a separate note, your three Template Sensors use legacy format. It’s still supported but you might want to take this opportunity to convert them to modern format. Refer to the documentation for more information.

4 Likes

Just to say thank you for this, your direction was really helpful. I needed to make some minor amends but in in the end got there with it. I will have to read up on how to update my legacy Template Sensors, but that’s for another day I think!

1 Like