The !include directive is used to assign a value to an option. For example, this will assign the contents of groups.yaml to the group option:
group: !include groups.yaml
If we apply that to your Feature Request, it would be:
variables: !include var.yaml
However, currently !include is used for assigning values to domains in configuration.yaml (or packages). You want to extend it for use in automations. Effectively, your FR is requesting a means of creating global variables (because more than one automation can reference the same variables file).
I like the concept of global variables but I’m not sure this is the best way to implement them.
What I see in your example is that your variables are simply aliases for existing entities or an entity’s state. Sometimes I do that in a single automation (if the automation refers to the same entity, or state, in multiple places) but I haven’t found much need to share the exact same variable in another automation.
Rather than importing an external file containing multiple global variables (which I may only need some but not all of them), I would prefer to reference the global variables individually and directly in the automation. For example, perhaps something like this:
the main problem around this req is the fact, that the WHOLE ha configuration is one big yaml document regardless split into several files. I mean configuration, automations, even themes - all is the single yaml document.
Separate files representing its parts are joined and then parsed without any soace for preprocessing
It causes several issues:
if one part has some issues, likely whole yaml is rejected from liading. Recently I had some minor typo in a theme (btw copied from some foreign repo) which caused that HA didn’t recover after restart (even if it could fallback to default theme, but it didn’t)
there is no space for any variables, preprocessing etc. there are techniques to create custom attributes to be used elsewhere (anchors), but those cannot be rewritten locally, not impacting their other appearances. it might be useful for some usecases while not for anothers.
To me whole HA config deserves overhaul.
edit: in contrary to taras’ example above I see no justify to create globals after sensors. making one identifier from another, adding new ones with new entities doesn’t make sense to me.
I would like to be able to have template of entity(s) which I can include after setting local variables. those variables would be resolved in the template. It would create tents of similar entities which differs only by their root name
I know I can achieve it with pre-generating yamls , but this is not the approach I accept (to have maintain one language which describes method to create configuration for another language is overkill imo)