!include filename.yaml or four advanced options to include whole directories at once

Which option do you chose for make configuration files easier to keep track.

  • !include filename.yaml
  • !include_dir_list
  • !include_dir_named
  • !include_dir_merge_list
  • !include_dir_merge_named

0 voters

!include filename.yaml is the statement that tells Home Assistant to insert the contents of filename.yaml at that point
!include_dir_list will return the content of a directory as a list with each file content being an entry in the list.
!include_dir_named will return the content of a directory as a dictionary which maps filename => content of file.
!include_dir_merge_list will return the content of a directory as a list by merging all files (which should contain a list) into 1 big list.
!include_dir_merge_named will return the content of a directory as a dictionary by loading each file and merging it into 1 big dictionary.

4 Likes

I just have one file called configuration.yaml.

1 Like

Do you havenā€™t separate files like group.yaml, automation.yaml, sensor.yaml ?

group: !include groups.yaml
automation: !include automations.yaml
sensor: !include sensors.yaml
media_player: !include media_players.yaml
zone: !include zones.yaml
scene: !include scenes.yaml
light: !include_dir_list lights
switch: !include_dir_list switches

No, just one file. Anything else just makes things complicated, as you have apparently found out.

Youā€™ll get there :wink:

Iā€™m using all of the include statements except the _merge_-variants

input_boolean: !include input/boolean.yaml
input_select: !include input/select.yaml
input_number: !include input/number.yaml
automation: !include_dir_list automation
sensor: !include_dir_list sensors
binary_sensor: !include_dir_list binary_sensors
media_player: !include_dir_list media_players
notify: !include_dir_list notify
zone: !include_dir_list zones
device_tracker:  !include_dir_list devices
group: !include_dir_named groups
script: !include_dir_named scripts
shell_command: !include shell_commands.yaml
alert: !include_dir_named alerts
timer: !include_dir_named timers
switch: !include_dir_list switches


config/ # find . -name '*.yaml' -exec cat {} \; | grep -v '^#' | wc -l
3211

Sebastian

1 Like

Ok! You only not use !include_dir_merge_named and !include_dir_merge_list

I want add one more poll option like:

  • All cofigurations in configuration.yaml

How can i contact a moderator ? I face a message.

You cannot add or remove poll options after the first 5 minutes. Please contact a moderator if you need to edit a poll option.

ā€¦ and include_dir_merge_list.
Until a few minutes ago, I was using include_dir_merge_list for two items, but I noticed that thereā€™s no
real reason to do so.

So, for example, instead of using
media_player: !include_dir_merge_list <dir>

and then having to start every file with a dash:

- platform: kodi
  [...]

and

- platform: denonavr
  [...]

Iā€™m now using Ƭnclude_dir_list` and

platform: kodi
[...]

and

platform: denonavr
[...]

Sebastian

3 Likes

Thank you very much :grinning: for explain different between !include_dir_merge_list and !include_dir_list

There should be an ā€œAll of the aboveā€. I have all of them in my configuration. Each of them are better depending on the situation.

1 Like

Thanks that turn the Light on LOL

You missed ā€˜package basedā€™ configuration splitting, which is becoming more and more popular.

I hardly have any includes, but use packages instead.Some cleanup still needs to be done :wink:

homeassistant:
  customize: !include include/customize.yaml
  packages: !include_dir_named packages

frontend:
  themes: !include_dir_merge_named themes/
zwave:
  device_config: !include include/zwave_device_config.yaml

##########################################################
## Reloadable without restart
##########################################################

group: !include include/group.yaml

# fixed name and path for use with automation editor
automation: !include automations.yaml

script: !include include/script.yaml

##########################################################
## TODO: move these to packages
##########################################################

light: !include include/light.yaml
media_player: !include include/media_player.yaml
2 Likes

Which configuration can include in package. Home assistant documentation have some e.g.- switch, light, automation and group. Which other configurations can include in packages ?

Pretty much everything.