Splitting Configuration using packages

After using home assistant for around 3 years now I finally got to the point where my config file is now almost unmanageable and have decided to do an overhaul

Clearing out old commented out code and splitting the config.

I would like to do a folder structure to organise each of the components but just can’t get it to work.

I am using packages: !include_dir_named packages/ to do this.

If I put all my new .yaml files in the packages directory then they load and all seems good. But to my mind this is still not as un cluttered as it could be.

looking at the “packages” documents it looks like I should be able to add another level of folders under the packages folder

so I add for example folders called “lights” and “cameras” (the two I have done for now while i try to get it to work) and move the light.yaml and camera.yaml into there folders

Then I change the line from packages: !include_dir_named packages/ to packages: !include_dir_merge_named packages/

I run the configuration validation and I get this error

expected a dictionary for dictionary value @ data[‘packages’][‘light’]

Here is an example of each .yaml

  - platform: ffmpeg
    name: Rear Camera
    input: rtsp://xxx:[email protected]:8554/profile0

  - platform: ffmpeg
    name: Front Camera
    input: rtsp://xxx:[email protected]:8554/profile0

any ideas?

I believe you would need the wildcard under Advanced Usages

!include_dir_* packages

Thank but tried that as well

configuration validation reports

Error loading /config/configuration.yaml: could not determine a constructor for the tag ‘!include_dir_*’
in “/config/configuration.yaml”, line 4, column 13

I use packages and use a folder structure as you wish to, this is my config entry : -

  packages: !include_dir_named packages

This includes everything in and under packages

1 Like

yes. I made that docs PR regarding the second level recently and in order for it to work you need a package id at the beginning of every file as described here.
In your case outdoor_cams.yaml in cameras folder may look like

cameras_outdoors: # it actually can be ANYTHING provided it's unique across all your packages
    - platform: ffmpeg
      name: Rear Camera
      input: rtsp://xxx:[email protected]:8554/profile0

    - platform: ffmpeg
      name: Front Camera
      input: rtsp://xxx:[email protected]:8554/profile0
1 Like

So, any progress ?

So what a challenge. Not yet been fully successfully without breaking my setup and needing to do a few restores. Decided to order a second Pi so i can play with a new install and not keep breaking what I have (not great for WAF)

I will update here once I have a solution.

How about doing so in a virtual machine (if you have a PC/laptop)?

Been a while since I started this thread.

Following AhmadK I have now managed to split my configuration.yaml

I did it slowly 1 section at a time but not without issue.
I found that !includes seems to mess it up and still have the themes in the main configuration.

Only include that did work was secrets.

Hope this helps someone else.

really? do you have an example?
I use almost all of them and they do the job fine.

I currently have 2(!) packages and slowly add more. It’s fun and not as painful as it sounded initially - basically it’s just choosing the right folder structure, file/package name and then getting all stuff together in one file (I don’t use includes inside packages) refactoring some stuff as you go/afterwards.

Anyway, you’re getting there. Give us a shout if you need help.

Just to confirm, 2 years down the line, I found this after scratching my head at the documentation… @Mutt 's config entry works fine for me with subfolders.

I originally had packages set up with all yaml files in the same package directory, but now I have more than 30, I want to now use subfolders for ease of organisation.

The other instructions from AhmadK and on the home assistant docs are a bit confusing and if I’m understanding correctly I would have to to rehash every package file to add in that package id and indent everything below… not something I’d be looking forward to doing!

Maybe the docs could do with an amend to clarify this method works? I’d gladly submit a PR but I’m not sure how to word it without confusing even more…!

1 Like