Using shell command in automations


I have the following commands in config.yaml, and I am using this object in the automatons the command is not being triggerd.

When running the curl command in crontab it works fine (i see output in the file).
Any ideas what is wrong?

# Command to update DDNS with public IP address
  update_dns: 'curl >> /tmp/freedns.log 2>/dev/null'

The shell commands in my configuration do not have the single quote marks. Don’t know if it matters, but you might try removing them. You might also try using the full path to curl, for example /usr/bin/curl …

I have some shell commands using curl and for mine the entire command is in single quotes but the http address is double quoted

command:  'curl "https://blah blah"'

would you mind pasting the full automation because I am not sure the curl command is within the Automation or in the config.yaml

That is not from an automation that is a shell_command… you shouldn’t have the actual command in the automation it should be shell_command.your_command

See examples:

that is how i did it … not urgent right now because I managed to do it with a crontab, but it would be nice to understand what is wrong

As others have suggested, quoting is usually the issue with shell_command

Note that I run HomeAssistant in a venv on Ubuntu under a dedicated service account - how you are setup could affect results. I tested my commands within the venv running as the service account user before implementing, which helped resolve some permission and path issues.

Some examples:

  extract_motion_image: 'ffmpeg -y -ss 04 -i /home/homeassistant/.homeassistant/snapshots/motion.mp4 -qscale:v 4 -frames:v 1 /home/homeassistant/.homeassistant/snapshots/motion.jpg &>/dev/null'
  extract_motion_cleanup: 'rm -f /home/homeassistant/.homeassistant/snapshots/motion.*'
  send_sms: 'gammu sendsms TEXT "{{ sms_to }}" -text "{{ sms_msg }}"'

and a curl command line example for a switch (calling a secondary hassio instance):

  - platform: command_line 
         friendly_name: 'Garden Lights'
         command_on: >
             /usr/bin/curl -X POST \
                 -H "Content-Type: application/json" -d '{"entity_id": "switch.garden_lights_switch"}' \
                 -H "Authorization: Bearer secrettoken"
         command_off: >
             /usr/bin/curl -X POST \
                 -H "Content-Type: application/json" -d '{"entity_id": "switch.garden_lights_switch"}' \
                 -H "Authorization: Bearer secrettoken"
         command_state: >
             /usr/bin/curl -X GET \
                 -H "Authorization: Bearer secrettoken"

what do you think of this?
Still not working :frowning: do you have a simple curl command I can use (eg write something to file and then I check the file)

# Command to update DDNS with public IP address
  update_dns: '/usr/bin/curl "" >> /tmp/freedns_com.log 2>/dev/null'

I would try that command at the command line manually as the Homeassistant user… in the venv if you have one … and see what happens

the problem might be that I am running through a docker… will test and let you know

Looks like there have been some parameter changes since I last tested my send_sms shell_command - I tested this evening after making some other configuration changes and was getting some 127 errors which I traced back to the parameters in the command.

I’ve just had to modify the command line (note the quote changes) to:

  send_sms: gammu sendsms TEXT "{{ sms_to }}" -text "{{ sms_msg }}"

EDIT: quote correction (copied wrong test line)

running the command from CLI works fine

pi@raspberrypi:~ $ curl “” >> /tmp/freedns_mooo_com.log 2>/dev/null

… at this point i am a bit confused

I don’t use docker so I don’t know how the different containers could affect how it runs… I would try putting the command you just ran as your shell command in your config… wrap the entire command in single quotes… restart Ha… the go to the services tab and choose shell_command.update_dns and press call service… then see if you get an error and check the logs to see the details

the msg I am getting in the logfile is the following:`

2019-11-24 19:53:53 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1854561712] Received {‘type’: ‘call_service’, ‘domain’: ‘shell_command’, ‘service’: ‘update_dns’, ‘service_data’: {}, ‘id’: 19}


not much help :slight_smile:
never mind mate. thanks for your help