Openhab 2 & Kodi

Hello

I try the Kodi Binding and everything works perfect.
Except the Kodi state for "Stop"
My rule knows the state “Play” & “Pause” but the state “Stop” doesnt work (it takes my rule for “Pause”).

My rule:

rule "Adjust living room lighting when XBMC starts/stops"
when
    Item KodiKeller_Kontrolle changed
then
    var String stateKino = KodiKeller_Kontrolle.state.toString()
  if (Xbmc_Kino_EA.state == ON){    
    switch (stateKino.lowerCase) {
		case "play" : {
                     Kino_ColorGroup1_Brightness.sendCommand(0)
                     Kino_ColorGroup2_Brightness.sendCommand(0)
                     Kino_ColorGroup3_Brightness.sendCommand(0)
                     Kino_ColorGroup4_Brightness.sendCommand(0)
                }
		case "pause" : {
                     Kino_ColorGroup1_Brightness.sendCommand(50)
                     Kino_ColorGroup2_Brightness.sendCommand(50)
                     Kino_ColorGroup3_Brightness.sendCommand(50)
                     Kino_ColorGroup4_Brightness.sendCommand(50)
		}
                case "stop" : {
    		      callScript("langzeitdimmer_kino")
		     }
    }
  }
end

What can i do?

Thanks, Marcel

The Kodi binding uses the “Player” item type. This item type only has a pause function (see https://www.eclipse.org/smarthome/documentation/concepts/items.html). AFAIK there is an enhancement request to provide a separate channel to execute stop requests.

Openhab see no difference between pause and stop…
Thats not good to hear.
Does the old XBMC Binding work or have it the same problem?

As a workaround: I solved this with the Script plugin on Kodi side. My Kodi issues MQTT commands on states. This is probably a little more complicated, but on the other hand, you have much more access to Kodi.

Instead of using MQTT it should be possible to send request via curl to Kodi. Here is an example: Kodi / XBMC Library Rescan via Button

I will create an enhancement request for Kodi to add a channel to stop the player.

The stop channel is aready there since around 3 weeks

Ok, but how can i get the state of the stop channel?

“Item Xbmc_Kino_Stop changed to Stop” or
"Item Xbmc_Kino_Stop changed to ON" doesnt work.

How can i get this in my rule to turn on lights when Kodi stops the playback?

THANKS

1 Like
  • 1 to find this out as well - as a test I have the state showing in my sitemap and it never shows stop, only play and pause (in caps as well - yuck)

Also noticed that the showtitle channel does not clear - always shows the last one played.

I guess the above comment about the smarthome comment also explaings why the player control doesnt have a stop button - wonder why this is the case I cant see why a basic media function like stop isnt included?

Have the same issue, play, pause works fine, but the stop channel doesn’t update if I stops from my Kodi remote. I have no idea why the stop has its own channel btw, why not put it in control like the rest?

Hi

Has someone already found a solution for this?
I can make a switch with the stop cannel

But i can not use it in a rule to put my lights at 100%

I have tried to check if mediatype is empty in my rule! (as a workaround)

That is not working, or my syntax is incorrect .

rule "Kodi stop light 100%"
when
      Item myKodi_mediatype != null 
then 
        E1Lachter1_Dimmer.sendCommand(100)
end

Any advice or ideas are welcome

Think this should work:

rule "Kodi stopped or playing"
when
	Item myKodiMediaType changed
then
	if (myKodiMediaType.state == "") {
		logInfo('Kodi','Kodi has stopped')
 	} else if (myKodiMediaType.state != null) {
 		logInfo('Kodi','kodi is playing something')
 	}
 end

Edit: But I do agree that it makes little sense not to have a “STOP” state for the Player item :confused:

Thanks for your advice,

I tried the code below, but its not working

rule "Kodi stopped or playing"
when
	Item myKodi_MediaType changed
then
	if (kodi:kodi:740d21d3:stop.state == "") {
		logInfo('Kodi','Kodi has stopped')
		E1Lachter1_Dimmer.sendCommand(100)
 	} else if (kodi:kodi:740d21d3:stop.state != null) {
 		logInfo('Kodi','kodi is playing something')
 		E1Lachter1_Dimmer.sendCommand(100)
 	}
 end

mayby the code is conflicting,with the code bellow
becouse when i press stop Kodi_State.state wil be pause en set my lights to 10%

and the rule “Kodi stopped or playing” must set my lights to 100%

rule "Adjust living room lighting when Kodi starts/stops"
when
    Item Kodi_State changed
then
    var String stateKodi = Kodi_State.state.toString()    
     switch (stateKodi.lowerCase) {
		case "play" : {
                     E1Lachter1_Switch.sendCommand(OFF)
                     E1LTafel_Switch.sendCommand(OFF)
                }
		case "pause" : {                           
			         E1Lachter1_Dimmer.sendCommand(10) 
		        }
        }  
end

You must define the mediatype channel as an item first, like:

kodi.items file:

String  myKodiMediaType "Mediatype [%s]"				{ channel="kodi:kodi:740d21d3:mediatype" }

And then the rule file:

rule "Kodi stopped or playing"
when
	Item myKodiMediaType changed
then
	if (myKodiMediaType.state == "") {
		E1Lachter1_Dimmer.sendCommand(100) // Kodi has stopped playing
 	} else if (myKodiMediaType.state != null) {
 		E1Lachter1_Dimmer.sendCommand(0) // Kodi is playing
 	}
 end

You are right,

I think I mixed some things up
Was defined in my item file as

String myKodi_mediatype     "Mediatyp [%s]"         { channel="kodi:kodi:740d21d3:mediatype" }

But not in my rule

wil try to correct en test this some other day .

thx for now

Thanks for the workaround, will try it tonight. Still hoping for a real solution though. Is it solved if I would download the latest version or not?

Did the solution work for you? If I’m correct, I tried something similar and it didn’t work for me.

Did you ever get around creating that enhancement request? Where can I sign up :wink:

The media player control was not changed but the Kodi bindings contains now a separate stop channel. Don’t remember when it was introduced but the current snapshot builds contains this channel

That’s great to hear, so far I only need the stop functionality in Kodi so I’m looking forward to trying that out. Thanks!

The stop channel doesn’t work properly for me. I can stop playback by sending ON to the stop channel. But when I stop playback in kodi directly, the channel doesn’t update in OH2.
Also nothing in the event log, I see that player, title and type for example change, but stop does not.

How can I check, which version of the addon I’m using? I tried via the karaf console, feature:list | grep kodi:
openhab-binding-kodi | 2.0.0 | x | Started | addons-2.0.0 | Kodi Binding

But in Paper UI under Control, I see that Kodi has a Stop switch so I assume it is supported?