Kodi Community Forum

Full Version: Creating a smart sleep script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I need some help with creating a smart script for put the HTPC into sleep mode.

The problem: There is an x86 PC with latest Libreelec controlled by an unbranded MCE IR remote. The default action at pushing power button on remote is sleep mode.
The HTPC goes to sleep mode and wakes up very fast when the power button is pressed. It is so fast that after wake up it still receives the signal form the remote and the system goes to sleep again. It is because the remote sends multiple IR pulses.

As a solution I would like to replace the xbmc shutdown action assigned to power button with a script which checks if the box was just woken up and prevents immediate sleep loop. This is where I need help

- Is there a smart way to find out programatically if the box just woke up?
- I could use the sleep.d script option which runs after wake up. What is the most simple way to share information between two scripts? (Set a flag by sleep.d script and check by the shutdown script)
One solution could be to specific different remote buttons for sleep and wake up.

What might also help is....

create a "sleep.d" folder in your ".config"-folder: mkdir -p /storage/.config/sleep.d

Inside that folder create a file which might be called "01-wakeup.power" (the "01-" and the ".power" is important, everything in between can be named different) and create an individual script which has probably something like this in it:

Code:
!/bin/sh
   case "$1" in
     pre)
     ;;
     post)
     sleep 5
     ;;
   esac

That will stall your system for 5 seconds after wakeup. "pre" is before suspend. "post" is after wakup.
Thanks for your response. You clearly understood my issue.
My first approach was also a separate on/off button. It works fine, however there is a need to control the system with an universal remote (switch on/off everything at once) where I had problem with setting them as a macro.

Regarding the script you suggested, it would be the most simple solution, but I am afraid that it actually won't delay the wake up. I assume the script is executed paralel.