Packages vs insertion operator

Currently a lot of my device configs are copies of each other. I’m looking to extract common configuration for particular devices into separate files that are then used by the device config files.

There seem to be two ways:

With packages:

  foo: !include <file>

( I don’t know what foo represents here by the way.)

With the YAML insertion operator:

<<: !include <file>

Are there differences between the two that I should know about? What are you using in practice?

I tend to use the packages: way as it will merge duplicated blocks from included files together. For instance if you have multiple sensor: blocks in your package included files and in the base yaml file they will all get combined. This can be done with the insertion operator but included files get added inline to the base yaml file. So if the base yaml file has a sensor: block, the insertion operator adding a file with more sensors would need to be in this block and the included file could only have sensors to get added. Using packages with the !include substitutions becomes very handy.

Oooh, I had actually tested if I could have sensors in an include file and in the including file and since I got no error message I assumed that it works. Prompted by your response I checked the combined output file and found out that the sensors in the include file are silently discarded.

Packages it is then.

By the way, can I somehow flag the package files so they aren’t treated as devices (shown as “OFFLINE”) in the dashboard?

Yeah. Name the file starting with a period or make a subdirectory.


To hide these base files from the dashboard, you can

  • Place them in a subdirectory (dashboard only shows files in top-level directory)
  • Prepend a dot to the filename, like .base.yaml

I read that but the way I understood it, that makes them disappear completely and I cannot edit them any more.

Good point. They don’t show up in the dashboard to use the ESPhome editor. They can be opened using the web based file editor add-on but you loose some of the error checking.

This might be a good feature request to submit. Add option for dashboard to show hidden files or add option for editor to open up files referenced by an !include.