It seems that I can only use !include after a colon and it needs to complete that context. It cannot be a partial snippet. It’s almost like the parser is fed the !include directly rather than inserting the external file and then parsing the end result.
So this is a yaml parser thing. HA is oblivious. You can’t just insert new key/value pairs that HA doesn’t already expect. Instead, you’ll either need to create dummy objects to define your anchors or annotate as you go. Here’s what I came up with:
I’ve since used this technique on multiple config and automation files. Note that the HA ‘visual editor’ will expand all your anchors. It’s best to make these files external (i.e. read-only).
The { } is more compact and no indentation worries. The anchors will work either way.
I realized later that my inline yaml may not format as nicely on the forum-- especially mobile. On a monitor, the forum wastes 1/3 of the screen width. The line length is not a problem for local editing.
This method may be used in cases when similar “input_text” entities are initially defined in different packages.
Ofc, if they are defined in the same package - yaml-anchors are sufficient.