Home Assistant Config Maintenance
I was inspired to finally start cleaning up my Home Assistant config file last night after watching Dr Zzzs and Franck talking about how YAML works. It's interesting to note that YAML is used outside of Home Assistant, something I was not always aware of and there are various way to write the same thing in YAML. Getting a good understanding on how the language work helps a lot when working with your config. Very, very simply put yaml, has either a list or a dictionary.
#List with 2 item - From my automations for example - id: '1552475178483' alias: (Gate) Check Gate is Closed trigger: platform: time at: '22:55:00' action: service: switch.turn_off data: entity_id: switch.gate_open - id: '1552488155107' alias: Number Plate Reader trigger: - event_data: entity_id: image_processing.openalpr_gate plate: XXXXXX event_type: image_processing.found_plate platform: event action: - data: entity_id: cover.gate service: cover.open_cover
#Dictionary with 2 item - your main config is a dictionary doorbird: devices: - host: 192.168.1.XXX username: !secret door_bird_user password: !secret door_bird_password token: !secret door_bird_token name: Door Bell events: - doorbell_1 - motion_detected_gate input_datetime: only_time: name: Bedroom Lights On has_date: false has_time: true
It would be best to see the fully explanation here:
The main take away I found useful to know is that in your configuration.yaml file you can load an integration twice. The example was given for automations:
automation: !include automations.yaml automation whateveryouwant: !include_dir_list automations
You may have a file that contains a lot of automations in one file including the ones generated in the GUI and on the second line you can also load your automations created in the text editor from a directory /config/automations each file in that directory will be one automation. This can be helpful to slowly sort all your files out instead of doing one big change over and having lots of errors.
To breakup your config you can use the following directory types:
#Will return the content of a directory as a list with each file #content being an entry in the list. The list entries are ordered #based on the alphanumeric ordering of the names of the files typeone: !include_dir_list typeone #Will return the content of a directory as a list by merging all #files (which should contain a list) into 1 big list typetwo: !include_dir_merge_list typetwo #Will return the content of a directory as a dictionary which #maps filename => content of file. typethree: !include_dir_named typethree #Will return the content of a directory as a dictionary by #loading each file and merging it into 1 big dictionary typefour: !include_dir_merge_named typefour
So I went ahead and started sorting my config out with this information and everything is still working, which is great. Even though I removed script: !include scripts.yaml from config, and replaced it with script: !include_dir_names scripts for some reason home assistant GUI would place the new script in the file scripts.yaml and if you don't have a scripts.yaml file you can't edit script at all in the GUI.
Anyway I will continue and let you know how operation config cleanup goes.