Shell_command automation

I’m trying to use a “shell_command” in an automation and am experimenting with the example from the home assistant documentation.

I’ve added the code to the blank automations.yaml. VSC gives me errors for all keywords:

  • Missing property “action” for automation:
  • Property input_number is not allowed for input_number:
  • etc.

What am I missing? The ultimate goal is to run a shell command once a day.

Thanks!

Hi, would be easier if you post your automation code.

In automation.yaml:

- alias: Backup
  id: "1651514372914"
  description: Backup configuration to GitHub (nightly)
  trigger:
    - platform: time
      at: 02:00:00
  condition: []
  action:
    - service: shell_command.github_backup
  mode: single

In configuration.yaml:

shell_command:
  github_backup: "bash /config/ha_gitpush.sh"

/config/ha_gitpush.sh is an executable that works fine when run from the command line. I would like it to be run each day at 2am, but it’s not.

I’ve also tried the following, same result (i.e. the script is not executed):

In automation.yaml:

- alias: Backup
  id: "1651514372914"
  description: Backup configuration to GitHub (nightly)
  trigger:
    - platform: time
      at: 02:00:00
  condition: []
  action:
    - service: hassio.addon_stdin
      data:
        addon: a0d7b954_ssh
        input: /config/scripts/ha_gitpush.sh
  mode: single

In short, I would like the shell script /config/scripts/ha_gitpush.sh to run once a day at night.

Have you tried the service call alone ? To check if your script is running ? (service: shell_command.github_backup)

It’s now working. The shell_command was not in the correct location.

Thanks!

1 Like

Hi Bernhard
what was correct location for the shell_command ??

I would like to know too

Does anyone know what location works?

I am having the same issues. In ‘terminal’ the script works just fine. In the service command I get a ‘file not found’. Both cases I do a Cut/Paste of the command:
/config/script.sh
The terminal works as expected, the service command says “File not found”

Any ideas?

service: shell_command.restart_fritz
data: {}

Works for me, when file is located at homeassistant/fritzbox-restart.v1.sh

I had problems with log locations within the script, maybe you need to adapt paths within the script too.

Also try to chmod 777 the file.

doh!! was trying to create a os level cron job. way simpler with a HA time trigger.