Working out why items are receiving commands

Hi All

Not sure what’s changed by the kodi_control item used to control the media player has suddenly started to switch to PLAY or PAUSE for a reason I’m yet to work out.

When its play, it turns my light motion sensor off which means im in the dark at night! :slight_smile:

The log is full of play/pause.

Any suggestions on how to troubleshoot? I have an Widget which has PLAY/PAUSE buttons but my Rules only react to it being on PLAY or PAUSE.

I cant work out why its doing this :frowning:

Any suggestions??
Thanks!

The offending item is this:

myKodi_control
mber percent = 0
var Timer fade_timer = null

rule "Apply Scene and turn the TV to the correct input for FTA when TV OFF"
when
    Item TVProxyFTA received command ON
then
    if (TVStatusONOFF.state == OFF && Yamaha_Power.state  == OFF) {
     Zone_1_Scene.sendCommand("Scene 1")
     Thread::sleep(3000)
     TV.sendCommand("TVFreeToAir")
   }
end





rule "Apply Scene and turn the TV to the correct input for FTA when TV ON"
when
   Item TVProxyFTA received command ON
then
   if (TVStatusONOFF.state == ON) {
    Zone_1_Scene.sendCommand("Scene 1")
    Thread::sleep(1000)
    TV.sendCommand("TVFreeToAir")
  }
end





rule "Watch a Vero Movie, Dim the Lights and Turn All AV Equipment on"
when
        Item Scene_Watch_Vero received command ON
then
    var String scene = "Vero Scene"
    //Switch on TV
    if (TVStatus.state == OFF) {
        TV.sendCommand("TVOnOff")
        logInfo(scene, "TV switched On")
    }
    //Switch On AVR
    if (Main_Zone_Power.state == OFF) {
        Main_Zone_Power.sendCommand(ON)
        logInfo(scene, "AVR switched on")
    }
    //Change AVR Scene to Movie
    if ((Zone_1_Scene.state != "Scene 1" || Zone_1_Scene.state != "Scene 2")) {
         Zone_1_Scene.sendCommand("Scene 3")
         logInfo(scene, "AVR Scene set to Vero")
    }
end

rule "When Kodi Player changed to PLAY"
when
        Item myKodi_control changed
then
if (myKodi_control.state == PLAY){
    FibaroEye1Motion_Armed.sendCommand(OFF)   // Disable the motion sensor from turning on
    //Slowly Dim the Lights if they are on
    if (LivingRoomSw1.state == ON) {
        if (fade_timer === null) {
           percent = LivingRoomDim1.state as Number
           fade_timer = createTimer(now.plusMillis(100), [ |
                if (percent > 0) {
                    percent = percent - 2
                    if (percent < 0) percent = 0
                    LivingRoomDim1.sendCommand(percent)
                    fade_timer.reschedule(now.plusMillis(100))
                } else {
                    fade_timer = null
                }
            ])
        }
    }
}
else {
     FibaroEye1Motion_Armed.sendCommand(ON) // Enable the motion sensor for any other state of myKodi_control
}
end


rule "When Kodi Player changed to PAUSE"
when
        Item myKodi_control changed to PAUSE
then
    Thread::sleep(200)
     if (FibaroEye1Lux.state < 20 && LivingRoomSw1.state == OFF  && myKodi_stop.state == OFF)
        LivingRoomDim1.sendCommand(5)
end


rule "When Kodi Player changed to ON"
when
        Item myKodi_stop changed to ON
then
 //Slowly Brighten the Lights at the end of the Movie
     if (LivingRoomSw1.state == OFF && FibaroEye1Lux.state < 20) {
        if (fade_timer === null) {
            percent = LivingRoomDim1.state as Number
            if (percent == 0) {
                fade_timer = createTimer(now.plusMillis(100), [ |
                    percent = percent + 2 // increase slowly
                    if (percent <= 30) { // up to 30%
                        LivingRoomDim1.sendCommand(percent)
                        fade_timer.reschedule(now.plusMillis(100))
                        FibaroEye1Motion_Armed.sendCommand(ON)
                    } else {
                        fade_timer = null
                    }
                ])
            }
        }
    }
end




rule "Kodi Video Library Scan"
when
        Item myKodi_rescan received command
then
        val result = executeCommandLine("/etc/openhab2/scripts/kodi_rescan.sh", 5000)
        logInfo("Kodi Library Scan", result)
end

rule "Check Vero Presense"
when
        Thing "kodi:kodi:d78d7398" changed to ONLINE or
        Thing "kodi:kodi:d78d7398" changed to OFFLINE
then
        var thingStatusInfo_Vero = getThingStatusInfo("kodi:kodi:d78d7398")
                if ((thingStatusInfo_Vero !== null) && (thingStatusInfo_Vero.getStatus().toString() == "ONLINE")) {
          logInfo("Vero Status", "Vero is online.")
        } else {
          logError("Vero Status", "Vero is offline")
}
end

rule "Turn Kodi Subtitle Off"
when
        Item myKodi_subtitle_off received command OFF
then
        val String URL = "http://192.168.0.12:8080/jsonrpc"
        var String contenttype = "application/json"
        var String jsondata = '{"jsonrpc":"2.0","id":1,"method":"Player.SetSubtitle","params":{"playerid":1,"subtitle":"off"}}'

        logInfo("Kodi subtitle", "Sending Command " + myKodi_subtitle_off.state + " to myKodi_subtitle_off.")

        sendHttpPostRequest(URL, contenttype, jsondata)
end


rule "Turn Kodi Subtitle On"
when
        Item myKodi_subtitle_on received command ON
then
        val String URL = "http://192.168.0.12:8080/jsonrpc"
        var String contenttype = "application/json"
        var String jsondata = '{"jsonrpc":"2.0","id":1,"method":"Player.SetSubtitle","params":{"playerid":1,"subtitle":"on"}}'

        logInfo("Kodi subtitle", "Sending Command " + myKodi_subtitle_on.state + " to myKodi_subtitle_on.")

        sendHttpPostRequest(URL, contenttype, jsondata)
end


rule "Mute and unmute the music in case of a Call"
when
    Item Mute_Music received command
then
    if (Main_Zone_Power.state == ON && (spotify_current_playing.state == ON || myKodi_control.state == PLAY )) {
        Zone_1_Mute.sendCommand(receivedCommand)
        logInfo("Mute",if(receivedCommand == ON) "Music muted due to Incoming Call" else "Music unmuted due to Call Hang Up")
        }
end

rule "Pause Kodi if the Doorbell rings"
when
   Item DoorBird_DoorBell received command ON
then
   if (myKodi_control.state == PLAY){
       myKodi_control.sendCommand(PAUSE)
      logInfo("Kodi", "The movie has been paused as theres someone at the door")
}
end

rule "Mute and unmute the music in case of a Doorbird ring"
when
    Item DoorBird_DoorBell received command
then
    if (Main_Zone_Power.state == ON && (spotify_current_playing.state == ON || myKodi_control.state == PLAY )) {
        Zone_1_Mute.sendCommand(ON)
        logInfo("Mute",if(receivedCommand == ON) "Music muted due to Doorbird ring" else "Music unmuted due to Doorbird hangup")
        }
    if (DoorBird_SIP.state == OFF) {
        Zone_1_Mute.sendCommand(OFF)
}
end

Your description is unclear and indicates you misunderstand a couple of things.
Rules never react on an item being in a state but only ever on item state changes.
Is your problem that you receive many play/pause events ? or is it that you think your rules should not react when you receive play/pause ?

When you say “the log is full of play/pause”, you must be more precise: what log, and what unit is creating those entries ?

If it’s the Kodi binding then you have to debug your Kodi as it shouldn’t be sending that all the time.

If you cannot do that then you have to add additional data checks in your rules to differentiate “fake” events from “real” ones, but you have to find out for yourself how to do that.

Hi Markus,

Yes, I receive many play/pause events as indicated in the events log here:

2019-02-07 19:34:13.959 [ome.event.ItemCommandEvent] - Item 'myKodi_control' received command PAUSE
2019-02-07 19:34:13.961 [nt.ItemStatePredictedEvent] - myKodi_control predicted to become PAUSE
2019-02-07 19:34:13.962 [vent.ItemStateChangedEvent] - myKodi_control changed from PLAY to PAUSE
2019-02-07 19:34:28.789 [ome.event.ItemCommandEvent] - Item 'myKodi_control' received command PLAY
2019-02-07 19:34:28.791 [nt.ItemStatePredictedEvent] - myKodi_control predicted to become PLAY
2019-02-07 19:34:28.792 [vent.ItemStateChangedEvent] - myKodi_control changed from PAUSE to PLAY

These are from the item myKodi_control

Player myKodi_control               "Control"                   { channel="kodi:kodi:d78d7398:control" }

lll look into the binding debug, thanks

So its been happening a bit and I cant work out why. I’ve enabled the debug on the kodi binding and I did a test to change PAUSE to PLAY



10-Feb-2019 18:32:17.858 [DEBUG] [ab.binding.kodi.internal.protocol.KodiClientSocket] - Message received from server: {"error":{"code":-32602,"data":{"method":"Player.PlayPause","stack":{"message":"Value between 0 (inclusive) and 2 (inclusive) expected but -1 received","name":"playerid","type":"integer"}},"message":"Invalid params."},"id":51,"jsonrpc":"2.0"}
10-Feb-2019 18:32:17.858 [DEBUG] [ab.binding.kodi.internal.protocol.KodiClientSocket] - callMethod returns {"error":{"code":-32602,"data":{"method":"Player.PlayPause","stack":{"message":"Value between 0 (inclusive) and 2 (inclusive) expected but -1 received","name":"playerid","type":"integer"}},"message":"Invalid params."},"id":51,"jsonrpc":"2.0"}
10-Feb-2019 18:32:17.859 [DEBUG] [ab.binding.kodi.internal.protocol.KodiClientSocket] - Error received from server: {"code":-32602,"data":{"method":"Player.PlayPause","stack":{"message":"Value between 0 (inclusive) and 2 (inclusive) expected but -1 received","name":"playerid","type":"integer"}},"message":"Invalid params."}


Its about all I can find right now. Its saying INVALID Parameters when a JSON request is made. Does this look like a Kodi binding issue?

Regards

It seems that a refresh or update of the items file or a restart of the system definitely turns the switch OFF in this case.