The solution to this is simple. First, upon suspend and resume, the pm-suspend program executes a series of scripts in
/usr/lib/pm-utils/sleep.d. So my solution is to add a script that does the following:
- Upon suspend, record the current time and register a wakeup event using rtcwake.
- Upon resume,check the current time against the recorded time from above. If enough time has elapsed, then we probably woke up due to the rtc timer event. Otherwise we woke up early due to a user event (such as opening the laptop screen).
- If we woke up due to the rtc timer, then immediately issue a "pm-hibernate" command to go into hibernation.
Here is a script that does this. Name it
0000rtchibernate and place it in the
/etc/pm/sleep.d directory (the 0000 is important, so that the script executes first on suspend, and last on resume).
# Script name: /etc/pm/sleep.d/0000rtchibernate
# Purpose: Auto hibernates after a period of sleep
# Edit the "autohibernate" variable below to set the number of seconds to sleep.
echo "$curtime $1" >>/tmp/autohibernate.log
if [ "$1" = "suspend" ]
# Suspending. Record current time, and set a wake up timer.
echo "$curtime" >/var/run/pm-utils/locks/rtchibernate.lock
rtcwake -m no -s $autohibernate
if [ "$1" = "resume" ]
# Coming out of sleep
# Did we wake up due to the rtc timer above?
if [ $(($curtime - $sustime)) -ge $autohibernate ]
# Then hibernate
# Otherwise cancel the rtc timer and wake up normally.
rtcwake -m no -s 1
Hopefully this code comes through on this message board (this is my first post here).
Edit the timeout value "autohibernate=7200" at the top, to however many seconds you which to sleep before going into hibernation. The current value above is 2 hours. Note, that you laptop WILL wake up at that time for a few seconds, while it is executing the hibernate function.
So if you plan on putting your laptop in a case, don't suspend, but hibernate instead. Otherwise your laptop could overheat in esp. if it is in a tight fitting slip case (although it will only be on for a few seconds to a minute).
I've been using this method for the past couple of days, so far it has been successful (and saved me from a dead battery this afternoon). Enjoy.