Placing a shell_command in scripts.yaml results in error “[curl_get] is an invalid option for [script].”

Hi,

I’m completely new to HA and YAML, so I’m trying to take some small steps. I made a small WAN IP change automation which runs a shell command on state change of my router’s wan ip sensor.

I added this to configuration.yaml to create the required service for the curl command.

shell_command:
  curl_get: "curl -X GET {{ url }}"

All works fine, but when I move this to scripts.yaml, the service no longer works and I get an error in my log: [curl_get] is an invalid option for [script]

Am I supposed to format things differently when I add them to an include or is this not supposed to go in scripts.yaml?

Any input is much appreciated, thanks!

shell_command is an integration, not part of the regular script engine. See this example, how to call a shell command within a script / automation:

service: shell_command.curl_get

Include files are added to where the include line is in the YAML file.
This means

configuration.yaml might contain:

include scripts.yaml

scripts.yamil might contain:

shell_command:
  curl_get: "curl -X GET {{ url }}"

Which will result in the following being passed to HA:

shell_command:
  curl_get: "curl -X GET {{ url }}"

But if your you configuration.yaml contains this:

scripts: include scripts.yaml

and your scripts.yaml still contains:

shell_command:
  curl_get: "curl -X GET {{ url }}"

Then the result being passed to HA will be:

scripts:
  shell_command:
    curl_get: "curl -X GET {{ url }}"

Which might be wrong.

Thanks, that makes sense. I hoped it would work via the scripts include so that I wouldn’t have to restart HA after every small addition/change. I’m still wrapping my head around what goes where and the correct terms for everything.

So if I wanted to keep my main config clean I could add a separate include to my main configuration.yaml like this?

shell_command: !include shell_commands.yaml

And inside that I just list the various commands I want to be able to call as a service:

curl_get: "curl -X GET {{ url }}"
clear_nas: "bash /scripts/clear_nas.sh"
...etc etc

correct.
I can recommend watching this video with Frenck and DR. ZZs about the YAML files.
It has a section about the different kind of includes too.

1 Like

This is pure gold. Thanks!
As soon as he pointed out that it’s basically a bunch of nested associative arrays I was good :smiley: