Split your configuration up in multiple files

After some time doing a lot of stuff in configuration.yaml, I found that I needed to make a much more clean setup, where things were split up in multiple files instead of all automations being in automations.yaml etc. Basically my configuration.yaml and automations.yaml files contained thousands of lines making them confusing to look at or modify.

I read the documentation regarding splitting up the configuration.yaml file into multiple files (official documentation here), which seems both logic and easy. Before I did it I however sad down and made a list on how to do it, for example by the use of folders.

I split up my usage in the following to types:

  • File Merge
    This is used with the !include_dir_merge_list. It will find all files in the folder and merge them together to one big list, meaning that I can place multiple files in a folder and Home Assistant will find the files and merge them without me needing to change the configuration.yaml file.
  • File Reference
    This is where I use a folder containing multiple files, but where I point to a specific file in the folder in my configuration.yaml.
    This covers a lot of my integrations, like IHC, HomeKit etc.
Folderautomations/File Merge
Foldergroups/File Merge
Folderintegrations/File Reference
Folderlights/File Merge
Folderscenes/File Merge
Folderscripts/File Merge
Foldersensors/File Merge
Foldersetup/File Reference
Folderswitches/File Merge
Foldervariables/File Reference

After this I created the folders through Visual Studio Code (one of my add-ons installed), took the content from my existing files and placed them in the different folders.

Below you can see some chosen examples on how my files look like afterwards:





The examples shows two files that will be merged to one list (lights/room-entrance.yaml and lights/room-livingroom.yaml), but you will also see an example where I referer to a specific file (integrations/tplink.yaml).

You could say that if the files in a folder is for the same integration, then you should use file merge, and if the files in a folder is for different integrations, then you should use file reference. For example in my integrations-folder I have different files for different integrations like IHC, HomeKit, iRobot, while in my automations-folder I have files for the automation-integration.

Furthermore you should remember that in each file you should not start by defining the integration. It’s already defined in configuration.yaml, for example:

What I have done in my automations-folder is that I have created files per room, so it’s easier to have a file-based overview. All related automations for your livingroom is in the same file, while all related automations for our entrance is in another file. This makes a much more clear overview and easier to find the YAML code you are searching for, add extra code og modify existing code.

I didn’t do this from the beginning, and I regret that today. I took some time changing all of this from my old method to this new method, but I was worth the time. Everything is much easier now.

Leave a Reply

Your email address will not be published. Required fields are marked *