Weather forecast template sensor

  - trigger:
      - platform: sun
        event: sunrise
        offset: "-00:15:00"
      - platform: sun
        event: sunset
        offset: "-00:15:00"
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: weather.forecast_home
        response_variable: hourly
    sensor:
      - name: Forecast Hourly
        unique_id: weather_forecast_hourly
        state: "{{ states('weather.forecast_home') }}"
        attributes:
          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
2 Likes