====== How to disable the screensaver from a Kodi add-on ====== I wrote a Kodi **[[https://kodi.wiki/view/HOW-TO:Script_addon|script add-on]]** (that is different from a [[https://kodi.wiki/view/Audio-video_add-on_tutorial|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 [[https://kodi.wiki/view/JSON-RPC_API|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 [[https://xbmc.github.io/docs.kodi.tv/master/kodi-base/d0/d3e/page__list_of_built_in_functions.html#built_in_functions_15|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 ===== * **[[https://forum.kodi.tv/showthread.php?tid=250636|Stop Screensaver from Python script]]** * **[[https://forum.kodi.tv/showthread.php?tid=354784|Toggle Screensaver on/off through JSON-RPC?]]** * **[[https://kodi.wiki/view/JSON-RPC_API|Kodi JSON RPC API]]** * **[[https://xbmc.github.io/docs.kodi.tv/master/kodi-base/index.html|Kodi Documentation]]** (current) * **[[https://codedocs.xyz/w3tech/xodi/index.html|Kodi Documentation]]** (snapshot of version 19.0)