Dear Community!
I want to write a little rule to start a Harmony Activity if Kodi starts playing.
However, I want to do this dinamically, so when a music started, it should start “Listen to Music” Activity, etc…
Here is what I did so far.
rule "Start Playing"
when
Item KodiMediacenter_Stop received update OFF
then
Thread::sleep(2000)
if(CurrentActivityHub.state.toString == "PowerOff") {
switch(Kodi_mediatype.state.toString) {
case "song" :
CurrentActivityHub.sendCommand("Listen to Music")
case "episode" :
CurrentActivityHub.sendCommand("Watch a Movie")
case "movie" :
CurrentActivityHub.sendCommand("Watch a Movie")
case "radio" :
CurrentActivityHub.sendCommand("Listen to Music")
case "video" :
CurrentActivityHub.sendCommand("Watch a Movie")
case "unknown" : {
logInfo("radio.rules", "Switch case: unknown")
CurrentActivityHub.sendCommand("Listen to Music")
}
default : {
logInfo("radio.rules", "Switch case: Default")
CurrentActivityHub.sendCommand("Watch a Movie")
}
}
}
end
However, it seems that the switch case only evaluates to default. I think I’m missing something there.
Also I need a little Thread::sleep at the beginning because Kodi needs a little time to start playing something and read and send the details of what’s playing to openHab. That’s why it start’s with sleep, but it messes up somehow.
Also, I need further checking at case “unknown” and default case, because sometimes Kodi couldn’t get mediatype information (like when I’m playing through Airplay).
So my second question is how do you check a String type in openHab if it is empty?
For example(?):
if(KodiMediacenter_Album == null)
Am I correct? Can someone help me?
Thanks