Exec:pass string from Item to thing

Hello all,

I just started to migrate from OH1 to OH2 and have a question to the exec binding. I understood, I have to use item and things to execute scripts in OH2.

My .item file in OH1 consists of several execution of a script, which reads the oneWire files of my PI:
Number Speicher “WW-Temperatur [%.1f °C]” (Heizung) { exec="<[/etc/openhab2/scripts/onewiretemp.sh 10-0008021db5f6:60000:REGEX((.?))]" }
Number Aussen “Aussentemperatur [%.1f °C]” (gTemperatur) { exec="<[/etc/openhab2/scripts/onewiretemp.sh 28-00044a025aff:60000:REGEX((.
?))]" }

and so on.
So, I called the script “onewiretemps.sh” with the address of the OW-device as a parameter.

How can I do this in OH2?

AFAIK, I have to create a thing like this:

Thing exec:command:getTemp [command="[/etc/openhab2/scripts/onewiretemp.sh ", interval=15, timeout=5]

where is a parameter comming from the call in the .items file:
Number Aussen {channel="exec:command:getTemp:??? "}

Please help



Please have a look at the documentation:


Specifically, the two channels named “exit” and “output”.

I had a look to that page, already but could not find out how I have to adopt this to my needs.

In the example .items, there is no call to the thing “myscript”. So I don’t know where to put the OW-address in the items file.

Should I do input with address first:
Number Aussen) {channel="exec:command:getTemp:input 28-00044a025aff "}
and then read the output:
Number Aussen “Aussentemperatur [%.1f °C]” (gTemperatur) {channel="exec:command:getTemp:output "}


Ah! I think I understand now what you mean.

I have not tested this, but I believe you need to create one item (of type String) connected to the “input”-channel and another item (of type String) connected to the “output”-channel.

Then you need to set your “input”-item to the address (e.g. “10-0008021db5f6”) that you want to execute the script for. A change in state of the “input”-should trigger execution of the script. In additon you need a rule that triggers on a change (of update) of the “output”-item and in this rule you need to parse the output and convert it to a Number-item.

Piece of cake, eh?

As you may have noticed there is a lot of discussions going on in this forum regarding the Exec 2.0 binding, and in particular how it has change completely from what people were used to with the 1.8 binding.

Thanks for your help but I don’t think, it’s a piece of cake :slight_smile:
IMHO it is arkward.

There must be an easier way.
It is even easier, if I copy the script several times (wadd the name of the sensor) and include the address in every script. Then I can call individual scripts.

My statemement was purely ironic, :slight_smile: I completely agree that this is far from “a piece of cake”, and it seems most of the forum members agree as well, given the amount of discussion on this topic

1 Like