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?
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?
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?
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”);
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.