Exec Binding in OH3

Hey guys,

recently upgraded to OH3 and now my Exec Binding isnt working anymore. I tried every tips on other threads, but nothing helped me. At the moment my rule looks kinda like this. (This worked in OH2 flawless.

    if (receivedCommand != OFF) {
        val VideoDatei = SmartTable.state.toString
        val StringBuilder meinBefehl = new StringBuilder
        meinBefehl.append("ssh pi@192.168.178.61 omxplayer \"/home/pi/SmartTable/")
        meinBefehl.append(VideoDatei)
        meinBefehl.append(".mp4\" --loop --no-osd")
        executeCommandLine(meinBefehl.toString)

I have no idea how to use the new syntax in this rule. Can anyone help me?

This was the first thread: Add Item in a executeCommandLine - #4 by Wolfgang_S

It was announced that executeCommandLine (which is not the Exec Binding) was among the breaking changes in OH 3. The new way to use executeCommandLine is documented at Actions | openHAB

So for my understanding i need to make a script? And then load the script via “executeCommandLine(pathToScript/script.py)”? Or can i add the script direct into executeCommandLine?

No, look at those docs again. The arguments you pass to executeCommandLine changed. You do not need to make a script.

executeCommandLine(DurationofSeconds(1), “ssh pi@192.168.178.61 omxplayer halloween.mp4”)

should work then?

The quoted string needs to be split into separate arguments which need to be separated by commas.

“executeCommandLine(ssh,pi@192.168.178.61,omxplayer,halloween.mp4)” ?

No

executeCommandLine("ssh", "pi@192.168.178.61", "omxplayer", "halloween.mp4")
1 Like

I cant fiure out whats wrong


meinBefehl.append("\"ssh\",\"pi@192.168.178.61\",\"omxplayer\",\"/home/pi/SmartTable/")
meinBefehl.append(VideoDatei)
meinBefehl.append(".mp4\"")
executeCommandLine(meinBefehl.toString)
logInfo("SmartTable Rule:", meinBefehl.toString)

log:

20:58:37.769 [INFO ] [ab.core.model.script.SmartTable Rule:] - "ssh","pi@192.168.178.61","omxplayer","/home/pi/SmartTable/Halloween.mp4"

Using this works fine:

executeCommandLine("ssh","pi@192.168.178.61","omxplayer","/home/pi/SmartTable/Halloween.mp4")

Theres no difference looking at the output
 Whats wrong?

You can not build the meinBefehl string before, executeCommandLine needs the parameters in separate strings

   if (receivedCommand != OFF) {
        val VideoDatei = SmartTable.state.toString
        executeCommandLine("ssh", "pi@192.168.178.61", "omxplayer", "/home/pi/SmartTable/" + VideoDatei + ".mp4", "--loop", "--no-osd")
1 Like

The not working is one string that has substrings with escaped double quotes.
The working one are separated strings.
What might work - I did not try - is to execute a script that gets one argument, your string.
It then runs a shell inside your script and executes the arguments. If that does not work write the arguments into a file during runtime and exeucte that file.

This is working for me. Unfortunately the “VideoDatei” is sometimes a name with spaces in it, sometimes not. Like “Mensch Ă€rgere Dich nicht” or “Halloween”.

With “Halloween” it is working fine. With “Mensch Ă€rgere Dich nicht” it is not working. I think the spaces are making trouble. Any way to get rid off these spaces inside the rule?

The quotes around the video file name and path where missing, try this:

executeCommandLine("ssh", "pi@192.168.178.61", "omxplayer", "\"/home/pi/SmartTable/" + VideoDatei + ".mp4\"", "--loop", "--no-osd")`

Thank you so much. Finally this works -

1 Like

Anyone who wants to do the same:

I made myself a GameTable, even the german youtuber “Spiel und Zeug” made a video about this. After updating to OH3 the GameTable was not working anymore. So here is the update, for my GameTable rule.

// AN/AUS

rule "SmartTable AN"
when
    Item SmartTable changed from OFF or
    Item SmartTable changed from NULL
then
    if (SmartTable.state != OFF) {
        if (Harmony_Kueche_Aktuelle_Aktivitaet.state == "PowerOff") {
        Harmony_Kueche_Aktuelle_Aktivitaet.sendCommand("TableTop")
        }
        if (Rollladen_Kueche.state != 50) {
        Rollladen_Kueche.sendCommand(100)
        }
        PhilipsHue_Kueche_Bewegungsmelder.sendCommand(OFF)
        PhilipsHue_Esstisch_Helligkeit.sendCommand(0)
        PhilipsHue_Esstisch_Schalter.sendCommand(OFF)
        Licht_Kueche_Schalter.sendCommand(OFF)
    }
end

rule "SmartTable AUS"
when
    Item SmartTable received command OFF
then
    if (Rollladen_Kueche.state == 100) {
        Rollladen_Kueche.sendCommand(0)
    }
    if (Harmony_Kueche_Aktuelle_Aktivitaet.state == "TableTop") {
        Harmony_Kueche_Aktuelle_Aktivitaet.sendCommand("PowerOff")
    }
    PhilipsHue_Esstisch_Helligkeit.sendCommand(100)
    PhilipsHue_Kueche_Bewegungsmelder.sendCommand(ON)
end

rule "Mapauswahl"
when
    Item SmartTable received command
then
    executeCommandLine("ssh", "pi@192.168.178.61", "killall", "omxplayer.bin")
    if (receivedCommand != OFF) {
        val VideoDatei = SmartTable.state.toString
        executeCommandLine("ssh", "pi@192.168.178.61", "omxplayer", "\"/home/pi/SmartTable/" + VideoDatei + ".mp4\"", "--loop", "--no-osd")
    }
end

I have a similar problem. I want to execute a command from openhab via ssh on another PC. This already works on the console without entering a password.

My code looks like this:

var logger = Java.type(‘org.slf4j.LoggerFactory’).getLogger(‘org.openhab.rule.’ + ctx.ruleUID);
var Exec =Java.type(“org.openhab.core.model.script.actions.Exec”);

logger.info(“BEGIN”);
Exec.executeCommandLine(“ssh","ubuntu@192.168.0.50”,“/home/ubuntu/vectorstream.sh restart &”)
logger.info(“END”);

I don’t get any error messages in the log, only the BEGIN and END messages.

You might start by capturing and logging out the message that Exec returns to you. You’ll need to specify a timeout for that.

Did you execute your console test with openhab user privileges ? Keep in mind OH runs with openhab user privileges and might not use the same private ssh key as your command line does.