Exec binding - start and kill process using single Switch item

Hi there!
I run OpenHAB 3.x on my remote Raspberry Pi. I would like to be able to run and kill process on that Pi (TCP tunnel for remote SSH) by issuing shell command via single OpenHAB dashboard Switch. I use exec binding add-on which allows me to issue whitelisted commands. Sadly, command can only be run using Switch item (as far I understand it).
I would like to have only one Switch and when switched ON - the command is issued to start process and when switched OFF - the command is issued to kill process. The problem that to achieve this I have to have 3 Switch items on my dashboard.
Switch 1: when switched process starts
Switch 2: when switched process is killed
Switch 3: when switched ON the Switch 1 is switched ON, when switched OFF the Switch 2 is switched ON.
If I only use one Switch, then I only can issue one of the commands, i.e. start the process but no kill it later.
Did I over-complicated this? Is there cleaner way to do this?
And if not - is there at least way to hide extra two Switch items in the sitemap?

It’s all in the manual. You should enable your script to accept parameters, like for example: ‘script.sh STOP’ and ‘script.sh START’.

Then:

rule "Set up your parameters"
when
   Item YourTrigger changed
then
      // here we can take different actions according to source Item
   if(YourTrigger.state == ON){
      yourcommand_Args.sendCommand("Additional Argument to command line for ON")
   }else{
      yourcommand_Args.sendCommand("Different Argument to command line for OFF")
   }
      // Caution : openHAB bus is asynchronous
      // we must let the command work before triggering execution (if autorun false)
end
1 Like

Thank you. Script parameters is the new concept for me. But finally learned it and implemented it. It works now.