Template Weather Provider throws KeyError: 'condition_template'

Hi!
I’m trying to create a “Template Weather Provider” as per this.
My code is:

template:
  weather:
    -  name: "My PWS"
       unique_id: "my_pws"
       condition_template: "{{ states('weather.forecast_haus') }}"
       temperature_template: "{{ states('sensor.weewx_außentemperatur') | float }}"
       temperature_unit: "°C"
       humidity_template: "{{ states('sensor.weewx_luftfeuchtigkeit') | float }}"
       forecast_daily_template: "{{ state_attr('weather.haus', 'forecast') }}"

After reload I have this in the log:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 360, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/src/homeassistant/homeassistant/components/template/weather.py", line 162, in async_setup_platform
    WeatherTemplate(
  File "/usr/src/homeassistant/homeassistant/components/weather/__init__.py", line 269, in __call__
    instance: PostInit = super().__call__(*args, **kwargs)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/template/weather.py", line 186, in __init__
    self._condition_template = config[CONF_CONDITION_TEMPLATE]
                               ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'condition_template'

I tried three different weather providers, all of them with the same result.

{{ states('weather.forecast_haus') }} gives me snowy in the Template Tool.

Help would be highly appreciated.

I think you’re using the older template format. What you have in your post doesn’t match the example code on the template integration page. You have:

template:
  weather:
    -  name: "My PWS"

but the example is:

weather:
  - platform: template
    name: "My Weather Station"
2 Likes

Ok, I’ll give that a try. I thought this was interchangable…

Yep, that was it :man_facepalming:
I’m still struggling with the whole yaml syntax.
Thanks very much!

1 Like

A bit of necroposting, but I think Mathias was right that there’s an issue here. It’s newly relevant again due to deprecations in 2024.4.

There’s two different formats for Weather Templates:

Reviewing it, I think this GitHub issue matches your problem.

This issue is newly extra relevant, since the previously-deprecated forecast attribute is no longer available on Weather entities. As a result, the only game in town if you want a Template Weather Provider with forecasts is the “modern” format which supports actions (legacy format does not support it).