Script editor and split up files

is it possible to both use the script editor and have split up files for scripts?

I have managed this with automations thanks to automation old but cant find anything similar for scripts

1 Like

Just do the same

script: !include scripts.yaml
script old:  !include wherever your old ones are

To clarify, ā€˜oldā€™ isnā€™t some kind of special command, itā€™s just a way of separating your components. It could just as easily beā€¦

automation bob:
2 Likes

unfortunately it doesnt work.

tried
script: !include scripts.yaml
script bonus: !include_dir_merge_list scripts/

Scripts are not lists, you need to use dir_merge_named

Still doesnā€™t work.
It just refuses to read any folder after loading the first scripts.yaml

What does?

Used dir_merge_named but it never reads from the second script entry in configuration.yaml

Yeah what doesnā€™t? Do they appear in HA and just not in the script editor, or do they not appear in HA at all?

How have you organised your split scripts?

Only scripts that loads in HA is from the original scripts.yaml

Currently i have only one file in the config/scripts folder
scripts_harmony.yaml

in the file I have multiple scripts for harmony in the style as:

whatson:
  alias: Vad Ƥr det pƄ tv
  sequence:
    - service: remote.send_command
      data:
        device: 49114562
        entity_id: remote.harmony_hub
        command:
        - green
        - DirectionRight
        - back
        delay_secs: 5

script: !include scripts.yaml
script specific: !include_dir_merge_named scripts

Needs to be one script per file, and I havenā€™t used dir_merge_named for a while but I think you put the name of the script as the name of the file, and then start the contents of the file with alias: and sequence: up against the left edge.

Ignore the last bit, Iā€™ve just been back through my GitHub commits and checked.

Did it work for you in the end? I got the same problem.

I tried the following:

script: !include scripts.yaml # UI generated scripts
script manual: !include_dir_merge_named scripts/ # Manual scripts

That does only load scripts.yaml

Another try:

#script: !include scripts.yaml # UI generated scripts
script manual: !include_dir_merge_named scripts/ # Manual scripts

That gave an error on startup so no scripts are loaded at all: Error during setup of component script

Another try:

# script: !include scripts.yaml # UI generated scripts
script: !include_dir_merge_named scripts/ # Manual scripts

That actually loaded the scripts from the scripts folder but then the ones generated from the ui are not loaded anymore!

Any help please?

remove the /.

are your scripts 1 per file?

this should work:

script: !include scripts.yaml
script extra: !include_dir_merge_list scripts

Doesnā€™t work. Iā€™m pretty sure scripts need the include_dir_merge_named instead of the include_dir_merge_list. Also the / should not make any difference.
Yours one works with automation (I have exactly that for the automations) but not for scripts.

Never got it to work.
I just included the folder and skipped the single file used when creating scripts trough UI.

script: !include_dir_merge_named my_script

Guess it is a bug then. I opened an issue (see https://github.com/home-assistant/home-assistant/issues/15628). Please upvote if youā€™re also affected by this.

if its any help, I use script: !include_dir_merge_named scripts in configuration.yaml, and have all scripts loadedā€¦

several folders in the /scripts folder, and they all have more scripts in them, formatted as follows:

opstart:
  alias: Opstart
  sequence:
    - service: script.scene_opstart

opstart_direct:
  alias: Opstart direct
  sequence:
    service: input_select.select_option
    data:
      entity_id: input_select.arrive_leave
      option: Opstart

so no leading -

also all scripts in packages load without issue.

2 Likes

Also ran into this problem. Using script: !include_dir_merge_named script works fine obviously, but having anymore than one occurrence of script just fails.

script extra: !include_dir_merge_named script
script: !include scripts.yaml

Reason I would like to do this is that I have a load of scripts that are already setup and in use in the directory, but it requires a restart of HA to get changes loaded. Where as when you have the default script.yaml in root, you can use the super easy reload script setting in the UI to quick check any changes you make, or setup new scripts, and when they are working all ok, you can move them to their own yaml in the directory.

This would be a very nice so we can use the editor in the ui and separate files in a sub dir.

Anyone got this to work now?
It seems to work fine for scenes but I still struggle with using both UI version and loading my old script files from script folder

Workaround by hard linking scripts.yaml into your custom scripts folder:

ssh username@your_hass.ip
cd config
ln scripts.yaml your-script-folder/scripts.yaml

(This makes a ā€œhard linkā€, that is, the file scripts.yaml now appears two places: as config/scripts.yaml that will continue to be edited by the UI script editor, and as config/your-script-folder/scripts.yaml and thus loaded just like your other scripts.)

7 Likes