I wanted to share a guide for anyone trying to get their tv to turn off when via CEC when the screensaver kicks in. The upside of this method is that you can have a period of traditional screensaver before the tv is turned off.
I have a bad habit of walking away with a movie paused, and I hated wasting the power. So here is my workaround. I hope it helps someone else who is also frustrated.
I had been using the screen saver Turn Off, and it worked for a long time. Then somewhere around v18 of CoreElec it stopped turning off my tv if I had a video paused. That screensaver still works fine when sitting idle in the GUI, but never if the video was paused.
The following scripts turn the TV off 60 seconds after any screensaver kicks in. You can adjust the scripts if you want a different time period.
I hope this help other Eco-friendly media lovers.
- Install service add-on ‘Kodi Callbacks’
- Create two scripts (code below). I placed mine in the downloads folder to make finding them easy.
- Enable any screensaver and set it to your preferred wait time like normal.
- Configure Kodi Callbacks Tasks
- Under Tasks
- Set Task 1 to Script
- Max number = 1
- Script executable file - browse to TurnOff.sh (I have mine in /storage/downloads/TurnOff.sh)
- Set Task 2 to Script
- Max number = 1
- Script executable file - browse to TurnOn.sh (I have mine in /storage/downloads/TurnOn.sh)
- Configure Kodi Callbacks Events
- Set event for Event 1 to on Screensaver Activated
- Task = Task 1
- Set event for Event 2 to on Screensaver Deactivated
- Task = Task 2
I suggest using ssh and nano to create the scripts.
#!/bin/bash sleep 60 echo "standby 0" | cec-client -s
#!/bin/bash kill -9 $(pgrep -f turnoff.sh) echo "on 0" | cec-client -s
- Be sure to chmod +x the scrips to make them executable.
- Remove the sleep 60 statement if you want the tv to go to sleep immediately, and not show the screensaver for 60 seconds. Change the 60 to another time in seconds if you want to show the screensaver for more than 1min before turning off the tv.
- These scripts assume that your TV is device 0. If your TV is another device then you need to change the 0 to whatever it is. The cec-client is beyond the scope of this guide, but google has your back.
- I found that the Asteroids screensaver caused the box to freeze after executing the CEC suspend commad. I don’t suggest using that. All the others I tested seem to be fine.
- This may not work for all TVs as CEC support can be spotty, but it worked on my Samsung and TCL TVs.
- I had trouble with the Kodi Callback GUI scrolling all the way to the bottom every time I tried to set event 2. You can try another skin, or you can edit the settings file manually. It is in Userdata\addon_data\script.service.kodi.callbacks\settings.xml
- I am using an S905x (Nexbox A95X) box. I assume this will work on others, but I have not tested it.
- Corrected an oversight in the second script, and added the line I forgot which kills any pending requests to turn off the TV.