On splitting up the config


So I have two broadlink devices with a boatload of IR codes in them. This config is very verbose but stable, I don’t need to edit these files once I have the codes in there.
I tried to factor each broadlink device in it’s own switch YAML;
broadlink_downstairs.yaml and broadlink_upstairs.yaml and I include them into the configuration.yaml like so :

switch: !include broadlink_upstairs.yaml 
switch: !include broadlink_downstairs.yaml 
switch: !include switches.yaml 

Both files look something like this:

- platform: broadlink
  host: 10.0.X.X
  mac: '34:EA:34:8D:XX:XX'
  type: rm_mini
  timeout: 15
      friendly_name: "Fan"
      command_on: 'JgDiASkPKg0Dikq6yygPKA8pDikqAA0FDioNKg0q'
      command_off: 'JgAEASkPKQ4NKg4qDSAAAA=='
    etc ...

However, that does not fly as I get this error in the log :

ERROR (SyncWorker_0) [homeassistant.util.yaml] YAML file /config/configuration.yaml contains duplicate key “switch”. Check lines 158 and 161.
ERROR (SyncWorker_0) [homeassistant.util.yaml] YAML file /config/configuration.yaml contains duplicate key “switch”. Check lines 161 and 162.

Is what I attempt possible or not? What can be done?

The why seems fairly obvious, you are only allowed one section named switch, and you have effectively created 3.

How to fix it as you want and have 3 seperate files I don’t know. Can you have nested includes? I don’t have the time to try iy now, and someone will probably chime in and say it doesn’t work, but something like:

switch: !include all_switch.yaml

Then in all_switch.yaml:

!include broadlink_upstairs.yaml 
!include broadlink_downstairs.yaml 
!include switches.yaml 

No idea if it will work, but worth a try.

You can only have one switch: declartion in your configuration.yaml file.

Use !include_dir_merge_list to add all your seperate switch files that you have put in a directory of your choosing:

1 Like

Ah - that’s simple…

yep, include_dir_merge_list is the way to go if you want to split things that are list elements.

and in you need to split a file that contains an array (like input_boolean), use include_dir_merge_named.

Hi All,

I have a question im trying to split up my confg but keep getting errors

my configuration looks like this

packages: !include_dir_named packages
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

This is fine, however if i try to add, sensors: !include sensors.yaml i get errors.

my understanding was i should really be able to use and name at all for example
test: !include test.yaml

Please Help

sensor: !include sensors.yaml

The bit before the first “:” (called the key, “sensor” in this case) must be something recognised by home assistant as a platform/integration or custom component.

So no. You cant use “test:”, or sensors: it must be sensor:

Hi @tom_l, thanks i obviously misunderstood. however i have entered this exactly as i typed it and im still setting errors.

this is how i have it

packages: !include_dir_named packages
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensors.yaml


i am using file editor to edit my yaml and doing this i cant even save and restart.

Apologies im very new to this.

Possibly needs a / after packages:

  packages: !include_dir_named packages/

When you run the config validation tool what errors do you get?

Just in case:
To run the config check, go to your profile and enable Advanced Mode.
The tool should then be in the Configuration / Server Controls menu.

Hi Tom,

Im getting the following error.

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

for refference this is my config now


However if i use this


that works but my sensors dont work

in my config folder i have a folder called sensors, in that file i have different .yaml files for different sensors



im probably doing this all wrong.

thanks for your help

in your timedate.yaml, no sensor: is needed

# Time & Date
- platform: time_date
  - 'date_time'

still didn’t work, have moved everything back to the config.yaml