Regarding documentation or structuring HA, here is what I did (I am writing/updating all the files in yaml directly using the file editor of HA as I started to use HA a long time ago and all gui interfaces where not existing at that time):
- I am splitting my automations based on some kind of domains: one file for each domain. For example, I am naming my files containing Electrical Vehicule automations: EV_electrical_vehicule.yaml… Same approach for heaters, airconditioning, pool, etc…All these files are in a subdirectory of /config called automations.
In these automation files and for each automation, I am trying to document what the automation is doing, when it is triggered and what are the conditions to fullfill to be executed… adding some remarks if necessary to understand the reasons for some conditions, triggers or actions… For some automations, it is obvious what the automation is doing, but some can be very complex or tricky and needs to be documented. So I decided to document all the same way. example:
#=Done================================================================================================
#
# Calcul température de fonctionnement de l'electrolyseur et de la pompe de la piscine:
# - en été: de mars à octobre
# - suivant le mode de fonctionnement de refroidissement automatique et température piscine
# quand:
# - à l'heure d'extinction de la pompe pour calculer planning du lendemain
# - si changement de mode de refroidissement automatique
# conditions:
# - si le refroidissement automatique de la piscine est activé
# - et si la température de la piscine à l'entrée de la pompe à chaleur est inférieure ou égale à la température target pour le refroidissement
# - et si la température de la piscine (pour le calcul: voir sensors) est connue (comprise entre 5 et 50°C, la valeur doit être au moins 6°C pour faire tourner la piscine minimum 3 heures par jour)
# - ou si le refroidissement automatique de la piscine est désactivé
# - et on est en été (de mars à octobre)
# - et si la température de la piscine (pour le calcul: voir sensors) est connue (comprise entre 5 et 50°C, la valeur doit être au moins 6°C pour faire tourner la piscine minimum 3 heures par jour)
#
# les limites de fonctionnement sont calculées en partant de l'heure de milieu de plage et en retirant/ajoutant une nombre d'heures égal à la température de la piscine divisée par 4.
# Donc si la température de la piscine est de 6°C, la plage se situe donc entre la plage du milieu - 1,5 heure et la plage du milieu + 1,5 h...
#
- alias: calculate_time_montreal_ete
initial_state: true
trigger:
- platform: time
at: input_datetime.h_ext_pompe_m
- platform: state
entity_id: input_boolean.poolstage_refroidissement_auto
condition:
condition: or
conditions:
- condition: and
... etc etc ...
For each automation, I am writing some comments linked with steps into a message file (that I am closing everyday at midnight, keeping 7 version/days of those files)… So I can track easily by reading this file what steps where executed during a specific day and when… example:
2022-07-19 05:58:00 **** DM-014.1 Allumage Pompe Piscine
2022-07-19 05:58:00 **** DM-016.1 Allumage Electrolyseur Piscine Montréal
2022-07-19 06:00:00 **** DM-019.1 Extinction chauffe-eau Salle de Bain (haut) Montréal
2022-07-19 06:15:02 **** EV-001.1 Chargeur Voiture: demande extinction...
2022-07-19 06:15:11 **** AG-015.1 Theme set to light (day)
2022-07-19 06:18:11 **** MQ-015.1 Ecriture Heures Lever et Coucher du Soleil à Montréal (remote via mqtt)
2022-07-19 07:00:00 **** EM-001.1 Change Energy Tariff to the next one
2022-07-19 09:03:51 **** EV-003.1 Chargeur Voiture éteint...
As you can see, every record in the file contains the time the step of the automation was executed, a reference to the file where the automation was executed (EV for the last one, so related to EV_electrical_vehicule.yaml) a number+step to find the automation/step having generated the message and a comment about the step(s) executed…
- regarding dashboard, I splitted also all the tabs/paths by creating one file per tab/path. regrouping those files into a subdirectory called lovelace in /config directory… If for some reasons I have group of identical cards existing in multiple tabs, I am creating specific files for those cards. Those files are stored in another subdirectory of /config called tiles. I am incorporating the reference of that card into the lovelace yaml files for building one tab/paths… example:
#==============================================================================================
#**********************************************************************************************
#** **
#** Tableau de bord **
#** **
#**********************************************************************************************
#==============================================================================================
- title: Tableau de bord Montréal
path: montreal
icon: mdi:billboard
cards:
#
# Left Stack
#
- type: vertical-stack
cards:
#
# Cards for Alarm Off Display Status - MONTREAL
#
- !include /config/tiles/Alarme-Montreal-Titre.yaml
- !include /config/tiles/Alarme-Montreal-Status.yaml
- !include /config/tiles/Alarme-Montreal-Timer.yaml
- !include /config/tiles/Alarme-Montreal-Code.yaml
#
disadvantage: less flexibility in creating the layout of your different tabs.
advantage: If I change one file in the tiles directory, automatically all the tabs/path of lovelace using it are updated (instead of updating each file in the lovelace directory). I didn’t do this at the beginning but I decided to change the approach when the lovelace files where very long/difficult to maintain… This is a consequence of my decision to split my dashboard into multiple tabs…
-
I am using a lot of button-cards (installed using HACS) in lovelace, therefore I am using a lot of template cards to simplify the creation of repetitive cards (like lights cards, switches cards, alarms, heaters, airconditioning, etc…). This is simplifying the writing of those cards.
-
documenting sensors (in fact everywhere you use templates) is also a good idea as some templates could be very complex and difficult to understand when you come back a few months later and have to change it… for that one I have some home work to do to develop a good documentation…
This is the way I have organized my HA files, this is just of course examples and a feedback… I have two sites managed the same way with a dashboard with 27 tabs/paths in one location (the other one has only 15 tabs/paths). I have 335 automations on one site and 131 on the other one… Pretty big configurations, where a good documentation helps to maintain it.