In Ubuntu 18.04 LTS and above suspend-then-hibernate
works similarly
In this mode laptop sleeps or suspends to RAM when the lid is closed or a button is pressed. After a certain time that has been pre-set, the laptop will wake up and write the data in RAM to disk, and enter hibernate mode.
The advantage is, the laptop suspends (sleeps) more quickly when close the lid. If you wake it up before the pre-set time it resumes quickly as well. If you don't wake the it up before the pre-set time it automatically saves battery in hibernate mode shut-down.
In Ubuntu 17.10 and below hybrid-sleep
was the closest
In this mode the data in RAM is written to disk for hibernating before the laptop entered sleep (also known as suspend) mode. If the battery gets critically low while sleeping, the laptop goes into hibernation before turning off power, so the data in RAM is not lost.
In case the battery is drained out while the laptop was in hybrid sleep mode, plugging it into the power socket and powering it up will bring it back to the state when the lid was closed to put the laptop to sleep.
See What is hybrid suspend for some more explanations.
From the Ubuntu manpage on systemd power-saving mode:
systemd supports four general power-saving modes:
suspend
a low-power state where execution of the OS is paused, and complete power loss might
result in lost data, and which is fast to enter and exit. This corresponds to suspend,
standby, or freeze states as understood by the kernel.
hibernate
a low-power state where execution of the OS is paused, and complete power loss does
not result in lost data, and which might be slow to enter and exit. This corresponds
to the hibernation as understood by the kernel.
hybrid-sleep
a low-power state where execution of the OS is paused, which might be slow to enter,
and on complete power loss does not result in lost data but might be slower to exit in
that case. This mode is called suspend-to-both by the kernel.
suspend-then-hibernate
A low power state where the system is initially suspended (the state is stored in
RAM). If not interrupted within the delay specified by HibernateDelaySec=, the system
will be woken using an RTC alarm and hibernated (the state is then stored on disk).
Settings in these files determine what strings will be written to /sys/power/disk and
/sys/power/state by systemd-sleep(8) when systemd(1) attempts to suspend or hibernate the
machine.
See this answer if you want to enable either suspend-then-hibernate
or hybrid-sleep
in your Ubuntu laptop.
Hope this helps.
Best Answer
1.Basic alarm clock function
Entering suspend mode
for this solution, you need to enter suspend mode by running the script below. It makes the computer go into suspend mode and wakes you up at a (clock-) time, defined by you (in the script). playing your song.
Of course you can simply run the script manually to use it, but it is more convenient to make it available via a key combination, set in
System Settings > Keyboard > Shortcuts > Custom Shortcuts
.Set up
Paste the script below in an empty file, set the wake up (clock) time (in 1-24 hours, 1-60 minutes), set the path to your wake up song, and save it as
wakeup.py
.make the script executable
Set a key combination to run the script; open
System Preferences > Keyboard > Shortcuts > Custom Shortcuts
, add the commandand choose a key combination
The script needs administrator's privileges. To run it without having to enter the password, open the sudoers file:
add the line to the very bottom of the file:
Note that the sudoers file is an essential file; errors in the file possibly lead to serious problems, so be careful!
N.B.
gksu
:sudo apt-get install gksu
. In that case, the command to run the script isgksu /path/to/wakeup.py
, and you will be prompted for your password each time you run it.Now you can enter suspend mode with your key combination and you'll get woken by your wake up song.
2.Extended version including stop function when (any) key or mouse is hit
The differences between this one and the "basic" version is that in this one the alarm stops when any keystroke or mouse movement is detected (more convenient than stopping Rhythmbox on the computer when you just woke up), and that the alarm automatically exits after a defined period of time.
The setup is pretty much the same as the basic version, but
xprintidle
needs to be installed, to detect keystroke- or mouse movement events:The script:
Explanation
rtcwake
Both scripts are written around the
rtcwake
command, as explained here. The command can be used to put the computer into suspend and wake up after a defined amount of time (and optionally run a command after wake up). The-m disk
option is used, since OP mentioned his computer does not support "suspend to RAM" feature in BIOS. See alsoman rtcwake
.The stop function
The stop function works by a function that measures idle time every second while the song is playing, and remembers the last idle time. IF the last idle time exceeds the current one, it means a keystroke or mouse event has taken place, and Rhythmbox is killed.