Weather forecast template sensor

Hi everybody, as I’ve only copied the codes, I’m too stupid to adjust it, as the weather forecast has changed with 2024.3.

I used this sensor for the average temperature for the next 24 hours. If it updates once before sunset, it would be a dream:

{{ state_attr('weather.openweathermap', 'forecast')[:8]
      | map(attribute='temperature') | average | round(1) }}

And second I use this sensor to decide, whether my shutters should go in “summer mode” so they are closed aligned to the sun. If this updates at sunrise, would be fantastic:

{{ (state_attr('weather.openweathermap', 'forecast')|selectattr('datetime', 'lt', (now().replace(hour=23,minute=59)).isoformat()))| map(attribute='temperature') | list | max }}

Thank you very much for your help

  - trigger:
      - platform: sun
        event: sunrise
        offset: "-00:15:00"
      - platform: sun
        event: sunset
        offset: "-00:15:00"
      - service: weather.get_forecasts
          type: hourly
          entity_id: weather.forecast_home
        response_variable: hourly
      - name: Forecast Hourly
        unique_id: weather_forecast_hourly
        state: "{{ states('weather.forecast_home') }}"
          forecast: "{{ hourly['weather.forecast_home'].forecast }}"
  - sensor:
      - name: "High temperature today"
        unique_id: High_temperature_today_1
        device_class: temperature
        state: "{{ (state_attr('sensor.forecast_hourly', 'forecast')|selectattr('datetime', 'lt', (now().replace(hour=23,minute=59)).isoformat()))| map(attribute='temperature') | list | max }}"
        unit_of_measurement: °C
  - sensor:
      - name: "Average temperature today"
        unique_id: Average_temperature_today_1
        device_class: temperature
        state: "{{ (state_attr('sensor.forecast_hourly', 'forecast'))[:24] | map(attribute='temperature') | average | round(1) }}"
        unit_of_measurement: °C
1 Like