I can’t get the shell_command service to fire in my automations. What am I doing wrong?
I’m following this YouTube video on how to automate backing up my config files to a private github repo, but the video was made before HA removed the ability of the hassio.addon_stdio to run ssh scripts. No biggie; shell_command should ostensibly be able to do this.
Here’s what I’ve done so far:
I’ve created a shell script to back up my stuff to a github repo. The script works perfectly when running it manually from the command line (via the Terminal add-on)
Could you make it work? I’m getting a similar result, a shell command runs correctly when I do it from the developer tools, but not when it’s on an automation.
Me too. It says the path is incorrect, but I’ve tried all the variations I can think of. Calling the script itself works fine, but the Shell Command service from automations results in an error that the file doesn’t exist.
Fun fact: I’m trying to do the same today to backup my esphome.
I added everything like in the tutorials and it wasn’t working. After restart HA it works to execute the script, but username can’t be found.
configuration.yaml:
When calling script in dev tools service: "shell_command.ha_gitpush"
[Code on ]: 25-02-2024 15:32:08
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
stderr: >-
fatal: could not read Username for 'https://github.com': No such device or
address
returncode: 128
docker exec -it homeassistant bash
cd esphome
./ha_gitpush.sh
# --> Enter username and tokken for github
# --> Wait till commit finished and verify on github
Then:
git config credential.helper store
After that, change something in your HA folder and run service: "shell_command.ha_gitpush"
again. This resolved in:
stdout: |-
[Code on ]: 25-02-2024 15:44:00
[master e5fdcfb] [Code on ]: 25-02-2024 15:44:00
1 file changed, 1 insertion(+), 1 deletion(-)
branch 'master' set up to track 'origin/master'.
stderr: |-
To https://github.com/***************/home-assistent.git
ec739e7..e5fdcfb master -> master
returncode: 0
Just an addition, which is pretty nice I think:
I changed the ha_gitpush.sh to:
# Change this to your folder if it is different and you don't want to backup just esphome configs.
cd /config/esphome
# Add all files to the repository with respect to .gitignore rules
git add .
# Commit changes with message prepared in file:
git commit --file .commit_message.txt
# Push changes towards GitHub
git push -u origin master
in same folder (for me /config/esphome) I have a file .commit_message.txt and if I change something in my config, I just write down what I’ve changed and why. So I don’ have every commit with “files at dd-mm-yyyy”, I have the message
Changing bash to /bin/bash seems to be working for me from inside my container when manually running the automation. We’ll see tonight what it does running as an automation. Thanks @exx