Java Runtime Environment: java version “1.8.0_201”
openHAB version: 2.5.0~S1502-1
Issue of the topic: Storing the output of an exec command in an item
Hello all.
I am struggling to get the output of an exec command into an item.
After successfully firing the below listed rule, the item has a state of UNDEF.
I have been recently learning how to adapt pmpkk’s Matrix Theme to my simple set up. I would like to display the installed version of openHAB on one of HabPanel system information pages, and am trying to get the version of OH installed into an item using the exec binding.
I’m not certain if there is an easier way to do this or if I’m doing this completely wrong but i am also using this as a learning experience for myself. If there is an easier or better way, please let me know!
exec Binding version installed: 225 │ Active │ 80 │ 2.5.0.201901142229 │ Exec Binding
For testing, i am using a rule from part of my Zwave lights remote. ie when the lights are turned on… When working properly it will be put into a rule and executed when the system is started.
Mocked up rule where the remote button “ON” is pressed…
lights.rules
rule "Turn lights ON"
when
Item on_button received command ON
then
OH_version_out.sendCommand(ON)
logInfo("EXEC BINDING", OH_version_out.state)
end
After successful running of the rule, the Item “OH_version_out” has an UNDEF state.
Running the command from the command line and the result:
openhab@OpenHAB-debian:$ dpkg -s openhab2 | grep -i version
Version: 2.5.0~S1502-1
Is anyone able to point me in the right direction or have I misunderstood how the exec binding works…
Getting closer. I was not executing the correct item type. Should be:
exec.items
// state of the execution, is running or finished
Switch OH_version_run {channel="exec:command:OH_version:run"}
// Output of command line execution
String OH_version_out "[%s]" { channel="exec:command:OH_version:output" }
This results in “OH_version_out” being populated with data.
However the pipe in the exec command is being rejected, so the grep portion is not being processed. See the last line in the log below:
2019-01-27 20:02:04.076 [vent.ItemStateChangedEvent] - OH_version_run changed from OFF to ON
==> /var/log/openhab2/openhab.log <==
2019-01-27 20:02:04.089 [WARN ] [hab.binding.exec.handler.ExecHandler] - Couldn’t transform response because transformationService of type ‘REGEX’ is unavailable
==> /var/log/openhab2/events.log <==
2019-01-27 20:02:04.090 [vent.ItemStateChangedEvent] - OH_version_run changed from ON to OFF
dpkg-query: error: --status needs a valid package name but ‘’|‘’ is not: illegal package name in specifier ‘’|‘’: must start with an alphanumeric character
Use --help for help about querying packages.
dpkg-query: error: --status needs a valid package name but ‘’|‘’ is not: illegal package name in specifier ‘’|‘’: must start with an alphanumeric character
How can i escape the pipe so it will not be rejected? I have tried ^| but it did not work.
An unrelated word of caution, cos it was seen in another thread. There’s a finite time between triggering run, and run.state going to ON. Depending on system performance you could act too early and get the result of a previous run. Check for run going ON before waiting, or allow a delay, or trigger a separate rule from run going OFF
Ideally set autoupdate false on the run Item as well, stop it interfering.