OH3: executeCommanLine translate from OHv2

  • openhabian 3.3.0 on rpi4

I have a bunch of these in different rules files, writing to different log files, and adding a timestamp at the beginning.

val String errMsg = ZonedDateTime.now().toString + " " + Zeva_Message.state.toString.replace('|', '_')
val String errCmd = executeCommandLine("/bin/sh@@-c@@echo " + errMsg + " >> /etc/openhab2/html/Zeva_BMS.txt; echo $?", 3000)

I understand the format has changed.
So I added a thing

… but, what do I put into the command field?

There is still an executeCommandLine Action. Actions | openHAB. You don’t need to move to the Exec binding unless you want to.

But, as the docs show, executeCommandLine has changed.

executeCommandLine(Duration.ofSeconds(3), "/bin/sh", "-c", "echo " + errMsg + " >> /etc/openhab2/html/Zeva_BMS.txt; echo $?")

If you did want to move to the Exec binding, you’d put the command you want to execute under Command. Per the Exec binding docs " * the current (or last) command to the input channel (see below, example: %2$s)" so the command would be:

/bin/sh -c echo %2$s  >> /etc/openhab2/html/Zeva_BMS.txt; echo $?

This Thing will have a number of Channels associated with it. You will link a String Item to the Input Channel and sendCommand your errMsg to that String Item to cause the command to be run. The output of the command will be updated to a String Item linked to the Output Channel.

Note that you must add that command string as it appears in the whitelist (see the docs).

1 Like