Trouble creating scripts via the UI

I’ve been trying to add a new script via the HA UI. Every time I created one and hit save it appeared to save fine, but it never actually saves. It won’t appear in the list of scripts, and if I tried to run it after saving I get a not found error.

Thinking it might be because I used to have some scripts manually created I deleted the line script: !include_dir_merge_named configuration/script from my configuration.yaml and “Scripts” tab disappeared completely from the UI. I got the tab back again by adding script: back into my configuration.yaml but it’s working no better than before.

Am I missing some bit of config required to move over the UI managed scripts?

If you created a scripts directory within the configuration directory (i.e. the directory that contains the configuration.yaml file) then it should be this:

script: !include_dir_merge_named scripts/

I didn’t, I created it at /config/configuration/scripts. Even if the path was wrong I don’t think that should cause the UI to stop working?

If that’s where you created it (scripts) then the problem may be because you specified script here:

script: !include_dir_merge_named configuration/script
                                                     ^
                                                     |
                                            Missing 's' here

The script editor in the UI will only make and modify scripts in /config/scripts.yaml. To use it you need to have this in your configuration.yaml:

script: !include scripts.yaml

If you use default_config then you already have that. I assume you have removed default_config since that’s not happening for you.

If you still have other scripts made in YAML you want to use then you should also add something like this:

script my_yaml_ones: !include_dir_merge_named configuration/script

my_yaml_ones can be any text you want, that’s just an example.

Fwiw I bet if you looked in /config you’d find that the scripts you’ve been making are in /config/scripts.yaml. However since you are not including that file in your configuration nothing happens when you click save. It just ends up reloading all your other scripts and misses that one.

My configuration.yaml is many years old at this point and I keep finding I’m missing bits that are now provided in the default config. I should probably rebase on top of the default configuration.yaml at some point :sweat_smile:.

That fixed my problem though, cheers! You were right about a scripts.yaml existing with all the ones I’d attempted to make too. The decision to save to config/scripts.yaml regardless of config, but not load from it seems odd. The error here was very opaque and it feels very easy to put yourself into this invalid state. Maybe it’s time I finally found some time to make a HA PR and at least improve the error message or docs a little.

I don’t use default_config and have this in my configuration.yaml file:

script: !include_dir_merge_named scripts/

image

Guess where scripts I create via the UI go?
In configuration/scripts.yaml (not in configuration/scripts/scripts.yaml)

The scripts I create via a text editor are stored in several files within the configuration/scripts directory.