YAML variables

I recently learned about this on a docker conference, YAML has the ability to use ‘variables’. The syntax is kinda funky but you can make your lovelace config (for example) more DRY. Since I never saw anyone using this I thought I let you guys know :slight_smile:

Spec:
https://yaml.org/type/merge.html

Lovelace example:

3 Likes

I have seen that syntax many times before, but I never took the time to understand what was going on. I like the idea of this. I am going to try it right now on the compact header on my Lovelace. :slight_smile:

For example: https://github.com/notoriousbdg/Home-AssistantConfig/blob/master/packages/battery_alert.yaml#L231

1 Like

Yes, they are called node anchors. You can use them anywhere within the YAML files - including traditional yaml config, lovelace, and even Dockerfile files. They are definitely useful - eliminate the duplicates and promotes re-use within YAML. You define once, and use it everywhere - later if you want to modify, you only have one place to modify. Comes in handy!

2 Likes

If working with packages, could one create a node anchor in one ‘common’ file and reuse it in other files?