Using "automation: !include_dir_merge_list automations/"

So,

Looking at this: Splitting up the configuration - Home Assistant, I got a wild hair and decided to try to “organize” my automations. Having some 1000 lines of text in configuration.yaml just hurt my head.

There aren’t that many, 25 I guess.

I inserted

“automation: !include_dir_merge_list automations/”,

into configuration.yaml create the automations folder, and then went moving copying each the automations from confiigurations.yaml into separate .yaml files under the /automations folder.

Rebooting, HA sees all my automations, but…

Opening any one of them, I’m getting:

“This automation cannot be edited from the UI, because it is not stored in the automations.yaml file, or doesn’t have an ID.”

This particular automation looks like this:

- id: tv_mode_on
  alias: "TV Mode - Lights On"
  triggers:
    - trigger: state
      entity_id: remote.bravia
      to: "on"
  actions:
    - action: script.evaluate_bulb_state

So, there is an id, but HA is not seeing it. This is what it looks like in settings->automations-> edit in yaml:

And, I am unable to edit the yaml in “settings->automations-> edit in yaml”, thus the screen grab

The only way to edit it is with Studio Code Server, or the inbuilt editor.

Any idea what the issue is here?

Thank you

First of all you likely got the following line

automation: !include automations.yaml

and you need the following likely besides

automation mine: !include_dir_merge_list automations/

Important is the word “mine” which could be anything you fancy.
Same applies for the last “automations/” which is a name you choose and it must match a directory you create within the config folder, which then holds the automations you want to use with include_dir_merge_list

finally a YAML file with an automation has to be a list, means it must start like this

- alias: TV Mode - Lights On

not just “alias:” … since as it said before … it must be a list-object

Ok,

I’m more confused than before.

The docs say

Advanced usage

We offer four advanced options to include whole directories at once. Please note that your files must have the .yaml file extension; .yml is not supported.

This will allow you to !include files with .yml extensions from within the .yaml files; without those .yml files being imported by the following commands themselves.

  • !include_dir_list 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.
  • !include_dir_named will return the content of a directory as a dictionary which maps filename => content of file.
  • !include_dir_merge_list will return the content of a directory as a list by merging all files (which should contain a list) into 1 big list.
  • !include_dir_merge_named will return the content of a directory as a dictionary by loading each file and merging it into 1 big dictionary.

I’ve got a folder not unlike this one:

I have no early idea what a “dictionary” applies to in this context.

The goal is to be able to see the automations in the Automation tool in HA, and be able to edit it in the Edit in YAML section.

All my automation files look like the one shown above. According to the documentation, there should be no “-id: xxxxx” in any of the files.

So, which if the four options is appropriate in my use case?

Sorry to be a pest.

I haven’t read the other posts, but I’ll just answer the question.

You cannot edit automations in the UI that are outside the automations.yam file. You can only view them.

Having this inside your configuration will allow you to edit automations in yaml or in the UI.

automation: !include automations.yaml

Using this in your configuraiton.yaml will limit you to yaml only but you can view it in the UI.

automation: !include_dir_merge_list automations/

EDIT: I read the other post. They are making the assumption that you are using automation: !include automations.yaml which you said you were not using. Meaning the advice is missing the mark. Their advice is showing you how to have automations that are managed only by yaml, and automations that are also managed by the UI, side by side but mutually exclusive. This does not mean you can organize your automations in folders while also using the UI.

Thank you,

This raises the obvious question:

Why is this functionality provided if it’s effectively “broken”?

One of the biggest hurdles I’m fighting with virtually every aspect of HA is the fact that so much stuff is shoved into just a couple of files.

I’m a really old school kinda guy in which the treatise “every subroutine should only be one page” was beaten into my head a long, long time ago.

Trying to manage this stuff, particularly with no ability to leave comments is really difficult for me.

So I need to decide how I’m going to do this.

cheers

Because automations.yaml is the ONLY place the UI uses to edit stuff.
Personally I’ll use the UI to scratch an automation, but I always move them out to other folders because subsequent edits for me are in YAML using Code Server.

The option is for people that want to edit the YAML, not for people that only want to use the UI.

The UI came many years later than YAML only. so that is the recent add-on.

Home assistant and its upstream yaml libraries have no concept of where the yaml comes from. It’s all combined prior to to being fed to each integration that uses it. To get around that limitation scripts and automations that are managed by the ui are assumed to come from hard coded filenames. This allows the ui to modify the files with 100% certainty.

If you want both GUI and YAML (one or the other for each automation, not both at the same time) you can do this:

automation: !include automations.yaml # GUI only automations
automation yaml: !include_dir_merge_list automations/ # YAML only automations