Add Item in a executeCommandLine

Hey guys,

is there a way to implement an item in a executeCommandLine?

rule "SmartTable"
when
    Item SmartTable changed
then
    executeCommandLine("ssh pi@192.168.178.49 omxplayer /home/pi/Desktop/GameTable/"+ SmartTable +".mp4")

end

As you see, i want in the executeCommandLine an ttem called SmartTable to be added to the String.

When i set SmartTable to “Halloween” i want it to send the command

ssh pi@192.168.178.49 omxplayer /home/pi/Desktop/GameTable/Halloween.mp4

automatically. Unfortunately, my setup isnt working like this.

Have a look at this thread: [SOLVED] executeCommandLine inject variable

It describes how to concatenate the string you need during runtime.
Instead of using “+” you need to use StringVariable.append to concatenate your string components.

Thanks for your quick reply.

So for my understanding the code needs to look like this:

var video = SmartTable
val StringBuilder myCommand = new StringBuilder
myCommand.append(ssh pi@192.168.178.49 omxplayer /home/pi/Desktop/GameTable/)
myCommand.append(video)
myCommand.append(.mp4)

executeCommandLine(myCommand.toString, 200)

Am i right?

My Filename must be storaged in a String-Item. Can i add the item this easily to the variable using “var video = SmartTable”?

You need to add double quotes around the string containing the ‘fixed’ strings.
To put the string of the item SmartTable into the variable video you need add .toString ( ? ) to SmartTable.

var video = SmartTable.toString
val StringBuilder myCommand = new StringBuilder
myCommand.append("ssh pi@192.168.178.49 omxplayer /home/pi/Desktop/GameTable/")
myCommand.append(video)
myCommand.append(".mp4")

executeCommandLine(myCommand.toString, 200)

Like this? The Item SmartTable is already a String-Item. Is it still necessary to add “.toString” to the SmartTable Item?

Try it…
Write the string myCommand to the openhab log file and check if it is as you would like to have it:

logInfo("SmartTable rule", "my command string: {}", myCommand.toString )

Since SmartTable is an Item, you need to get its State first. It will be a StringType, which you can then convert it to a string with .toString. Also, since video is not changing, use val instead of var.

val video = SmartTable.state.toString

Thanks for all of your replies.

I fixed it using this:

rule "Mapauswahl"
when
    Item SmartTable changed
then
    val video = SmartTable.state.toString
    val StringBuilder myCommand = new StringBuilder
    myCommand.append("ssh pi@192.168.178.49 omxplayer \"/home/pi/Desktop/GameTable/")
    myCommand.append(video)
    myCommand.append(".mp4\" --loop --no-osd")
    executeCommandLine(myCommand.toString)
end
1 Like