Guest - Testers are needed for the reworked CDateTime core component. See... https://forum.kodi.tv/showthread.php?tid=378981 (September 29) x
Stop Screensaver from Python script
#1
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?
Reply
#2
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
Reply
#3
Thanks

Works 100% and I have learned something
Reply
#4
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?
Reply
#5
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 )
Reply
#6
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"}}
Reply
#7
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?
Reply
#8
Bumped it...
Reply
#9
Just send the key to stop the saver: {"jsonrpc": "2.0", "method": "Input.Select", "id": 1}
Reply
#10
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.
Reply

Logout Mark Read Team Forum Stats Members Help
Stop Screensaver from Python script0