Weather Template and Forecast

I read quite a bit on how things changed with the 2024.04 release and weather forecast attributes.

However I still have not understood the documentation of the “Template Weatger Provider”.

# Example configuration.yaml entry
weather:
  - platform: template
    name: "My Weather Station"
    condition_template: "{{ states('weather.my_region') }}"
    temperature_template: "{{ states('sensor.temperature') | float }}"
    temperature_unit: "°C"
    humidity_template: "{{ states('sensor.humidity') | float }}"
    forecast_daily_template: "{{ state_attr('weather.my_region', 'forecast_data') }}"

I am looing to have the forecast in my template sensor of hourly and daily temp min max and condition values.
All examples I found always only provide parts of the information — or more likely I think in a wrong way and dont understand it :slight_smile:

Any hints welcome :slight_smile:

This template is to create a wether entity if you already have a forecast. But I’m guessing you want the reverse? If so, you’re probably looking at the wrong documentation. In that case you want the “Example template sensor using get_forecasts” on this page:

ahh thanks :slight_smile:
may I ask more then.

1- so I need to create a sensor for every value specifically?

    sensor:
      - name: Temperature forecast next hour
        unique_id: temperature_forecast_next_hour
        state: "{{ hourly['weather.home'].forecast[0].temperature }}"
        unit_of_measurement: °C

No way to just get everything from the response and leave the rest to the Template Weather Provider?

  1. Is there a UI way to create a action or does this go to the configuration.yaml only?

Thanks

You can put it in one or more entities, split it up in attributes, etc. Yaml only. But what is it you want to do with the values exactly once you have them? because sticking them back in a template weather entity will create a sort of copy of what you already had. If you just want to display a weather card you do not need all this, you just provide the weather entity to the weather card of your choice.

I have a Weather Template Sensor.
I mixed my own sensors outside temp etc. with forecast from a cloud weather provider.

The home assistant standard weather entity (all data from met.no) shows a forecast. (left card)
The right weather card shows my own weather.local entity. I wanted to populate the forecast info there aswell. Currently I thought I have to use get_forecasts and provide it to “forcast_daily_template” of the Template Weather Provider to achieve this?

Ah, ok, that makes sense. Then you use the template in the example, and create an attribute on the sensor using:

"{{ hourly['weather.home'].forecast[0] }}"

It needs to be an attribute because it contains the whole forcast for all days (or hours, depending on which service you pick. You could also do both.). The state has limited length, attributes do not.
Then, when you create your weather entity, you supply that attribute as the forecast.

Thank you again.
For anyone stumbling over this and also wanting to have Template Weather Entity eg. to mix data from local solution like Ecowitt and cloud with forecasts … this is my working code:

Code in configuration.yaml for triggering the data and read it to the standard weather.yourcloudentity

template:
  - trigger:
      - platform: time_pattern
        hours: /1

    action:
      - service: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: 
           - weather.home
        response_variable: daily

    sensor:
      - name: Daily Forecast
        unique_id: weather_forecast_daily
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: "{{ daily['weather.home'].forecast }}" 

  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: 
            - weather.home
        response_variable: hourly
    sensor:
      - name: Hourly Forecast
        unique_id: weather_forecast_hourly
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: "{{ hourly['weather.home'].forecast }}"

Template Weather Entitiy


- platform: template
  name: "Wetterdaten Lokal und Cloud Mix"
  unique_id: "weather.local"
  condition_template: "{{ states('weather.home') }}"
  temperature_template: "{{ states('sensor.local_ecowitt_outdoor_temperature') | float }}"
  apparent_temperature_template: "{{ states('sensor.local_ecowitt_feels_like_temperature') | float }}"
  dew_point_template: "{{ states('sensor.local_ecowitt_dewpoint') | float }}"
  humidity_template: "{{ states('sensor.local_ecowitt_humidity') | float }}"
  pressure_template: "{{ states('sensor.local_ecowitt_relative_pressure') | float }}"
  wind_speed_template: "{{ states('sensor.local_ecowitt_wind_speed') | float }}"
  wind_bearing_template: "{{ states('sensor.local_ecowitt_wind_direction') | float }}"
  visibility_template: "{{ state_attr('weather.home', 'visibility') }}"
  forecast_daily_template: "{{ state_attr('sensor.daily_forecast', 'forecast') }}"
  forecast_hourly_template: "{{ state_attr('sensor.hourly_forecast', 'forecast') }}"
3 Likes

The actions part is a list. So you can put both forecasts in the same time trigger if you want.

I stumbled upon this thread in search of a solution why there is no longer an attribute for the weather.
Thank you very much for the code snippet.

just in case if someone is as unpatient as me, this is my version that also triggers on a reboot to get the latest data.

#template:
  - trigger:
      - platform: time_pattern
        hours: /1
      - platform: homeassistant
        event: start
        
    action:
      - service: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: 
           - weather.home
        response_variable: daily

    sensor:
      - name: Daily Forecast
        unique_id: weather_forecast_daily
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: "{{ daily['weather.home'].forecast }}" 

  - trigger:
      - platform: time_pattern
        hours: /1
      - platform: homeassistant
        event: start
        
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: 
            - weather.home
        response_variable: hourly
    sensor:
      - name: Hourly Forecast
        unique_id: weather_forecast_hourly
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: "{{ hourly['weather.home'].forecast }}"

Imo this should be automatically be created when a weather entity gets created.

5 Likes

[quote=“The-May, post:9, topic:760083”]I stumbled upon this thread in search of a solution why there is no longer an attribute for the weather.
Thank you very much for the code snippet.
[/quote]
Has anything changed since then?

Im using OpenWeather as a provider, if i run weather.get_forecasts on it, i do get an array with the forecasts, but the template above doesnt work and the sensor is created just with this

attributes:
friendly_name: Weather Forecast Daily
forecast: null

This is my code:

    action:
      - service: weather.get_forecasts
        target:
          entity_id: weather.xxx
        data:
          type: daily
        response_variable: daily
  - sensor:
      - name: Weather Forecast Daily
        unique_id: weather_forecast_daily
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: "{{ daily['weather.xxx'].forecast }}"

Hasnt changed so far as i can see.
Im using it for my OPENHASP display and it shows everything i need.
i dont really know what the issue is on your hand though.

Here ist the most compact but still complete YAML code I could come up with.
It creates a weather template entity which is based on OpenWeatherMap including its forecasts, but uses my own sensors for temperature, humidity and dewpoint.

template:

  - trigger:
      # use this to update every minute during tests
      # - platform: time_pattern
      #   minutes: /1
      - platform: time_pattern
        hours: /1
      - platform: homeassistant
        event: start
    action:
      - service: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: 
          - weather.openweathermap
        response_variable: owm_daily
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: 
            - weather.openweathermap
        response_variable: owm_hourly
    sensor:
      - name: OWM Forecast, Daily
        unique_id: owm_forecast_daily  # this is NOT the entity_id!!!
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: "{{ owm_daily['weather.openweathermap'].forecast }}"
      - name: OWM Forecast, Hourly
        unique_id: owm_forecast_hourly  # this is NOT the entity_id!!!
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: "{{ owm_hourly['weather.openweathermap'].forecast }}"

  - weather:
      - name: "OpenWeatherMap & own sensors"
        condition_template: "{{ states('weather.openweathermap') }}"
        # --- mix in some of my own sensor values:
        temperature_template: "{{ states('sensor.aussen_temperature_calculated') | float }}"
        humidity_template: "{{ states('sensor.aussen_humidity_calculated') | float }}"
        dew_point_template: "{{ states('sensor.aussen_dewpoint_calculated') | float }}"
        # ---
        wind_speed_template: "{{ state_attr('weather.openweathermap', 'wind_speed') }}"
        pressure_template: "{{ state_attr('weather.openweathermap', 'pressure') }}"
        forecast_daily_template: "{{ state_attr('sensor.owm_forecast_daily', 'forecast') }}"
        forecast_hourly_template: "{{ state_attr('sensor.owm_forecast_hourly', 'forecast') }}"
2 Likes

For me it is still not working. Can you show what you get under “OWM Forecast, Daily” entity?

I do see supported_features: 3 for the newly created entty but when I open it I get no forecast. My current code is:

template:
  - trigger:
      - platform: time_pattern
        hours: "/1"
      - platform: homeassistant
        event: start
    action:
      - service: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: weather.arso_vreme_litija
        response_variable: arso_daily
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: weather.arso_vreme_litija
        response_variable: arso_hourly
    sensor:
      - name: "Weather Daily Weather Forecast"
        unique_id: weather_forecast_daily
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: >
            {{ arso_daily['weather.arso_vreme_litija'].forecast
               if arso_daily is defined else [] }}

      - name: "Weather Hourly Weather Forecast"
        unique_id: weather_forecast_hourly
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: >
            {{ arso_hourly['weather.arso_vreme_litija'].forecast
               if arso_hourly is defined else [] }}
               
weather:
  - platform: template
    name: "Ecowitt"
    condition_template: "{{ states('weather.arso_vreme_litija') }}"
    temperature_template: "{{ states('sensor.wittboy_pro_outdoor_temperature') | float(0) }}"
    temperature_unit: "°C"
    humidity_template: "{{ states('sensor.wittboy_pro_humidity') | float(0) }}"
    pressure_template: "{{ states('sensor.wittboy_pro_absolute_pressure') | float(0) }}"
    pressure_unit: "hPa"
    wind_bearing_template: "{{ states('sensor.wittboy_pro_wind_direction') | int(0) }}"
    wind_speed_template: "{{ states('sensor.wittboy_pro_wind_speed') | float(0) }}"
    wind_speed_unit: "km/h"
    forecast_daily_template: >
      {% set f = state_attr('weather.arso_vreme_litija', 'forecast') or [] %}
      {{ f | map(attribute='__dict__') 
            | map('dict',
                   datetime='datetime',
                   temperature='temperature',
                   templow='templow',
                   condition='condition',
                   precipitation='precipitation',
                   wind_bearing='wind_bearing',
                   wind_speed='wind_speed')
            | list }}

    forecast_hourly_template: >
      {% set f = state_attr('weather.arso_vreme_litija', 'forecast') or [] %}
      {{ f | map('dict',
                   datetime='datetime',
                   temperature='temperature',
                   condition='condition',
                   precipitation='precipitation',
                   wind_bearing='wind_bearing',
                   wind_speed='wind_speed')
            | list }}

I had to use that remap otherwise I got errors in log about too many data that weather template doesn’t support.

2025-09-05 19:29:14.141 ERROR (MainThread) [homeassistant.components.template.template_entity] Error validating template result '[{'datetime': '2025-09-05', 'temperature': 28.0, 'templow': 15.0, 'precipitation': 0.3, 'snowfall': 0.0, 'wind_speed': 3.0, 'wind_bearing': 'NE', 'condition': 'unknown', 'pressure': 1017.0, 'wind_gust_speed': 36.0}, {'datetime': '2025-09-06', 'temperature': 21.0, 'templow': 13.0, 'precipitation': 0.4, 'snowfall': 0.0, 'wind_speed': 4.0, 'wind_bearing': 'SE', 'condition': 'lightning', 'pressure': 1024.0, 'wind_gust_speed': 0.0}, {'datetime': '2025-09-07', 'temperature': 23.0, 'templow': 12.0, 'precipitation': 0.0, 'snowfall': 0.0, 'wind_speed': 4.0, 'wind_bearing': 'SE', 'condition': 'partlycloudy', 'pressure': 1021.0, 'wind_gust_speed': 0.0}, {'datetime':..