Multiple curl calls in a command_line

I have the following command line…

- platform: command_line
  switches:
    garagedooricon:
      command_off: 'curl "http://192.168.0.110:8090/syslog?type=INFO&message=Garage_Closed&silent=true"'
      command_on: 'curl "http://192.168.0.110:8090/syslog?type=INFO&message=Garage_Open&silent=true"' 

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

- platform: command_line
  switches:
    garagedooricon:
      command_off: 'curl "http://192.168.0.110:8090/syslog?type=INFO&message=Garage_Closed&silent=true"'
      command_off: 'curl "http://192.168.0.50:8090/syslog?type=INFO&message=Garage_Closed&silent=true"'
      command_on: 'curl "http://192.168.0.110:8090/syslog?type=INFO&message=Garage_Open&silent=true"' 
      command_on: 'curl "http://192.168.0.50:8090/syslog?type=INFO&message=Garage_Open&silent=true"' 

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/network-bandwidth.sh enxd0374516f37c" # usb ethernet on macmini2012
    unit_of_measurement: "kB/s"
    value_template: "{{ value_json }}"
    json_attributes: 
      - "timestamp"
      - "interface"
      - "in"
      - "out"
      - "units"
  - platform: template
    sensors:
      transmission_down_speed_kbps:
        friendly_name: "Transmission Down Speed"
        unit_of_measurement: 'kB/s'
        value_template: "{{ state_attr('sensor.network_bandwidth', 'in') }}"

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

#!/bin/bash
# network-bandwidth.sh
# 202010161015

INTERVAL="1"  # update interval in seconds

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

IF=$1

R1=`cat /sys/class/net/$1/statistics/rx_bytes`
T1=`cat /sys/class/net/$1/statistics/tx_bytes`
sleep $INTERVAL
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 "http://192.168.0.110:8090/syslog?type=INFO&message=Garage_Closed&silent=true" && curl "http://192.168.0.50:8090/syslog?type=INFO&message=Garage_Closed&silent=true"'

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