I got a question about the exec binding in OH2, which i already asked here. I don´t understand how to migrate my old exec binding triggered scripts to OH2 and need some advice. The bash-script looks like this:
cat licht_sofa.sh
!/bin/bash
value="$1"
if [ $value == "ON" ]; then
an () {
echo "TXP:0,0,10,5600,350,25,1,3,1,3,1,3,1,3,1,3,3,1,1,3,1,3,1,3,1,3,1,3,1,3,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,1,3,1,3,3,1,1,16,;" | nc -u 192.168.188.25 49880 &
pid=$!
sleep 1
kill $pid 2>/dev/null >/dev/null
}
echo An
an
else
aus () {
echo "TXP:0,0,10,5600,350,25,1,3,1,3,1,3,1,3,1,3,3,1,1,3,1,3,1,3,1,3,1,3,1,3,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,1,1,1,16,;" | nc -u 192.168.188.25 49880 &
pid=$!
sleep 1
kill $pid 2>/dev/null >/dev/null
}
echo Aus
aus
fi
If i call the script from shell with variable ON or OFF, the device (a Brennestuhl wallplug which get a put from the Brematic controller on my network) switches from ON to OFF or vice versa.
In OH1.x i call this script from .items-file like this (note that for ON and OFF, there are two scripts needed in OH1.x):
Switch Light_GF_Living_Couch "Steckdose Sofa" (GF_Living) { exec="OFF:/opt/brematic/licht_sofa_off.sh, ON:/opt/brematic/licht_sofa_on.sh" }
In OH2, i define a new thing and call the variable-active script:
Thing exec:command:wallplug [command="/opt/brematic/licht_sofa.sh", interval=0, timeout=5]
But how can i send ON or OFF to the script?
Referring the docs, an item can look like this:
String APCRaw "[%s]" (All) {channel="exec:command:apc:output"}
Switch APCRunning { channel="exec:command:apc:run"}
Number APCExitValue {channel="exec:command:apc:exit"}
DateTime APCLastExecution {channel="exec:command:apc:lastexecution"}
Normally i would guess that my item has to look like
Switch LichtSofa { channel="exec:command:wallplug:run"}
but in this way, i can´t get the switch to toogle its state. What am i doing wrong?
PS / Hint:
There is no chance to get state switches state from the controller. So the best option would be to call maybe ON first, each time the script is fired. So you got a chance of 50% that the switch goes on or off. Otherwise i should also be possible to read the state from persistence in some way