Multiple curl calls in a command_line

I have the following command line…

- platform: command_line
      command_off: 'curl ""'
      command_on: 'curl ""' 

I wan to add more http curl calls to this like the following…

- platform: command_line
      command_off: 'curl ""'
      command_off: 'curl ""'
      command_on: 'curl ""' 
      command_on: 'curl ""' 

But it will not call both on a “on” command, it only calls one item. How do I get it to call both?

1 Like

Not directly to your question. That said, I have found good results by using the command_line sensor with bash scripts. Makes it a bit easier to debug, without having to start and stop HA as you revise. Example below sends parameter to bash script and returns results in a JSON string to HA. I have crammed several script commands on to a single line of a command_line command: argument, however, it gets messy quickly. Good hunting!

# network bandwidth
  - platform: command_line
    name: Network Bandwidth
    command: "shell_scripts/ enxd0374516f37c" # usb ethernet on macmini2012
    unit_of_measurement: "kB/s"
    value_template: "{{ value_json }}"
      - "timestamp"
      - "interface"
      - "in"
      - "out"
      - "units"
  - platform: template
        friendly_name: "Transmission Down Speed"
        unit_of_measurement: 'kB/s'
        value_template: "{{ state_attr('sensor.network_bandwidth', 'in') }}"

        friendly_name: "Transmission Up Speed"
        unit_of_measurement: 'kB/s'
        value_template: "{{ state_attr('sensor.network_bandwidth', 'out') }}"

# 202010161015

INTERVAL="1"  # update interval in seconds

if [ -z "$1" ]; then
        echo usage: $0 [network-interface]
        echo e.g. $0 eth0


R1=`cat /sys/class/net/$1/statistics/rx_bytes`
T1=`cat /sys/class/net/$1/statistics/tx_bytes`
R2=`cat /sys/class/net/$1/statistics/rx_bytes`
T2=`cat /sys/class/net/$1/statistics/tx_bytes`
TBPS=`expr $T2 - $T1`
RBPS=`expr $R2 - $R1`
TKBPS=`expr $TBPS / 1024`
RKBPS=`expr $RBPS / 1024`

#echo $TBPS
#echo $RBPS
#echo $TKBPS
#echo $RKBPS

#echo -e "{\"Hello\"}\n"
#echo "{\"timestamp\": $(date '+%Y%m%d%H%M%S'), \"interface\": \"$1\", \"speed\": {\"out\": $TKBPS, \"in\": $RKBPS}, \"units\": \"kB/s\"}"
echo "{\"timestamp\": $(date '+%Y%m%d%H%M%S'), \"interface\": \"${1}\", \"out\": \"${TKBPS}\", \"in\": \"${RKBPS}\", \"units\": \"kB/s\"}"

Like this:

command_off: 'curl "" && curl ""'

I found this thread having the same issue. Solved it like this as I supect HA only forwards whatever you write as command to the underlying linux OS and there you can run several commands in sequence by separating them with &&. So Commad1 && Command2 && Command3. From my testing it appears 2 will not be run before 1 is done. But not sure. Anyway. I can run several curl commands like this, with no issue

*I know this is an old thread, but maybe someone else can find it in search of answers :grinning_face_with_smiling_eyes:

1 Like