I think the stop channel only works as button (in german as a “Taster”) that only sends a stop command to Kodi. openHAB has currently no button widget, so a switch is normally used for this purpose. But the switch does not really represent the current state.
But I think in this case it should be possible that the stop channel can give a feedback whether Kodi is playing something or not.
I read the thread and want to show you my version of controling the lights when watching a movie with Kodi. Hence there is no really “Stop” state my rules based on a Player item for the control channel and a String item for the mediatype channel, Ignoring the stop channel completely. I want to dim the lights while watching movies, brighten them in breaks and at the end. But the light should not change while listening to music or looking pictures. Here you are:
rule "Kodi Player Command changed to PLAY"
when
Item kodi2LivingRoomPlayerCommand changed to PLAY
then
if( (kodi2LivingRoomPlayerType.state.toString == "channel") ||
(kodi2LivingRoomPlayerType.state.toString == "episode") ||
(kodi2LivingRoomPlayerType.state.toString == "movie") ||
(kodi2LivingRoomPlayerType.state.toString == "video") ) {
callScript("lights.darken")
}
end
rule "Kodi Player Command changed to PAUSE"
when
Item kodi2LivingRoomPlayerCommand changed to PAUSE
then
callScript("lights.brighten")
end
Why do I use these three rules?
The first and second rule together may be a solution for the requirement. But when you want to darken the light only for video or movie files you had to check the media type. In a lot of situations the media type is not correct when the first rule is executed. This can be traced back to the sequence in which the binding refreshes channels.
The third script is a solution as well. But when you want to brighten the lights in a break you need all three rule together. Another positive side effect of this combination is that the brightness of the light changes when you are listening to music and start a movie in the background.
Currently I am thinking about implementing a trigger-channel in the Kodi binding for handling this scenario a little easier.
Tried your rule and just read your description again. If I’m correct, you don’t distinguish between PAUSE and STOP.
So I’m still missing the functionality of the old binding in OH1. In my scenario, I have to distinguish:
PLAY (movie or episode): 2 lamps switch off
PAUSE: one of the lamps dims to 50%
STOP: both lamps switch to 100% again.
So I really do need the stop channel again I’m afraid.
Yes that is correct. I don’t do that. In case of STOP the media type is set to “”, in case of PAUSE it remains the same value as before. Maybe that helps.
//EDIT: I agree, the referenced pull request solves your problem.
Already tried to use the media type to distinguish between the two states, but that didn’t work cleanly either. I think the media type wasn’t always set to “” when the state already changed so you would have to work with sleeps and that always gets a bit messy.
Thanks for confirming, I think I’ll just wait for the pull request to be available then my problems should be solved
Hi, i’m into OH just 2-3 weeks but have been able to fully integrate my 3 Kodi system.
Everything works and I can control volume, switching lights based on play-mode and displaying OH messages on TV when a OH trigger been raised.
The only problem I have is when Kodi/XBMC is crashing or is getting powered-off… this is causing an error in OH when trying to send commands to the Kodi Instance.
How can I avoid such error and detect that a Kodi instance has died or become unavailable?
Whenever Kodi is starting or getting closed/crashing OH is receiving either of the below messages.
Message when Kodi starts:
[me.event.ThingStatusInfoChangedEvent] - 'kodi:kodi:a972fc7c-ce36-9cfe-7f1a-81c63cfe850f' changed from OFFLINE to ONLINE
Message when Kodi is closed or even crashed:
[me.event.ThingStatusInfoChangedEvent] - 'kodi:kodi:a972fc7c-ce36-9cfe-7f1a-81c63cfe850f' changed from ONLINE to OFFLINE
I tried to catch the event with according rule but it is not detecting
rule "Handle KODI1"
when
Channel 'kodi:kodi:a972fc7c-ce36-9cfe-7f1a-81c63cfe850f' triggered
then
logInfo("Kodi 1 alarm", "===============>>>>>>>> KODI is on/off <<<===================")
end
Unfortunately the rule is not detecting the change in the Kodi instance! … is there any way to identify the Kodi is actively running ? …
Maybe yes. It depends on your setup. If the device running Kodi is offline too, you can try to use the Network binding. If the device is online and only the Kodi instance is down, I think it is not possible.
Could you send me an abstract of your log file, containing such an error? Maybe we can try to handle it and avoid those messages.
rule "new kodi message"
when
Item Kodi_Message received command
then
logInfo("=========>> Mesage ========>> ", Kodi_Active.state.toString)
if (Kodi_Active.state.toString=="1" ) sendCommand(sKodi1_Msg,Kodi_Message.state.toString) // send to Kodi-1
if (Kodi_Active.state.toString=="2" ) sendCommand(sKodi2_Msg,Kodi_Message.state.toString) // send to Kodi-2
if (Kodi_Active.state.toString=="3" ) { sendCommand(sKodi1_Msg,Kodi_Message.state.toString) // send to both
sendCommand(sKodi2_Msg,Kodi_Message.state.toString) }
end
This is the error message when the Kodi-2 instance is not active (works without error when instance is up):
13:07:58.132 [INFO ] [marthome.event.ItemStateChangedEvent] - Kodi_Message changed from Dog Movement detected !! to Entrance Movement detected !!
13:07:58.132 [INFO ] [cript.=========>> Mesage ========>> ] - 3
13:07:58.132 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'sKodi1_Msg' received command Entrance Movement detected !!
13:07:58.147 [ERROR] [i.internal.protocol.KodiClientSocket] - Error during callMethod
java.lang.Exception: socket not initialized
at org.openhab.binding.kodi.internal.protocol.KodiClientSocket.sendMessage(KodiClientSocket.java:197)[183:org.openhab.binding.kodi:2.0.0]
at org.openhab.binding.kodi.internal.protocol.KodiClientSocket.callMethod(KodiClientSocket.java:222)[183:org.openhab.binding.kodi:2.0.0]
at org.openhab.binding.kodi.internal.protocol.KodiConnection.showNotification(KodiConnection.java:490)[183:org.openhab.binding.kodi:2.0.0]
at org.openhab.binding.kodi.handler.KodiHandler.handleCommand(KodiHandler.java:143)[183:org.openhab.binding.kodi:2.0.0]
at org.eclipse.smarthome.core.thing.internal.ThingManager$4.call(ThingManager.java:372)[105:org.eclipse.smarthome.core.thing:0.9.0.b4]
at org.eclipse.smarthome.core.thing.internal.ThingManager$4.call(ThingManager.java:1)[105:org.eclipse.smarthome.core.thing:0.9.0.b4]
at org.eclipse.smarthome.core.common.SafeMethodCaller$CallableWrapper.call(SafeMethodCaller.java:179)[98:org.eclipse.smarthome.core:0.9.0.b4]
at java.util.concurrent.FutureTask.run(Unknown Source)[:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)[:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)[:1.8.0_131]
at java.lang.Thread.run(Unknown Source)[:1.8.0_131]
13:07:58.147 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'sKodi2_Msg' received command Entrance Movement detected !!
13:08:00.576 [INFO ] [marthome.event.ItemStateChangedEvent] - mDog changed from OFF to ON
13:08:00.576 [INFO ] [marthome.event.ItemStateChangedEvent] - mDog_last changed from 2017-05-16T12:32:27.353+1000 to 2017-05-16T13:08:00.576+1000
13:08:00.576 [INFO ] [g.eclipse.smarthome.model.script.Dog] - Movement detected !!
13:08:00.592 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Kodi_Message' received command Dog Movement detected !!
13:08:00.592 [INFO ] [marthome.event.ItemStateChangedEvent] - Kodi_Message changed from Entrance Movement detected !! to Dog Movement detected !!
13:08:00.592 [INFO ] [cript.=========>> Mesage ========>> ] - 3
13:08:00.592 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'sKodi1_Msg' received command Dog Movement detected !!
13:08:00.592 [ERROR] [i.internal.protocol.KodiClientSocket] - Error during callMethod
java.lang.Exception: socket not initialized
at org.openhab.binding.kodi.internal.protocol.KodiClientSocket.sendMessage(KodiClientSocket.java:197)[183:org.openhab.binding.kodi:2.0.0]
at org.openhab.binding.kodi.internal.protocol.KodiClientSocket.callMethod(KodiClientSocket.java:222)[183:org.openhab.binding.kodi:2.0.0]
at org.openhab.binding.kodi.internal.protocol.KodiConnection.showNotification(KodiConnection.java:490)[183:org.openhab.binding.kodi:2.0.0]
at org.openhab.binding.kodi.handler.KodiHandler.handleCommand(KodiHandler.java:143)[183:org.openhab.binding.kodi:2.0.0]
at org.eclipse.smarthome.core.thing.internal.ThingManager$4.call(ThingManager.java:372)[105:org.eclipse.smarthome.core.thing:0.9.0.b4]
at org.eclipse.smarthome.core.thing.internal.ThingManager$4.call(ThingManager.java:1)[105:org.eclipse.smarthome.core.thing:0.9.0.b4]
at org.eclipse.smarthome.core.common.SafeMethodCaller$CallableWrapper.call(SafeMethodCaller.java:179)[98:org.eclipse.smarthome.core:0.9.0.b4]
at java.util.concurrent.FutureTask.run(Unknown Source)[:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)[:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)[:1.8.0_131]
at java.lang.Thread.run(Unknown Source)[:1.8.0_131]
13:08:00.608 [INFO ] [marthome.event.ItemStateChangedEvent] - sKodi1_Msg changed from Entrance Movement detected !! to Dog Movement detected !!
13:08:00.608 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'sKodi2_Msg' received command Dog Movement detected !!
13:08:00.608 [INFO ] [marthome.event.ItemStateChangedEvent] - sKodi2_Msg changed from Entrance Movement detected !! to Dog Movement detected !!
How do you determine the state of the Kodi_Active item? This seems to be the interesting part.
The error message seems familiar to me. I saw it in my logs, too. In the same situations you mentioned - after a Kodi crash and sometimes after a reboot. IMHO the connection of the socket could be checked, before sending a notification to the Kodi instance. Maybe we should open an issue in the openHAB 2-addons repo to avoid those message
sounds good. I am happy you find a solution. You’re welcome, ask again if anything matters.
I had another idea this night. You can access the ONLINE or OFFLINE Status of a thing via the REST API. Combined with the HTTP binding and a JavaScript Transformation it is possible to setup a Switch item for each Kodi instance and change it to ON/OFF if the Kodi status changes. I am going to test that way and post it here.
currently it is not possible with the Kodi binding. Since the Kodi uses a JSON-RPC API you can access them in the same way as described in my last post (HTTP binding combined with a JavaScript Transformation). I imagine that there is a tutorial or post in this forum describing this method with more details -
but I cannot find it at the moment.
Which properties do you miss at much? The only thing I am missing is the Screensaver.State.