Kodi addon - how to detect screensaver / idle time

looking for a way to detect that kodi screensaver is active, so I can trigger some action (shutdown TV)
I have found this:
{“jsonrpc”: “2.0”, “method”: “XBMC.GetInfoBooleans”, “params”: { “booleans”: ["System.ScreenSaverActive "] }, “id”: 1}
from here: JSON API : checking whether the system is idle

Is there a way to use this with openhab?
to create an item that gets updated or something?

You may wonder why I dont just use kodi built in option - switch off monitor after x min idle - I cannot use that as I am using kodi for playing music to my home theater system (with TV switched off) - if I let him shutdown hdmi port - music stops. So I need a way to poweroff the TV
Currently I’m doing it with a ridiculous complicated rule which checks if video is playing or music is playing, if its music or nothing it starts timer for 10min, if meanwhile some video is started it cancels the timer and so on - it’s not perfect and it would be much more elegant to have a way for openhab to know if screensaver is active or not.


I think you can use the http binding for this.
But I am not sure.

You may use the exec binding or ExecuteCommandLine to run the shell script that you mentioned. Minor modifications might be required.

let me wake this topic up…

i finally got the time to work on this, here is the script that cron runs every 5min on kodi libre elec machine
if screensaver is active or not, it writes to opehab item myKodi_screensaver ON or OFF

ScreenSaverActive=$(curl -s -u root:yourkodipassword -X POST -H 'Content-type: application/json' -d '{"jsonrpc": "2.0", "method": "XBMC.GetInfoBooleans", "params": { "booleans": ["System.ScreenSaverActive "] }, "id": 1}' http://localhost:8080/jsonrpc)

case $ScreenSaverActive in
    echo ScreenSaver is active
    curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "ON" ""
    echo No ScreenSaver
    curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "OFF" ""

then i have just a simple rule to poweroff the tv after 6 minutes of waiting (its waiting for another 5min cycle of item update, if screensaver still running, kills the tv, otherwise cancels the timer

var Timer KodiTimer = null

rule "KODI Screen Saver"
    Item myKodi_screensaver received update
if(myKodi_screensaver.state == ON && Television.state == ON)
{if(KodiTimer === null)
{logInfo("kodi.rules", "LGTV_ON - timer started")
KodiTimer = createTimer(now.plusMinutes(6)) [
 TVOFF.sendCommand(if(myKodi_screensaver.state == ON && Television.state == ON) ON)
 logInfo("kodi.rules", "LGTV_OFF - TV has powered off")
 KodiTimer = null]}}
else if(myKodi_screensaver.state == OFF && KodiTimer !== null)
{logInfo("kodi.rules", "LGTV_ON - timer canceled")
KodiTimer = null}
1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.