Home Assistant has a secrets.yaml file in the root folder of the configuration. The purpose of this file is to store usernames and passwords instead of having these set directly in the different YAML files. You can also store other things in the file, like IP-addresses, tokens etc. In your other YAML files you can then reference to the secrets listed in secrets.yaml.
You basically only need this if you share your Home Assistant configuration with others, or if you want to backup your configuration towards GitHub or other providers.
You can read about secrets.yaml in the official documentation here.
secrets.yaml is quite easy to use, so I would deep dive into an explanation, so you get the short version.
In my configuration.yaml I have multiple places where I write !secret followed by a name. Consider the “name” as a variabelname. So if I for example write !secret ihc_username, Home Assistant then expect that “ihc_username” is defined with a value in my secrets.yaml.
Look at the example below:
configuration.yaml:
1 2 3 4 5 6 7 8 9 10 11 |
homeassistant: latitude: !secret ha_latitude longitude: !secret ha_longitude elevation: !secret ha_elevation ihc: - url: !secret ihc_url username: !secret ihc_username password: !secret ihc_password auto_setup: false info: true |
secrets.yaml:
1 2 3 4 5 6 7 |
ha_latitude: 56.449736 ha_longitude: 9.391175 ha_elevation: 41 ihc_url: 'http://xxx.xxx.xxx.xxx' ihc_username: mit_brugernavn ihc_password: min_adgangskode |
This makes it easy for me to share code on my blog without worrying if I forgot to remove a username, password or token. Furthermore I can without issues backup my configuration to GitHub and also make it a public repository on GitHub for everybody to look into.
Super cool and extremely easy to use.