[YAML] Reuse information

Hi,

I currently build some MQTT sensors by hand. Each of them refers to the SAME device. To define a manual device, I have to set the device map every time.

What is the best practive to reuse this information for each sensor? Can I define a variable with the map and simply set device: myDeviceVariableWithTheMap? Dont hit me, I did not found out how…

Use YAML anchors and aliases.

Example

Thanks! That worked! I wonder, why this is not added as example inside the docs (or did I just not found it?)

Home Assistant’s YAML documentation only covers the basics about YAML. It includes a link to YAML’s official documentation which is quite extensive (covering every aspect of it in Home Assistant’s documentation would be impractical).

Here’s the link to Anchors and Aliases in YAML’s documentation (and it’s admittedly not the easiest to digest):

https://yaml.org/spec/1.2.2/#anchors-and-aliases

1 Like