Last active
August 15, 2024 22:56
-
-
Save frenck/20a3236cf64bf5bbcb907ecc7cf665cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.