YAML, do you want to play with me?

Home Assistants configuration is build on YAML files, which many systems and platforms are using today when configuring.

You can read much more about YAML on Wikipedia.

In this post I will give you my experience with YAML, and hopefully give you some good advice if you are going to play with it.

YAML itself is very readable files. They are easy to understand. Unfortunately this also means, that if you don’t do YAML files in a good way, you would get some really long files and then easily lose track of the configuration. More about “how to split up your configuration into multiple files” in a different post.

In Home Assistant YAML files much always have a file extension on .yaml, for example guestbathroom.yaml.

1. Indentation
The most important thing in YAML files is indentation.

Det absolutte vigtigste i YAML filer er indrykning. It should be 100 % correct or the file and configuration is invalid.

Indentation is per definition always two spaces. Some editors help you with the TAB-button, while others do it on line change – at least to the level of indentation you are on in the code.

Below you can see a correct indentation on a piece of YAML code from my configuration.

2. Comment your files

A good thing I always do, when I code, is to make comments that shortly describes what the purpose is of a given function, trigger etc.

In my code shown above it’s basically commented through my text in the alias key: Do something when movement is registred in guestbathroom.

I have also other comments in my files. These comments indicate what the purpose of the file is and the type of configurations the file consists of – you can see it as some kind of headlines in the file. It makes it easy to search for specific areas in the file.

Comments in YAML is done by a starting the line with a # followed by the comment.

An example could be:

In general my experience is that YAML itself it quite simpel and super easy to build in.

I hope this post gave you a little insight, so you are ready to play and build with YAML.

3 thoughts on “YAML, do you want to play with me?

  1. Ved du hvordan kan det være at denne i min config fil kun skal have en (1) indrylning? når alle andre jeg laver har 2?

    username: !secret tuya_username
    password: !secret tuya_password
    country_code: 45
    platform: tuya

  2. nå , din kommetar boks sletter mellemrummet
    men alt efter tuya: har kun et mellemrum

    username: !secret tuya_username
    password: !secret tuya_password
    country_code: 45
    platform: tuya

  3. Hej René,

    Nej, det har jeg ikke bud på. Det lyder meget underligt. Har du prøvet at slette linjerne og danne dem på ny ved at skrive dem?

    Jeg tænker – kan der være et “skjult” tegn et sted, som måske driller?


Leave a Reply

Your email address will not be published.