Moving scripts to separate directory

I am trying to clean up my config by moving out of the scripts.yaml file but I am encountering an error while doing so.

I am following the same approach as I have already successfully done with automations and started by changing the script reference in configuration.yaml to read

script: !include_dir_list script/live/

and in the script/live directory I added the files with my scripts assuming this would be a walk in the park, however it was not…

Right now I have only one file added to script/live and the content of this is

wakeup:
  alias: Good Morning!
  sequence:
  - service: media_player.select_source
    data:
      entity_id: media_player.kjokkenet
      source: NRK P3

however when I restart HO it failes and when I check config I get this error:

Invalid config for [script]: expected dictionary for dictionary value @ data['script']. Got [OrderedDict([('wakeup', OrderedDict([('alias', 'Good Morning!'), ('sequence', [OrderedDict([('service', 'media_player.select_source'), ('data', OrderedDict([('entity_id', 'media_player.kjokkenet'), ('source', 'NRK P3')]))])])]))])]. (See ?, line ?).

Is there anyone out there who can see what rookie mistake I have probably made here?

Indent everything two spaces and run the config check again.

Can’t get to the docs right now but I think you may want include_dir_named instead.

my understand is change

!include_dir_list

to

!include_dir_merge_list

dont think you will need the last /

Scripts are not lists. They are named.

I went through the same exercise recently and this is what I use:

#script: !include scripts.yaml
script: !include_dir_merge_named scripts/

Now my scripts are located in separate files within the scripts directory. Each file may contain several scripts.

1 Like

Hello and thank you all for your help and inout. As I am sure you know already your suggestions did the trick and after I changed this entry in my configuration.yaml to

script: !include_dir_merge_named script/live/

everything is working fine.

Thanks guys!

(BTW, Is there any logic behind this difference between automations and scripts or is this just the way it is?)

It’s simply due to how they are defined in YAML. On uses a list and the other doesn’t. As to why, I’m not sure.

Please mark the post that answered your question with the Solution tag. Only you, the author of this topic, can do that. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has an accepted solution. It also automatically places a link beneath your first post that leads to the Solution. All of this helps other users find answers to similar questions.