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’.


rule "Set up your parameters"
   Item YourTrigger changed
      // here we can take different actions according to source Item
   if(YourTrigger.state == ON){
      yourcommand_Args.sendCommand("Additional Argument to command line for ON")
      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)
1 Like

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

@hal_sk What command do you use to kill the running process?
I am using the exec binding to run a audio file. I would like for the ability to stop the audio file instead of waiting for it to finish. so I am looking for the command to do that

Not sure if it will help you, but I use custom shell script with command to kill the process. The script execution is triggered by exec binding when Switch state changes to OFF.
If you talking about actual command in the script, I have no access to it right now, but you can use “kill” command with some other commands in pipeline. Search: “how to kill process in Linux” or something like that.

I will give it a shot…
Thank you very much