Hi,
I have a problem with some rules.
What I’m trying to achieve:
Rule1
-when kodi playback is stopped or paused, switch off TV after 15min. before switching off, make sure it is still stopped. if playback changed to PLAY, cancel the timer.
Rule2
- when kodi is playing music, switch off TV after 15min. before switching off, make sure it is still playing music (and not videos). If media type is changed to something else than song, cancel the timer.
here are my rules, please let me know where is the mistake,and/or if there is a smarter way of doing this.
var Timer KodiTimer = null
rule "KODI Stop"
when
Item myKodi_control changed
then
if(KodiTimer !== null) {
KodiTimer.cancel()}
else if(myKodi_control.state.toString == "PAUSE")
{KodiTimer = createTimer(now.plusMinutes(15)) [
LgTvPower.sendCommand(if(myKodi_control.state.toString == "PAUSE") ON)]}
else if(myKodi_control.state.toString == "PLAY")
{KodiTimer.cancel()}
end
rule "KODI Music"
when
Item myKodi_mediatype changed
then
if(KodiTimer !== null) {
KodiTimer.cancel()}
else if(myKodi_mediatype.state.toString == "song")
{KodiTimer = createTimer(now.plusMinutes(15)) [
LgTvPower.sendCommand(if(myKodi_mediatype.state.toString == "song") ON)]}
else if(myKodi_mediatype.state.toString !== "song")
{KodiTimer.cancel()}
end
thanks