Shell commands. How?

I am trying to get a shell script to work, but all I find is posts and articles with, what it seems, outdated information. I have this shell script file ‘curtains-close.sh’ that works from other non-home assistant systems. I added this to the folder homeassistant/bash:

#!/bin/bash
curl -v -X PUT \
    --header 'content-type: application/json' \

curl -X POST -H "Authorization: XXXXXcca576890c9ec04b9b865cbb7338942d0860067fab283127875dafec100XXXXX2230b86aa3d229d9e4c5" -H "Content-Type: application/json; charset=utf8" https://api.switch-bot.com/v1.0/scenes/T02-202011061031-12121212/execute

in the configuration.yaml I added:

shell_command:
  curtains_close: "homeassistant/bash/curtains_close.sh"

But I cant seem to get this script in an automation. A lot of posts and articles talk about adding a call to service, but that’s no longer there in the current HA version. I can perform a action, but there doesn’t seem a way to add this script. Also the information about shell script of HA seems to be quite outdated.

Am I missing something? Does anyone has a clear step-be-step info how to add and run shell scripts?

I believe the HA doc is pretty clear to me
Aside this, rethink if you want to use the REST integration or sensor instead

Service has been replaced by action.

In the action part of your automation you need

actions:
  - action: shell_command.curtains_close

Use the developer tools to test it. It will tell you the stdout, stderr and returncode.

1 Like

What does
chmod +x /path/to/homeassistant/bash/curtains-close.sh
in the host terminal do?

What does this do in automations

    condition: []
    action:
        - action: shell_command.curtains_close
    mode: single

Personally I have this working

I must say that your command line may be wrong. What is the full path of the command?

2 Likes