In this good answer about using anchors and aliases, there’s an example in YAML that includes a block where the line starts with a period, then an anchor name. I can’t find anything in YAML about that and asked about it on Stack Exchange and was informed that YAML doesn’t use that kind of notation.
So apparently the dot at the start of the line is an ESPHome thing. Here’s part of the code used in the answer I link to:
What is it called and where can I find more information about using this technique to provide a name for an anchor and a data structure that will be used as a source for objects that are created later?
And, as best I can tell, undocumented anywhere - but I’d need to know the name of this kind of function to be sure. Kind of hard to search for it when you don’t know the name of what it is!
Thanks, @juergenjw. That’s under Anchors and Aliases, though, and well documented. What I can’t find is the use of a dot or period to create a name for a section to be used as an anchor. I asked about it on SE here, but the closest to an answer was a very short discussion in the comments.
I did some tests with your example and i think that for esphome it is a key that is ignored/hidden and is used as placeholder for the keys:values to be used by the merge.
You can name the key .anything or use only a single dot as key.
I was thinking that, but had not tested it. Still, I was hoping to find more about it, in case there were more uses for it or some behaviors I had not seen. And it’d be nice to know if there’s a name for it.
Really? Interesting. It had not occurred to me to check that.
I believe this is one of a few methods that are available to reuse bits of configuration.
Most of the examples show the “simple” (to explain, but not necessarily use) way of doing things, where each device has all the configuration for everything.
There are several ways to make everything the same (that needs to be the same) while still allowing things to be different (that need to be different). All of these methods require some means of indirection and some means of overwriting (what needs to be different).
I am not an esphome expert and don’t know what is the One True Way, but discovered these ways:
It seems anchor is an older or at least less well described solution to the problem. I did not see anything describing the pros and cons of the various options and currently don’t know enough about them to write one. I am currently using substitutions and packages (even with a single device).
It looks like the leading dot in the YAML is an esphome thing that is not documented (at least not clearly).
Thank you for some good information on this issue! I’ve found info on anchors in YAML, but much of it was simple or simplistic examples that left me with more questions than answers. (Which is one reason it was so hard to find out this isn’t a YAML thing.)
Thank you - yes, that’s what I thought, but confirmation is always good. When I have time, I’ll have to check on Discord and see if I can get a good answer from a developer.