CONFIGURATION.YAML: Multiple switches

More and more I get familiar with Home Assistant. I hope you can give me more clarity about the following.

Often I see to add [code] to configuration.yaml. I didn’t want to make that file too large, so I started to seperate configs into files per device.

I added 2 Broadlink devices, learned the IR codes and configured them.

In configuration.yaml I put

switch: !include _ir_beamer_office.yaml
switch: !include _ir_beamer_guest.yaml

The outcome was that only ‘guest’ was working, not office.

If I merge the into one, both devices work.

FILE: _ir_beamer_office.yaml:

  • platform: broadlink
    mac: C8:F7:42:74:FC:34
    switches:
    • name: Office - AIRCO
      command_on: ‘[learned code]’
      command_off: ‘[learned code]’

FILE: _ir_beamer_guest.yaml:

  • platform: broadlink
    mac: C8:F7:42:63:19:9A
    switches:
    • name: Guest - AIRCO
      command_on: ‘[learned code]’
      command_off: ‘[learned code]’

Why don’t the two seperate files not work, and if I merge them into one they do?

Thank you for your input.

I would look at using packages, as they are more versatile.

I put them all in a folder called packages and use them like this

homeassistant:
  packages: !include_dir_named packages

You should be able to do the same with your switch files. You will need to add the switch: into each YAML file.

Please review the community guidelines on how to ask a good question for how to properly format your YAML.

The important info is that you cannot include more than one file per domain in the configuration.yaml

If you want to separate you switches into individual .yaml files, it makes most sense to put them into a directory called e.g. switches and then refer to all the files in the directory to be included by adding

switches: !include_dir_merge_list switches/

to your configuration.yaml file.

Documentation is here:
Splitting up the configuration - Home Assistant (home-assistant.io)

1 Like