12 March 2011

Wake up alarm on Linux.


--- Ubuntu 9.10

I wanted to put the computer on standby when I go bed and wake up with music in the morning.

I read about plugins for xmms, amarok, python scripts, and bash scripts.

Some people were using the node  .../.../wakealarm to set up the computer wake up time.


The best solution I found is to use rtcwake and alarm-clock. The first to resume the computer from standby. The second to run anything you want whenever you want.

Examples:                   
                   
# sudo rtcwake --verbose --mode standby --time `date +%s --date "2011-01-11 07:30"`
# sudo rtcwake --verbose --mode standby --time `date +%s --date "tomorrow  07:30"`

The  rtcwake command is part of the util-linux-ng package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.

Then use alarm-clock program to run the task you want.

That worked fine in Ubuntu, but not on my Debian computer.



--- Debian

Since the rtcwake didn't work well on my Debian, I had to find another solution.

I also found out that better than having two tasks to wake up at different times was to leave the music playing when I put the computer to sleep. When it wakes up the music would simply continue.

So this is the process (line) to make the computer wake up (as root):

## ensure that the permissions are correct; clean up anything previous ; insert wake up time; go to sleep;
# chmod 666 /sys/class/rtc/rtc0/wakealarm ;  echo 0 > /sys/class/rtc/rtc0/wakealarm;   echo `date -d "tomorrow 6:56" +%s` > /sys/class/rtc/rtc0/wakealarm ; pm-suspend


I find (up arrow key) and enter it when I go bed, and in the morning, since I have the screen off, I just do the same process again (up + Enter) when leaving home. I just use the music for some minutes.


I also did an script to raise the volume and then set it to medium-high, but at the end I just set up the volume before running the line and forget about the script.

In any case, here it is:

==============================
#!/bin/bash

# ------- Tasks -----------------------------------
# start playing music
kaffeine --play /your/play/list &

# set and increase volume repeatedly
SLEEPX="4";
for i in $(seq 40 85); do echo $i; VV="$i%"; aumix -v $VV -l $VV -p $VV -w $VV -W $VV; sleep $SLEEPX ; done;

# change volume to something normal
sleep 10; VV="75%"; aumix -v $VV -l $VV -p $VV -w $VV -W $VV
==============================


Hope it helps to anyone looking to have less devices on the room, while saving energy/noise and having a pleasant wake up.

1 Comments:

Anonymous Anonymous said...

And this is the version with music after waking up.

sleep 3; chmod 666 /sys/class/rtc/rtc0/wakealarm ; echo 0 > /sys/class/rtc/rtc0/wakealarm; echo `date -d "tomorrow 7:02" +%s` > /sys/class/rtc/rtc0/wakealarm ; pm-suspend; sleep 10 ; mplayer-playlist http://inbeatradio.com/ibrhouse.pls


You can change the radio stream for anyone you like. I use to take them from shoutcast.com

The second sleep is needed so the playing doesn't start immediately after the suspend, which would break the player next morning as it would have to refill the buffer.

This still allows me to quit the player and launch the script again without needing to power on the monitor/screen. So I enjoy some music in the morning and then put it to sleep again. The sequence of keys is: q, up, enter.

7:27 pm  

Post a Comment

<< Home

Too Cool for Internet Explorer