User Tools

Site Tools


doc:appunti:software:kodi_addon_disable_screensaver

How to disable the screensaver from a Kodi add-on

I wrote a Kodi script add-on (that is different from a audio/video plugin add-on) to play a special slideshow from a directory containing images. The peculiarity of my script is that it performs a resize and crop of images on the fly, following the instructions of a playlist.

Writing the add-on I faced the problem to disable the screensaver during image playback. It turned out that on the internet you find several examples, which are sometimes confusing and not working. In this page I hope to explain all the possibilities offered by Kodi 19 Matrix.

Before Kodi 19 Matrix the only way to disable the screensaver was to change settings via the JSON RPC API, starting with version 19 it is possible (and simpler) to call a built-in function.

Using JSON RPC

There are several Kodi settings related to the screensaver, screen dimming and power saving. From the Python code of the add-on it is possible to read each setting and change its value. Generally it is necessary to read the current settings when the add-on is started, change the values if required and restore the previous values on add-on exit.

Into the add-on code you can use the Python function xbmc.executeJSONRPC() to communicate with Kodi itself, using the JSON RPC API. You may need to save/change/restore several settings to effectively disable the screensaver. In my experience the most important are powermanagement.displaysoff and screensaver.mode: setting the first to zero and the second to the empty string should turn off any screensaver in Kodi.

powermanagement.displaysoff [int] Time in minutes to wait before turning off the display. When set to zero the function is disabled. This setting can be enabled even if no screensaver is active.
screensaver.mode [str] Name of the active screensaver. An empty string means to active screensaver.
screensaver.time [int] Time in minutes before starting the screensaver. This timer is indipendent from powermanagement.displaysoff.
screensaver.usedimonpause [bool] Dim the display when media is paused.
# Read current value of powermanagement.displaysoff setting.
command = {
    'jsonrpc': '2.0', 'id': 0, 'method': 'Settings.getSettingValue',
    'params': { 'setting': 'powermanagement.displaysoff' }
}
json_rpc = json.loads(xbmc.executeJSONRPC(json.dumps(command)))
self.saved_displaysoff = json_rpc['result']['value']
# Set powermanagement.displaysoff to zero, to disable display power off.
command = {
    'jsonrpc': '2.0', 'id': 0, 'method': 'Settings.setSettingValue',
    'params': { 'setting': 'powermanagement.displaysoff', 'value': 0}
}
json_rpc = json.loads(xbmc.executeJSONRPC(json.dumps(command)))
 
# ... Add-on executes its job...
 
# Restore powermanagement.displaysoff to the saved value.
command = {
    'jsonrpc': '2.0', 'id': 0, 'method': 'Settings.setSettingValue',
    'params': { 'setting': 'powermanagement.displaysoff', 'value': self.saved_displaysoff}
}
json_rpc = json.loads(xbmc.executeJSONRPC(json.dumps(command)))

Using a built-in function

There is another way to disable the screensaver in Kodi: it is a built-in system function called InhibitScreensaver() that was added in Kodi 19 Matrix. To call a built-in function there is the Python xbmc.executebuiltin():

# Prevent any screensaver to start.
xbmc.executebuiltin('InhibitScreensaver(true)')
 
# ... Add-on executes its job...
 
# Restore the screensaver default behaviour.
xbmc.executebuiltin('InhibitScreensaver(false)')

Web References

doc/appunti/software/kodi_addon_disable_screensaver.txt · Last modified: 2023/05/20 19:29 by niccolo