Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
---
#
# Let first talk about the different types in YAML
#
# It is important to understand the differences and terms.
# Not just for configuration splitting, but in general!
#
# Scalar values: String, Integer, Float, Boolean, Null
# Comments
# Collections: List (sequence), Dictionary (mapping) (important for splitting!)
#
# PS: Yes, this is not the full list ;)
#
# Strings
string: "Hello"
string2: Hello
# Integers
integer: 1
## Integers gotcha
this_is_not_what_you_think: 014 # This is actually 12! Leading 0 means octal!
# Floats
decimal: 0.1234
# Null
hassio: ~
discovery:
# Comments
# Yeah... there is a lot of comments in this file
# Booleans vs strings, boolean variants to avoid
# Use these 2 in general: lower case true & false, avoid the others
yes: true
no: false
other_yes: yes
other_no: no
# not boolean
language: "no"
string_true: "true"
# List (sequence), Array
this_is_a_list:
- hi
- again
- :)
this_is_also_a_list: [1, 2, 3, 4]
this_is_also_a_list_extended:
- 1
- 2
- 3
- 4
# Dictionary, Dict (mapping), Associative Array
dictionary:
item1: value
item2: another value
---
#
# Long strings are hard to read!
#
# Especially when using templates (Jinja2), this can becomes really hard.
# Any line of text that goes out of your screen, is just insanely hard to read.
#
# Multiple options, depending on the use case:
# `|` -> Literal style (Preserves new lines, but removes double new lines)
literal_example: |
This example is an example of literal block scalar style in YAML.
It allows you to split a string into multiple lines.
literal_example_same_as: "This example is a example of literal block scalar style in YAML.\nIt allows you to split a string into multiple lines.\n"
# `>` -> Folded style (Does not preserve new lines)
folded_example: >
This example is an example of a folded block scalar style in YAML.
It allows you to split a string into multi lines, however, it magically
removes all the new lines placed in your YAML.
folded_example_same_as: "This example is an example of a folded block scalar style in YAML. It allows you to split a string into multi lines, however, it magically removes all the new lines placed in your YAML.\n"
# Chomping indicators!
#
# No chomping operator (Clipping) (`|` and `>`):
# Keep last new line, remove additional new lines.
#
# Strip operator (`|-` and `>-`):
# No trailing new line, any additional new lines are removed at the end.
#
# Keep operator (`|+` and `>+`):
# Trailing new line, and keep all additional new lines in the end.
# Clipping/no chomping (Can be usefull)
no_chomping: |
This literal operator has no chomping operator/indicator.
Awesome!
no_chomping_same_as2: "This literal operator has no chomping operator/indicator.\nAwesome!\n"
# Strip chomping (Learn and use the `|-` and `>-` you'll need them in 90% of the cases)
strip_chomping: |-
This literal operator has no chomping operator/indicator.
Awesome!
strip_chomping_same_as2: "This literal operator has no chomping operator/indicator.\nAwesome!"
# Keep chomping (Forget this one...)
keep_chomping: |+
This literal operator has no chomping operator/indicator.
Awesome!
keep_chomping_same_as2: "This literal operator has no chomping operator/indicator.\nAwesome!\n\n"
#
# Why?!?!
#
why: https://github.com/frenck/home-assistant-config/blob/master/config/automations/areas/bedroom_flynn/window_climate.yaml#L28
#
# Lets talk Home Assistant!
#
# https://www.home-assistant.io/docs/configuration/splitting_configuration/
# Single include on the spot, result whatever is in the included file
first: !include file.yaml
# Each file is an item in the list, result is a LIST!
# https://www.home-assistant.io/docs/configuration/splitting_configuration/#example-include_dir_list
second: !include_dir_list ./second
# All files merged into one big list (files MUST contain a list), result is a LIST!
# https://www.home-assistant.io/docs/configuration/splitting_configuration/#example-include_dir_merge_list
third: !include_dir_merge_list ./third
# Merge all files into a directory using the filename as the key. Result is a DICTIONARY!
# https://www.home-assistant.io/docs/configuration/splitting_configuration/#example-include_dir_named
fourth: !include_dir_named ./fourth
# Merge contents of all files. Result is a DICTIONARY!
# https://www.home-assistant.io/docs/configuration/splitting_configuration/#example-include_dir_merge_named
fifth: !include_dir_merge_named ./fifth
#
# Secret trick. Loading the same integration multiple times.
#
# Not documented (I think), limited support I assume.
# But it can be helpful.
#
# This loads the old file (your current automations)
# This file is also used by the automations editor in the UI
automation: !include automations.yaml
# This loads the automations in a split file structure.
automation drzzs: !include_dir_list automations
# This allows one to migrate to a split config structure slowly!
@rpbx

This comment has been minimized.

Copy link

@rpbx rpbx commented Mar 29, 2020

Hello @frenck,

When on drzzs stream you started saying why it might be a good idea to still keep ID's when splitting up the files. However, you got rudely interrupted:)) Would you mind sharing that secret?:)

Thank you!!

@nickh66

This comment has been minimized.

Copy link

@nickh66 nickh66 commented Apr 7, 2020

Yes i agree. This secret would be a game changer for me.

I did once go though the effort to split all my automations into separate files. I soon really missed the GUI editor for the easy ability to get at least a basic automation started. Also, the fact that manual automations without an id would not appear in the UI either. So I quickly changed back to all automations inside automations.yaml.
This video was very insightful because i can now use both methods & slowly move completed automations to a split folder structure.
It would be such a bonus to be able to a split folder style structure for automation storage while still retaining the ability to create & edit in the UI would be awesome.

@casimiroc

This comment has been minimized.

Copy link

@casimiroc casimiroc commented Apr 23, 2020

Very useful ! thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment