Kodi Community Forum
Stop Screensaver from Python script - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: General Support (https://forum.kodi.tv/forumdisplay.php?fid=111)
+---- Forum: OS independent / Other (https://forum.kodi.tv/forumdisplay.php?fid=228)
+---- Thread: Stop Screensaver from Python script (/showthread.php?tid=250636)



Stop Screensaver from Python script - jagter5 - 2015-12-04

Hi,

How do I stop the screensaver from kicking in while running a long-duration python script?

I could not find any build-in functions or actions that will do this.

Any help?


RE: Stop Screensaver from Python script - BobCratchett - 2015-12-04

It's possible to set the screensaver to 'None' via json:-

Code:
xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "id": 0, "method":"Settings.setSettingValue", "params": {"setting":"screensaver.mode", "value":""} } ' )

You'd also need to make sure you get the current value first:-

Code:
xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "id": 0, "method": "Settings.getSettingValue", "params": {"setting":"screensaver.mode" } }')

And make sure you set it again once you're done Smile


RE: Stop Screensaver from Python script - jagter5 - 2015-12-04

Thanks

Works 100% and I have learned something


RE: Stop Screensaver from Python script - jagter5 - 2015-12-08

In retrospect, I realised I did not fully understand !!

After checking the logs etc, I realised the only thing that I implemented correctly, was stopping the screensaver.

Saving the existing Screensaver mode and setting it again, failed.

I do not fully understand the syntax of the JSON-RPC calls

This is what I have for saving and setting the screensaver mode

Code:
saver_mode = xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "id": 0, "method": "Settings.getSettingValue", "params": {"setting":"screensaver.mode" } }')

Code:
xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "id": 0, "method":"Settings.setSettingValue", "params": {"setting":"screensaver.mode", "value" : saver_mode} } ' )

Is this syntax correct?


RE: Stop Screensaver from Python script - spoyser - 2015-12-08

You need to put the contents of the variable into the string, ie

Code:
xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "id": 0, "method":"Settings.setSettingValue", "params": {"setting":"screensaver.mode", "value" : %s} }' % saver_mode )



RE: Stop Screensaver from Python script - BobCratchett - 2015-12-08

You also need to extract the value from the returned JSON - it won't just return a string containing the value. The Settings.getSettingValue will return something like:-

Code:
{"id":0,"jsonrpc":"2.0","result":{"value":"screensaver.xbmc.builtin.dim"}}



RE: Stop Screensaver from Python script - _BJ1 - 2016-08-31

Tried this out. Screensaver is indeed changing from the actual one to none (and backwards) but it didn't stop/deactivate an active screensaver. Where can I stop an actual running screensaver?


RE: Stop Screensaver from Python script - _BJ1 - 2017-03-18

Bumped it...


RE: Stop Screensaver from Python script - User 325245 - 2017-03-19

Just send the key to stop the saver: {"jsonrpc": "2.0", "method": "Input.Select", "id": 1}


RE: Stop Screensaver from Python script - Niccolo - 2023-05-20

Using Kodi 19 Matrix you should pay attention at least at two settings: screensaver.mode and powermanagement.displaysoff. This is an example on how to read the current value for powermanagement.displaysoff:

python:
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']

then you can change its value:

python:
# 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)))

But I think that calling the built-in function InhibitScreensaver(), new in Matrix 19, is more convenient:

python:
# Prevent any screensaver to start.
xbmc.executebuiltin('InhibitScreensaver(true)')

I wrote my notes and some example code on my wiki page.