Transforming sensor.yaml from old to new format

Hi community,

I trust I am not the only one struggling with templating sometimes.
here is yet another case that I cannot figure out despite quite the internet research…
I want to update my sensor.yaml from the legacy format of templating sensors to new format.

OLD Format Example:

- platform: template
  sensors:
    outside_temp:
      friendly_name: "Outside temperature"
      unit_of_measurement: "°C"
      value_template: "{{ state_attr('weather.myweather', 'temperature') }}"
    outside_humidity:
      friendly_name: "Outside humidity"
      unit_of_measurement: "%"
      value_template: "{{ state_attr('weather.myweather', 'humidity') }}"

I have updated according to the documentation of homeassistant to this:

- platform: template
  sensors:
    outside_temp:
      friendly_name: "Outside temperature"
      unit_of_measurement: "°C"
      value_template: "{{ state_attr('weather.myweather', 'temperature') }}"
    outside_humidity:
      friendly_name: "Outside humidity"
      unit_of_measurement: "%"
      value_template: "{{ state_attr('weather.myweather', 'humidity') }}"

if I do I will get the below error:

Invalid config for [sensor]: required key not provided @ data[‘platform’]. Got None. (See /config/configuration.yaml, line 10).

I will most certainly continue to investigate myself, but maybe someone can boost this transformation.

happy sunday ya’ll!

Holger

Your “Old” and “updated” are exactly the same…

Regarding the error message:

The newer method is set up under the template top-level key, not sensor. As such, the newer configuration cannot be placed in the sensors.yaml file, it must be placed in configuration.yaml or another properly included file (many people use templates.yaml).

isn’t it beautiful? It took me minutes making sure to format everything the right way and then this is the result.

But I see what you mean. I guess I will try this accordingly. Thanks, this is indeed something I overlooked.

Give me a few days and I will let you know. Thanks a million @Didgeridrew !