I assume you meant to say you are doing this so you do not have to find all automations that use the same set of entities (in a State Trigger). Your strategy is to centralize them in a file and simply !include the file wherever needed.
You could use YAML anchors and aliases but it amounts to the same thing (using a placeholder to represent information that is defined elsewhere) just without using a dedicated file. I don’t think it would be an improvement over what you have done.
BTW, how many automations do you have that effectively have the exact same State Trigger? I feel that might represent an opportunity to consolidate them into fewer automations.
Hi,
I don’t know of a better way but just wanted to say, that’s way cool. Had not even thought of doing something like that.
I’m curious, in that scenario does the trigger act like an OR or AND for the sensors? ‘sensor1 OR sensor2’ or ‘sensor1 AND sensor2’.
Cheers
Nick
The first example in the docs includes a State Trigger with multiple entities presented as a YAML list. What GAHA is doing is employing the !include directive which makes the YAML processor include information stored elsewhere.
I really just use it so I don’t have to edit the actual automation.
For example… I have an automation for doing various things when a motion sensor is triggered.
Then, I just append the new motion sensor to the motions.yaml trigger file.
Would be super useful if trigger entity_id’s accepted wildcards or regex as I have a standard naming convention and use the friendly name to distinguish what’s what.
There’s the recently introduced trigger_variables feature but, in its current form, it’s very limited (basically the variable only accepts a constant value).
The reason I mentioned consolidation is because if the exact same set of entities is used in many triggers then there’s potential for combining them into a single automation. Then there’s just one place where they all exist. If it cannot be reduced to a single automation then your strategy continues to be more convenient (i.e. centralized management of the State Trigger’s entities).
Agreed, I would avoid using an Event Trigger listening for every state-change.
If you have the time, can you give an example of what kind of automations are using the same State Trigger but cannot be consolidated into a single automation?
All of my automations are single automations. I use → python venv, all yaml, and automation: !include_dir_merge_list automation/ in configuration.yaml. I don’t like the gui stuff.
I use a standard naming convention and the !include …/triggers/some_file.yaml
In my automations I then set variables using trigger data.
So, I loved seeing the !include in the entity_id of a state trigger because I am currently using a script to write a list of entities to a file so I can copy it into an automation.
But, when I try the !include in the automation, I get an error trying to save it. Now, I am sad.
That didn’t work either. The automation editor does not like the ‘missing’ entities.
So, I made the change in the automations.yaml file and put the include in there. Now, it does build the automation with the entities in /config/triggers/frozen_food.yaml.
I expect that if I need to make a change to that automation, I’ll have to do the same thing otherwise it will save with the entities again.
This is very cool though. Now, when I add another food, I just have to add it to the script that builds my input_number file and that trigger file. On restart, they are all picked up.