Shell Command

Is it working on the last release ??

Trying to run a script without any luck

Thanks in advance

Just to clarify what release are you on. 32.3 came out today. With 32.2 my shell commands are working.

I didn’t know that 32.3 just came out…

I do have a

that I run from the command line but I can’t manage to get it work through HASS to use in a script or an automation

My configuration.yaml has

shell_command: !include shell_commands.yaml

My shell_coomands.yaml has

backup_config: ‘’

And doesn’t run when I try with HASS

Any advice ?

As luck would have it I just spent a very frustrating couple of weeks banging my head against a wall chasing something just like this down and have finally got shell commands. Previously I could not seem to run any shell commands at all. They would appear to run but nothing was achieved.

I think you need to specify a path to the file you created.

backup_config: /home/hass/.homeassistant/script_folder_location/

You might need to make sure this file is executable.

$ chmod 755 your/path/to/

These are probably not your problem but may help someone else searching like I was…

I had a few problems, one was trying to use directories - ie/ shell_command: !include_dir_named shell_commands. I had no errors but once I changed from directories to shell_command: !include shell_commands.yaml my shell commands started actually firing rather than just pretending to fire.

Next - line endings! I was using a windows computer with atom to create my sh files. Apparently if you do this you need to specify Unix line endings or you will get Dos line endings and the script will not work. I am a beginner and was blissfully unaware of this. Copying the script commands and pasting it into putty will work fine but running the .sh file files fails because of these line endings.

In Atom, in the bottom right hand corner there are a couple of file descriptors which will typically say CRLF UTF-8 Shell Script you need to set CRLF to LF by clicking on it and then save file. Notepad++ will say Dos/Windows - change to UNIX format and resave. This will not be a problem if you are using $ sudo nano to create your .sh files in the first place.

And for some commands I need to include bash at the start.

backup_config: bash /home/hass/.homeassistant/script_folder_location/

I can’t explain this to you as I am trying to understand it myself - I just know that it worked.

1 Like

It’s odd to me that this isn’t consistent; that you had to add it for some commands. Maybe this is something you should raise a bug issue on. Do you run any alternate shells?

I don’t really know what I’m doing or the terminology to use, and have only just been able to use shell commands so will have to test further. Should I edit that bit out so as to not confuse?

Also, I have to shamefully admit I don’t really know what bash means. By the time you read this I will have looked it up. The shell command scripts I am using bash on are starting with "curl -X GET "

I think what you mean by “shells” I interpret as “users”? If so, default AIO install with users “pi” and “hass”. I have been able to run scripts from both .homeassistant directory and pi directory in the home folder.

My apologies if I’m not making sense.


Thanks for the reply , I didn’t include the path because I previously included the directory that holds my scripts into the user $PATH

So for instance I can run the script straight from the command line after login no problem:

pi@raspberrypi:~ $

I double checked permission and everything seems to be right , but can’t manage to fire the script.


This is my script:

My problem was related to not being able to run any shell commands using .sh scripts at all, no matter how simple.

Can you run any .sh scripts or just not this one?

I can’t run anything with Shell Command

Well that is the same problem I had, I hope you can work it out faster and far less painfully than me.

I had to perform a clean install on a spare pi with absolutely nothing configured to trace my problems which were unfortunately user config and setup errors.

Did you get anywhere? I have the same issue for bash scripts, I can run python files no problem, but not bash scripts.

They run from the command line as pi user but not thru’ HA via the AIO install, so I’m guessing it’s to do with permissions, but being a 'nix noob I’ve no idea where to start. I’ve followed various threads here and tried just about everything…


backup_config: ‘sudo /home/homeassistant/.homeassistant/’

with and without bash and sudo does not work. I’ve made the file executable, no difference. Added HA to sudoers, no difference. I know my automation is running as I have a push notification when it runs and that always fires. I’ve tried it with " and ’ and no quotes.

Can anyone list the things that need to be done to execute a file from within HA via the AIO install.

Is there anything I can do to check if the file is running at all?

BTW using 0.39.

Thanks in advance for any help.

When you run scripts from HA it is done as the HA user. If you have a script with sudo in it, you will have to add the HA user to the sudoers list.

I have added HA to the sudoers list but with or without the sudo/bash or nothing infront of the command HA won’t run the file, or at least I think it’s not running it. Is there anyway that I can cause the file to output something? I’ve tried adding an echo but nothing comes out on a terminal window (didn’t really think it would tho’), but it would be nice to see if it is running at all.

Check the permissions on the scripts; can the HA user access them?

These are the first two things that gave me fits when I started using shell scripts.

Its 755 which I think means every1 can read and execute it, still does not run tho’ :frowning:

But who owns the file? Root or the HA user? I had to set my HA use (hass) as the owner before they would work for me.

sudo chown homeassistant:homeassistant
sudo chown homeassistant:root
sudo chown homeassistant

no dice.

Those are the only things I can think of at the moment. That’s what I had to do to make it work when I was using curl commands in HA to send presets to my cameras.

I created the shell script (sends commands twice to make sure the camera gets it properly):


curl -k ""
sleep 2
curl -k ""

Changed owner/group to my hass user and then put the commands in dir off root called shell_scripts.

Then created a script YAML that I could use in an input select to call it:


- service: shell_command.front_preset_1

and an automation to run the script when the input select was changed to the appropriate command:

- alias: "Front Cam Preset 1"
    platform: state
    entity_id: input_select.camera1
    to: 'street view'
    service: script.turn_on
    entity_id: script.f_preset1

That’s pretty much what I do, what does your shellcommand.yaml look like?

backup_config: 'bash /home/homeassistant/.homeassistant/'
echo "Home Assistant running Backup file"
DATETIMESTAMP=$(date '+%Y%m%d%H%M%S')
TAROPTIONS="--warning=no-file-changed --exclude-from=$TAREXCLUDEFILE -czf"

if [ -d "$HADIRECTORY" ]; then
  echo "Home Assistant Directory does not exist"
  exit 1

if [ ! -d "$BACKUPDIRECTORY" ]; then

ls -1tr

exit 0


 - alias: 'Backup Configuration at 3am'
     - platform: time
       after: '17:40:00'
     - service: shell_command.backup_config
     - service: notify.mypushbullet
         title: "Backup"
         message: "Backup Done NOT!!!!"

I’ve changed the time for testing and added a notify command to get some feedback.