Start and stop Kodi via executeCommandLine

Hi,

to be honest, I can’t find my mistake. I wrote myself a rule that allows me to quit Kodi and start another application on the machine. If I close the other application, I would like to start Kodi again.

Quitting Kodi works without any problems:

executeCommandLine("/usr/bin/sshpass","-p","<password>","/usr/bin/ssh","-t","-o","StrictHostKeyChecking=no","<username>@<ip>","sudo","/usr/bin/killall","-9","/usr/lib/x86_64-linux-gnu/kodi/kodi.bin")

Starting Kodi does not work. I tried multiple different ways. The last was:

executeCommandLine("/usr/bin/sshpass","-p","<password>","/usr/bin/ssh","-t","<username>@<ip>","export","DISPLAY=:0;","/usr/bin/kodi","--standalone")

If I try it via the command line it worked:

sudo -u openhab /usr/bin/sshpass -p <password> /usr/bin/ssh -t <username>@<ip> 'export DISPLAY=:0; /usr/bin/kodi --standalone'

I also tried it with StrictHostKeyChecking=no. I received the same result. And I also tried it by adding \& or for executeCommandLine \\& on the target and & on the host.

Thanks in advance.

I would try to run executeCommandLine in this way:
var ScriptResponse = executeCommandLine(Duration.ofSeconds(60), "your, options, here")
to get back an error message and print it to the openhab log using e.g.

logInfo("Log", ScriptResponse)

Who is the owner / logged in user of the DISPLAY ?
Using DISPLAY=:0 user openhab needs to be allowed to open/use the DISPLAY.

Maybe consider another way to do it.

  1. use public keys to establish ssh connection.
  2. build a script on the kodi machine, which is able to start and stop kodi
  3. send a simple message to that script.

I’ve written a tutorial in the german inofficial :slight_smile: openhabforum: Persistieren einer Gruppe - Seite 2 - openhabforum.de Don’t get disturbed by the title nor the length of text…

The tutorial is for safely shutting down a Pi remote, but it should be very easy to change functionality.