Forecast Depreciation

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