I’m trying to run the following command as a shell_command
curl volumio.local/api/v1/commands/?cmd=stop ; PARAM=('pr' 'vo' 'tr' 'bs' 'ch' 'pr') ; VAL=('01' '13' '09' '12' '05' '00') ; for zone in 1 2 3 4 5 6; do for i in "${!PARAM[@]}"; do curl -XPOST -d ${VAL[i]} 1.2.3.4:8181/zones/1$zone/${PARAM[i]}; done ; done;
I just answered someone else who was trying to do advance shell scripting in YAML and I would suggest the same here - and that is to put that kind of a script into a script file and set your shell_command to run that file instead, this gives you so many extra benefits, the least of which is that you only restart HA one time to register the command and can modify that shell script file at will without restarting HA. Additionally you get a chance to make sure that the command works the way you want from a terminal session because not all unix’s are equal and some of the commands available in HA are less capable than their full unix counterparts.
@CO_4X4 : Thanks. Very valid point I totally agree. I didn’t expect my command to be so lengthy when I started.
Just to answer my initial post, I ran a quick test that seems to confirm arrays are not usable through command_shell. The example below runs fine. It is actually a string with a space " " as the separator.
arraytest='string1 string2 string3' ; for s in $arraytest ; do echo "$s" ; done ;
If you are going to mix text qualifiers (single quotes and double quotes) you are going to fight with YAML since it’s going to encapsulate that into double quotes for the JSON conversion it saves. This is one of the reasons I prefer just scripting it in a file, I don’t have any of that YAML/JSON business to deal with and get pissed about
#!/bin/bash
curl $1/api/v1/commands/?cmd=stop
PARAM=('pr' 'vo' 'tr' 'bs' 'ch' 'pr')
VAL=('01' '13' '09' '12' '05' '00')
for zone in {1..6}
do
for i in "${!PARAM[@]}"
do
curl -XPOST -d ${VAL[i]} $2/zones/1$zone/${PARAM[i]}
done
done
Oh, and you can pass a single command line option in that shell too, FYI. Here’s what I to do send my TTS text to the computer that says whatever I put into HA: