MythTV is a Linux-based roll-your-own Tivo, and will probably be a major topic in this here blog.
I recently upgraded to version 0.21, and had a dickens of a time getting automatic wakeup/shutdown working. The problem is typical of linuxy things: there are many poorly described options, some of which seem to be redundant but interact in subtle and nefarious ways. Plus, while there is a huge amount of documentation online, a lot of it is contradictory or only applicable to specific (but often unstated) setups.
With that latter datum in mind: this is for Myth-0.21, and I am using ACPI for wakeup/shutdown, rather than NVRAM. Okay? Okay.
Step the First: Make sure acpi works on your machine
- Find out what timezone your BIOS clock is using. There are ways to find out from within linux, but let's go straight down to the metal and ask the BIOS. So, reboot your box (bye-bye uptime!), and press Del or whatever to get into the BIOS. Check the clock time; hopefully it's either your local time or UTC. Make a note of it.
- Boot into linux. If myth starts automatically, get out of it (keep pressing Esc until it asks if you're sure you want to exit...if that gets you the mythwelcome screen, press "M", then select Exit from the menu). At this point you should be in a desktop session of some kind.
- Attempt a manual ACPI wakeup. I'm going to assume that your kernel has ACPI stuff set up already, so if this step fails you may need to do some kernel recompilin' (hooray!). Open a terminal. We want to send the BIOS a message to boot the machine in about five minutes from now, so query the current time by typing
date, or date -u if your BIOS clock uses UTC. Then, we just need to write a time string set for five minutes from now into a particular file. For example, say that date -u returns "Wed Jan 28 12:35:42 2009". In that case, we would next type the following: echo "2009-01-28 12:41:00" > /proc/acpi/alarm. You should, of course modify the time string.
Next, shutdown the machine. Quickly now, you only have 5 minutes! sudo shutdown -h now should do the trick. Wait five minutes. The machine should power on all by itself! Spooky! If it doesn't...like I said, you could be in for some serious tweaking. Google around for more detailed docu.
Step the Second: Configure MythTV
All right, we've verified that ACPI works and the system can auto-boot given a properly-formatted timestamp sent to /proc/acpi/alarm. Next, we will set up MythTV to enable auto wakeup/shutdown.
In an ideal world, the MythTV configuration for auto wakeup/shutdown would simply be a checkbox, tagged with the simple query "Would you like MythTV to automatically shutdown when idle and wakeup when it's time to record?". This is evidently not an ideal world, so prepare yourself for something rather more labyrinthine...
First of all, get out of MythTV if it's running. Just keep pressing "Esc" until it asks if you want to exit, then select "Yes"! If that gets you to mythwelcome, press "m", then select "Exit" from the menu. You should now be looking at a desktop session of some kind. Before we begin, kill the backend program by typing sudo /etc/init.d/mythtv-backend stop.
There are two screens full of options that you'll need to tweak. The first is in the backend config tool. Open an xterm (on KnoppMyth, you right-click the desktop, then select "XShells", "xterm". Since the default font is unreadable on a TV, I usually Ctrl-right-click on the xterm and select the "Huge" font). Now type mythtv-setup in the xterm to invoke the config tool. Select "General" from the menu, then skip to page 5 (press Enter 4 times). Make it look like this:

In particular:
- Startup command:
/usr/bin/mythwelcome
- Block shutdown before client connected: checked
- Wakeup time format:
yyyy-MM-ddThh:mm:ss
- Command to set Wakeup Time:
sudo mythshutdown --setwakeup $time
- Server halt command:
sudo mythshutdown --shutdown
- Pre Shutdown check-command:
sudo mythshutdown --check
Set the time intervals to whatever you're comfortable with. I should probably change my "Max. wait for recording" to 30 minutes, because a 30-minute gap between recordings is relatively common. After you're done here, page through the rest of the config's many, many pages until you reach the Finish button (hooray!)
The next step is to run mythwelcome --setup. This tool is thankfully, only one page. Make it look like this:

That first line is truncated in the screenshot. In full, it reads:
sudo /usr/local/bin/convert_utc.sh $time; sleep 1; sudo /usr/local/bin/convert_utc.sh $time
This is an ugly belt-and-suspenders redundancy just to make sure that the convert_utc.sh script does its thing before the shutdown process begins. It would probably be more elegant to add the sleep 1 command to the script itself. (Note to self: do that!)
The other parameters are pretty straightforward. The "Command to shutdown" parameter is a useful place for some kung-fu if you need to diagnose shutdown problems. Just replace that command with killall mythwelcome and instead of shutting down, you'll simply get booted back to your desktop where you can check logs or console output (assuming you had started mythwelcome from an xterm). Pretty useful!
Step the Third: write convert_utc.sh
The convert_utc.sh script just takes the wakeup time string sent from MythTV (in Local time format), converts it to UTC, reformats it, and writes it to /proc/acpi/alarm. Here is my convert_utc.sh:
#!/bin/bash
stamp_file=/tmp/timestamp
#echo $1\ $2 > $stamp_file
echo $1 | sed "s/T/ /" > $stamp_file
# Add TZ info to the timestamp
datum=$(/bin/date -f $stamp_file +%F\ %T\ %z)
echo $datum > $stamp_file
#Express as UTC time
utcdatum=$(/bin/date -u -f $stamp_file +%F\ %T)
#uncomment for testing
#echo $utcdatum > $stamp_file
#uncomment to commit to /proc/acpi/alarm:
rm -f $stamp_file
echo $utcdatum > /proc/acpi/alarm
echo $utcdatum
Step the Fourth: Test Drive
Restart the backend (in an xterm or virtual terminal, type: sudo /etc/init.d/mythtv-backend restart). Next, type mythwelcome to start MythTV. Navigate to "Manage Recordings", "Schedule Recordings", "Program Guide", and pick something to record that's going to start relatively soon (but not too soon: if it starts within the "Max wait for recording" time interval, then MythTV will refuse to shutdown...for this reason, it's a good idea to keep Max-wait short while debuigging things). After clicking on the desired program, you get an extensive menu of recording/storage options. Set the program to record, then be sure to select "Save these settings". You should see an icon in the Program guide indicating that MythTV will record that program. Then exit MythTV (keep pressing Esc until you see the "Are you sure you want to exit???" question).
You should now see the mythwelcome screen, with status messages telling you that the system is currently idle, and that your selected program is the next thing to be recorded. You should see the idle timer counting down to trigger the ssytem shutdown. You can either let the timer run down, or press "m" to get a menu and select "shutdown now" from the menu. Hopefully, in either case your system will then shut itself off.
Now comes the real nail-biter. Will your system wake itself up to record the selected program? The wakeup time is controlled by the "startup before rec" option in mythtv-setup. So if that was set to 600 sec, then 10 minutes prior to the recording time, your computer should boot itself. Go grab yourself a sandwich, read a book, take a walk, ponder your existence, whatever. At the appointed time, you will hopefully hear the beeps and whirrs of your system waking up!
Step the Fifth: What if it doesn't work?
TBCompleted...