PSA: Be careful of merging existing scripts to those created by the UI editor

In the vein of the recent “PSA’s” I thought I would add one based on my experience trying to help someone out in another thread.

I’m cross posting it here to call attention to this inconsistent behavior to warn others and to figure out if I had done something wrong as the reason it didn’t work.

in that thread the other user was trying to use their old scripts but also create new scripts in the UI editor.

So to help out I changed my config to have it point to my existing scripts folder using “script old:” and then using "script: " to point to scripts.yaml.

Everything went well and it all worked even after manually adding a script to (previously empty) scripts.yaml file. But then when I added a script using the UI editor suddenly all of my existing manually created scripts were no longer accessible in HA.

Here is the bottom line from that thread:

Well…I made some assumptions that the automation editor and script editor work flow would be the same.

That assumption was completely incorrect! :roll_eyes:

Apparently the way the script editor works is different than the way the automation editor works when related to the old existing stuff in your config.

The docs for the automation editor says you can keep your old existing automations separately from your automations created by the editor by adding an “extender” name onto the existing “automation:” entry. the docs recommend adding “old” onto it like “automation old:”.

But that doesn’t work at all for the script entry for scripts added using the UI scripts editor.

I just tested adding a script in the UI editor and using the equivalent config for the one recommended for automations and it ended up killing all of my old scripts.

So, yeah, the bottom line is don’t do that.

What’s strange is that you can add the “script old:” entry and it will still reference all of the included files in the “script old:” and also in the “script:” locations just fine.

BUT as soon as you create a script in the UI editor that then gets added to your “scripts.yaml” file then none of the scripts located in the “script old:” location are recognized any more.

Reloading scripts or restarting HA won’t fix it either. The only way I could get my old scripts back was to remove the “script: !include scripts.yaml” entry and point it to my old scripts again using “script: !include_dir_merge_named scripts/” and after a restart everything was back to normal again.

Did I do something wrong there, is this a bug that needs reported or is this one of those “design features”?

It doesn’t effect me at all since I never use the UI editor but it might effect others trying to do the same thing later.

2 Likes

Looking at my setup, my automations and scenes bring in both yaml and ui generated code. However, scripts does not. There is one key difference, my scripts include uses !include_dir_named while the other two use !include_dir_list.

For example here are my includes:

automation yaml: !include_dir_list ../../automations
automation: !include ../../automations.yaml

scene yaml: !include_dir_list ../../scenes
scene: !include ../../scenes.yaml

script yaml: !include_dir_named ../../scripts
script: !include ../../scripts.yaml

My GUI created automation co-exists alongside my huge library of yaml automations. A test scene I created existed alongside my yaml scenes. But, my yaml scripts disappear until I change the code back to:

script: !include_dir_named ../../scripts

script appears to be the only one of the three that doesn’t work if you add script old:.

Should this be reported as a bug?