Template switch and yaml

Hi all

This weekend I have decided to tidy up my yaml and convert any old template sensors to the newer format, so far so good, I now have a template.yaml included.

In the template.yaml I have the following:

- sensors:
    sensor_1:
      friendly_name: "freindly name 1"
      ....    
    sensor_2:
      friendly_name: "friendly name 2"
      ....

- binary_sensors:
    binary_sensor_1:      
      friendly_name: "binary_sensor_1"   
      .... 
    binary_sensor_2:
      friendly_name: "binary_sensor_2"
      .....

I have removed all these entries from the original yaml and so far every thing is working as expected.

HOWEVER:
I have several template switches that I also waned to add to the same template.yaml but seem unable to no matter what formatting I try:

My current switch.yaml is formatted like this at present:

- platform: template
  switches:
    switch_1:
      friendly_name: 'template switch 1'
      ....
    switch_2:
      friendly_name: 'template switch 2'
      ....

I have tried several different ways to add these to template.yaml and no matter what I try I always end up with errors in the logs.

I assume something like this would work:

- sensors:
    ....

- binary_sensors:
    ....
    
- switches:
    switch_1:
       friendly_name: 'template switch 1'
       ....

But I get the following errors in the logs:

Invalid config for [template]: [switches] is an invalid option for [template]. Check: template->switches. (See /config/template.yaml, line 314).

(ERROR) config.py The entity definition format under template: differs from the platform configuration format.

Am I being stupid here or missing something obvious?

TIA

Rossk

According to the documentation, the new template definitions only applies to sensors, binary (on/off) sensors, buttons, numbers and selects. For Switches the old format still applies as far as I can tell.

2 Likes

Your a Gent…I suspected as much but failed to get a definitive answer from anywhere I was looking.

1 Like
template:
- sensor:
  - name: ...

- binary_sensor:
  - name: ...

- number:
  - name: ...

- select:
  - name: ...

- button:
  - name: ...

switch:
- platform: template
  switches:
    xyz:
      friendly_name: ...

It’s going to take quite a bit of refactoring to get the other legacy templates into the new format as they have way more going on in them.

1 Like

OK Thanks for the clarification, at least I can stop wasting my time now :slightly_smiling_face:

Best to just leave the switches.yaml as it is for the time being I guess.

FYI, the docs tell you what’s available in the new style if you know how to read the docs.

1 Like