Save yourself time (and code) with YAML anchors #790
13robin37
started this conversation in
Show and tell
Replies: 1 comment
-
Am I right in thinking this won't work if I have my views split up into separate yaml files? I get an error "unidentified alias" when I try, and a quick google search seems to indicate they only work within the individual file... :( |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This little trick might come in handy for people with lots of views, cards, whatever: YAML anchors!
The concept isn't very hard but a little tricky to implement sometimes. With YAML anchors you can write code for a card one time and use it at other points within your dashboard without copy-pasting the code - you just insert the YAML anchors (kind of like a variable) and Home Assistant does the rest.
Just to give you 1-2 examples: I don't want to copy-paste my chips for every view once I make adjustments (I have more than ten views).
With the help of
*header-chips
I can now re-use the cards configured here for other views.Home assistant will process it like this:
You can also configure anchors and change single variables. This is handy to implement cards that should look the same everywhere but have different entities (like a light or script card for example).
To adjust single variables you can't just insert the anchor and write the variable in the following line. Instead you need to use
<<:
- to make it work it has to look like this:This results in the following code:
Boom! If you ever want to adjust your light card, you just need to change a variable at one point in your dashboard.
This makes it super easy to maintain your dashboard and implement lots of changes at once. You don't need any extra cards for this. Any questions - feel free to ask. I've cut my dashboard code in half with this.
Beta Was this translation helpful? Give feedback.
All reactions