Hi,
Need help in modifying this rule.
So the rule starts a timer every time kodi screensaver is ON, and switches off TV if still ON. myKodi_screensaver gets updated every minute by cron job script.
This rule works perfectly:
rule "KODI Screen Saver"
when
Item myKodi_screensaver received update
then
if(myKodi_screensaver.state == ON && Television.state == ON && timerKodi === null)
{logInfo("kodi.rules", "LGTV_ON - timer started")
timerKodi = createTimer(now.plusMinutes(8))
[ if(myKodi_screensaver.state == ON && Television.state == ON)
{Television.sendCommand(OFF)
logInfo("kodi.rules", "LGTV_OFF - TV has powered off")}
timerKodi = null]}
else if(myKodi_screensaver.state == OFF && timerKodi !== null)
{logInfo("kodi.rules", "LGTV_ON - timer canceled")
timerKodi.cancel
timerKodi = null}
end
However, since the item is updated every minute, if you start using kodi during the last minute of the timer, it will never get cancelled and TV will be switched off.
For that purpose I want to manually trigger kodi screensaver update status script (via switch KODIScreen).
I would like to run that switch AFTER the timer expired (to update the item and verify screensaver still ON), and then if screensaver state changed to OFF I would like the rule to go to cancel the timer, but that does not happen, it still goes through and fires…
any advice how to make it happen?
rule "KODI Screen Saver"
when
Item myKodi_screensaver received update
then
if(myKodi_screensaver.state == ON && Television.state == ON && timerKodi === null)
{logInfo("kodi.rules", "LGTV_ON - timer started")
timerKodi = createTimer(now.plusMinutes(8))
[KODIScreen.sendCommand(ON)
if(myKodi_screensaver.state == ON && Television.state == ON)
{Television.sendCommand(OFF)
logInfo("kodi.rules", "LGTV_OFF - TV has powered off")}
timerKodi = null]}
else if(myKodi_screensaver.state == OFF && timerKodi !== null)
{logInfo("kodi.rules", "LGTV_ON - timer canceled")
timerKodi.cancel
timerKodi = null}
end
EDIT: got it working it seems by just adding a bracket around the item {KODIScreen}
working rule:
rule "KODI Screen Saver"
when
Item myKodi_screensaver received update
then
if(myKodi_screensaver.state == ON && Television.state == ON && timerKodi === null)
{logInfo("kodi.rules", "LGTV_ON - timer started")
timerKodi = createTimer(now.plusMinutes(2))
[{KODIScreen.sendCommand(ON)}
if(myKodi_screensaver.state == ON && Television.state == ON)
{Television.sendCommand(OFF)
logInfo("kodi.rules", "LGTV_OFF - TV has powered off")}
timerKodi = null]}
else if(myKodi_screensaver.state == OFF && timerKodi !== null)
{logInfo("kodi.rules", "LGTV_ON - timer canceled")
timerKodi.cancel
timerKodi = null}
end
Once again proven, morning is smarter than the night