[SOLVED] Knob with exec binding


I’m using openhab 2 and I’m trying to do something similar to https://community.openhab.org/t/exec-binding-and-setpoint/26800. I have a custom arduino thermostat which I can control using a bash script (read current and target temperature, set target temperature, start/stop the heater).

In my panel I have a dummy widget which displays the current temperature by calling the script. So far so good. Now I would also like to add a knob to display and set the target temperature but I cannot figure out how to do it.

For reading the current temperature I have this in my items file:

Number   Current_temperature   "Temperature [%.1f °C]"    <temperature>   (LivingRoom)   ["Temperature"]   {channel="exec:command:getCurrentTemperature:output", autoupdate="true"}

and this in my things file:

Thing exec:command:getCurrentTemperature [command="/bin/temperature.sh get-current-temperature", interval=10, timeout=15, autorun=true]
Thing exec:command:getTargetTemperature  [command="/bin/temperature.sh get-target-temperature", interval=10, timeout=15, autorun=true]
Thing exec:command:setTargetTemperature  [command="/bin/temperature.sh set-target-temperature %2$s", interval=0, timeout=15, autorun=false]

Intuitively, I’d say that the exec binding should have an inputOuput channel, not just input and output separately, but of course, this is not the case here. So how would you approach this?

You might be interested in the end of this posting, showing a single Item with separate in and out channels (which in your case could also be separate Things)

Hi @rossko57, thanks for the quick reply, it’s a nice trick indeed :).
Now the target temperature is correctly read but I cannot change it, it jumps right back to the original value (I also had a bug in the setTargetTemperature - I was missing the %2$s part, I’ll update my previous post).

2019-09-10 17:27:51.595 [ome.event.ItemCommandEvent] - Item 'Target_temperature' received command 18.8
2019-09-10 17:27:51.652 [nt.ItemStatePredictedEvent] - Target_temperature predicted to become 18.8
2019-09-10 17:27:51.749 [vent.ItemStateChangedEvent] - Target_temperature changed from 19.00 to 18.8
2019-09-10 17:27:56.578 [vent.ItemStateChangedEvent] - Target_temperature changed from 18.8 to 19.00

I should also have some logging from my script, but it seems it’s not called with the set parameters.
Does it need some rules to be set up, too? I’ll try to debug this further…

You missed the autoupdate setting in your Item

I’ve set the autoupdate property to true for that item and the “predicted” line no longer appears in the openhab log, but the behavior remains the same, the value jumps back.

I think the problem is that my script is not called. I also log stuff from it, like the parameters with which it is called and there is nothing related to setting the temperature in the script log.

It all depends how your exec Thing is set up. You have choices;

Use interval=nn to run periodically. Good for your temperature reading, not appropriate for ad-hoc updates like this.

Use autorun=true to trigger the script when you send a command to the input Item. There is a restriction that it only triggers if the command is different from the previous command. But that’s probably acceptable here,if there is no change in target value you don’t need the script to run?

Use neither of those (which looks like the way you have it set up now). You can then create an extra Switch Item, link it to the run channel, and send it an ON command to trigger a script run. If you wanted to pass a parameter value (your target temp) you would still need to send that as a command to the input channel beforehand.

Side note - you don’t really need autorun on your two “reading” exec Things, because you are triggering those on interval not command.
Indeed, if you are using that “combination” two-channel Item you probably don’t want to trigger the setpoint reading script on command at the same moment as the the setpoint writing script.

Based on your pointers, I finally managed to make it work. For anyone interested here is my setup:


Thing exec:command:getTargetTemperature  [command="/bin/temperature.sh get-target-temperature", interval=10, timeout=15, autorun=false]
Thing exec:command:setTargetTemperature  [command="/bin/temperature.sh set-target-temperature %2$s", interval=0, timeout=15, autorun=true]


String   Target_temperature  "Heating"  <heating>  (LivingRoom, gTemperature)   ["Temperature"]   {channel="exec:command:setTargetTemperature:input", channel="exec:command:getTargetTemperature:output", autoupdate="true"}

Thanks a lot, @rossko57, you’ve been very helpful ;).

1 Like