[SOLVED] EXEC BINDING - Need help to add args in item's file

Hello everybody,

Im doing this : https://www.openhab.org/addons/bindings/exec/

I would like to replace a rule by an item definition :

This rule :

Rule "begin your execution"
   Item YourTrigger changed
   if(YourTrigger.state == ON){
      yourcommand_Args.sendCommand("Additional Argument to command line for ON")
      yourcommand_Args.sendCommand("Additional Argument to command line for OFF")

By an item like this :

Switch yourcommand_Args {channel="exec:command:yourcommand:input", Additional Argument to command line for ON, Additional Argument to command line for OFF}

I would like to run it directly when input change by on or off switching button.

Is it possible ?
My thing is something likes that :

Thing exec:command:yourcommand [ command="<YOUR COMMAND> %2$s", interval=0, autorun=false ]

Thanks a lot

You can’t do it that way.

You can -
set up your exec command Thing to “autorun”
set up your exec command to accept parameter from input channel
Link a String Item to exec input channel.
Put that item on your Sitemap with a Switch widget.

Im not sure to understand your solution because it looks like my actual situation.
I want that %2$s be inside my item’s file or sitemap’s file and not in my rule’s file.
That 's your explanation ?

Here’s a tutorial that may help.

May want to read the entire topics as there are several examples.

Yes. Which part don’t you understand? Can you show us whereyou’re having trouble?

Can you create an exec command Thing with your command line, and a placeholder for your parameter?

Can you set that Thing to autorun?

Can you create a Text type Item?

Can you link that Item to your Thing’s input channel?

Can you display that Text Item on your sitemap with a Switch widget, with mappings for “apple” and “banana” or whatever your parameter needs to be?

When the poke the UI button, it will command “apple” to your Item. That is linked to exec’s input channel, so “apple” will be used instead of %2s in your exec command. Autorun will make it execute.


Thing exec:command:controlPdu [command="/bin/bash /Users/exhibition/Documents/openhab-2/conf/scripts/ControlPdu.sh %2$s", interval=0, timeout=5, autorun=false]


Switch controlPduTrigger
String controlPduInput “[%s]” {channel=“exec:command:controlPdu:input”}
Switch controlPduRun {channel=“exec:command:controlPdu:run”}


rule “pdu1”
Item controlPduTrigger received command
if(controlPduTrigger.state == OFF) {
controlPduInput.sendCommand(“t282-gude05 2 1”)
} else {
controlPduInput.sendCommand(“t282-gude05 2 0”)


sitemap admin label="Admin webpage"
  Frame label="Gude 1"
    Switch item=controlPduTrigger

But I have 4 pdu with 4 ports each and 2 status (on off), so I don’t want to write X lines of rules. I try to factorise.

Alright, use a completely different method then. What is your problem with that, now?

I think I can use this (like the tutorial) :
switch triggeringItem.name {
case “first pdu off” : controlPduInput.sendCommand (t282-gude04 1 0) //for OFF
case “first pdu on” : controlPduInput.sendCommand (t282-gude04 1 1) //for ON
case “second pdu” : controlPduInput.sendCommand (t282-gude05 1 0)…

but I think that there is a lot of line.

It’s hard to understand. rossko57 gave you a step by step approach to achieve this without using Rules and asked you to specifically tell him at which step you have difficulty so we can help. Instead of doing that you jump back to doing it in Rules.

It’s really hard to help if you jump around like that.

Thanks everybody for the solution, it works !

items :
String controlPdu1Port2 “ON / OFF PDU 1 Port 2” {channel=“exec:command:controlPdu:input”}
String controlPduInput “[%s]” {channel=“exec:command:controlPdu:input”}
Switch controlPduRun {channel=“exec:command:controlPdu:run”} (i think I can delete this line )

Switch item=controlPdu1Port2 mappings=[“t282-gude05 2 1”=“ON”, “t282-gude05 2 0”=“OFF”]

Thing exec:command:controlPdu [command="/bin/bash /Users/exhibition/Documents/openhab-2/conf/scripts/ControlPdu.sh %2$s", interval=0, timeout=5, autorun=true]

Thanks !!

This link helped me to understand a little more :

Dear all,
I have always an issues with %2$s
I need to give a parameter to a string item without sitemap.
Is it possible to create a switch item, when I click on this item, it gives a parameter to string item link to a thing ? Not by sitemap
Because I have somes computers to shutdown, I have an exec binding with shutdown command and parameter. The parameter has to be the hostname of my computer. I would like to create a switch item with the hostname in parameter.

If not by sitemap then what are you clicking on?

If using the sitemap, this is super easy. Just use a Switch element with mappings. That will create buttons and when you click the button it will send the name of the host as a command to the String Item being displayed.

If not, you’ll need to set it up in a Rule.

I have a scheduler for each morning and night and sometimes I click on sitemap.
Second solution is to do one thing declaration for each command and one switch link to the thing.

In additional of this problem, with openhab 3 I can not use classic ui, i have to do a new interface :frowning: .

Do you know if we can access to old exec binding 1 in OH3 ?

Ok i do your solution, one rule by item, it’s easiest and more logic.
Thanks for you help, i don’t need exec binding old version with this solution.

You can still use BasicUI (or the phone apps) with a sitemap in OH3.

I think perhaps you have not understood that you can use a Switch type widget in a sitemap, linked to a String type Item.

Using mappings= on the Switch widget, you can send any string you like from a button click.

Switch item=myStringItem label="test [%s]" mappings=["apple"="Fred","orange"="Mary"]

This makes two buttons marked Fred and Mary. Clicking a button sends string apple or orange.

You can do the same kind of thing in MainUI.

No. No OH 1 bindings are supported in OH 3.

Dear all,
I have a new problem, I have an exec thing
I use this rule to send multiple order to my exec thing :

rule " control Pdu"
Member of gPdu received command
val i = triggeringItemName.toString.length;
val pduName = triggeringItemName.substring(0, i - 1)
val pduPort = triggeringItemName.substring(i - 1,i)
val pduOrder = pduName + ’ ’ + pduPort + ’ ’ + receivedCommand

in my script i do gPdu.sendCommand(OFF)
it should send 4 pduOrder different, but only one or two are send
i think i need to do one instance by item
if I click one by one on the 4 items it works, but 4 simultaneously (by a group send command) doens’t work

ok sorry it works with autorun true :frowning:

Thing exec:command:controlPdu [command="/bin/bash /Users/exhibition/Documents/openhab-3/conf/scripts/switchGudeStatus.sh %2$s", interval=0, timeout=5, autorun=true]

it doesn’t work with false. but im ok to put true.