the acpi wiki's tends to be difficult to follow in places as they cater for multiple scenario's mostly at older versions. Here is my attempt at a HOW-TO for mythbuntu 9.04
- mythbuntu 9.04
- front end and back end on same machine
- bios clock using UTC (not local time)
What to expect
At completion of this how-to your system should suspend after the machine idle for predetermined period, it will shutdown. When it is time to do something, the machine will automatically restart and perform the activity required. Once complete and idle once more it will shutdown. The automatic shutdown can be overiden enabling the user uninterupted viewing.
How it works
Mythbackend is running and monitors activity. If it is idle for predetermined timeframe it will run a command mythshutdown with various switches and parameters.
In summary if idle it runs the following commands.
mythshutdown --check (this checks for activity). If a user is logged in, it will prevent shutdown by returning 1; if OK to shutdown will return a 0 (same as exit 0)
mythshutdown --settime $time (this stores the time for next wakeup, it does not write to bios h/w clock )
mythshutdown --shutdown (this triggers a script that sets time to wakeup in bios h/w clock and then shutdown/power off the computer)
When you boot the machine, the mythwelcome screen will be displaye. The mythwelcome program monitors activity and displays status of the backend. If the machine is idle for a preset time (noted by a countdown in mythwelcome, it will automatically shutdown the computer)
If whilst mythwecome is running, the user presses select/enter on remote/keyboard, the mythfrontend application will be started enabling the user to watch tv etc. If the mythfrontend is running, the machine will prevented from shutting down. To enable automatic shutdown/wake capability, the user must return to the mythwelcome screen by entering stop/end. THIS IS IMPORTANT!
STEP 1 - check bios clock is UTC
to check if bios clock is running UTC, start a command line session, then
the rtc_time should be a UTC time
STEP 2 - create MythWakeSet script
The cut and paste following code (taken from acpi wake page https://help.ubuntu.com/community/My...tNext/ACPIWake)
sudo apt-get install gedit
Note: if you have gedit installed already, there is no need to reinstall it; if you are not sure type gedit to determine if it installed.
save the script
# inspired from http://www.mythtv.org/wiki/index.php/ACPI_Wakeup
# and https://help.ubuntu.com/community/MythTV/Install/WhatNext/ACPIWake
# set mythtv wake-up time with UTC-adjusted time
# use: MythWakeSet date time
# ex.: MythWakeSet 2008-11-02 20:15:00
# See also 'man date' for date/time-formats.
# TimeZone, use +0100 for GMT+1
DATE=$(date -d "$1 $2 $TZ" "+%F %H:%M:%S" -u)
SECS=$(date -d "$1 $2" "+%s")
echo Running $0 to set the wakeup time to $1 $2 >>$LOG
if [ -e /sys/class/rtc/rtc0/wakealarm ]; then
echo 0 > /sys/class/rtc/rtc0/wakealarm
echo $SECS > /sys/class/rtc/rtc0/wakealarm
echo "echo 0 > /sys/class/rtc/rtc0/wakealarm" >>$LOG
echo "echo $SECS > /sys/class/rtc/rtc0/wakealarm" >>$LOG
cat /proc/driver/rtc >>$LOG
if [ -e /proc/acpi/alarm ]; then
echo $DATE > /proc/acpi/alarm
echo "echo $DATE > /proc/acpi/alarm" >>$LOG
echo "ERROR, Wakeup not set, no /sys/class/rtc/rtc0/wakealarm and no /proc/acpi/alarm found" >>$LOG
now make the script executable and put it in /usr/bin
Brief explanation of script: the scripts takes the time in yyyy-MM-dd hh:mm:ss and converts it secs since 19.. in UTC. It then writes the time to bios hw clock (not sure). This done by echo $SECS > /sys/class/rtc/rtc0/wakealarm command. The /prco/acpi/alarm is legacy and is not used in 9.04.
$ chmod +x MythWakeSet
$ sudo cp MythWakeSet /usr/bin
STEP 3 - configure backend to sleep/wake
Stop the backend and setup
Proceed to general>Shutdown/Wakeup Options
$ sudo /etc/init.d/mythtv-backend stop
untick Block shutdown before client connected
Set idle shutdown timeout (secs): 120
Set Max. wait for recordings (min): 15
Set Startup before rec (secs): 200
Set Wakeup time format: yyyy-MM-dd hh:mm:ss
Set Command to set Wakeup Time: sudo -H mythshutdown --setwakeup "$time"
Set Server Halt command: sudo -H mythshutdown --shutdown
Set pre shutdown check-command: mythshutdown --check
Note: if you are using EIT; you need to set the idle time to less that 5 minutes. If set longer, the EIT scan will interupt the idle time and it will never expire and hence the box will not shut down. In have set it to 120 secs here.
STEP 4 - get mythwelcome to run a startup
Now you need to get mythwelcome working
modify line from
$sudo cp /etc/mythtv/session-settings /etc/mythtv/session-settings.old
$sudo gedit /etc/mythtv/session-settings
save the file
STEP 5 - configure mythwelcome
run setup for mythwelcome
update the setup page as follows:
set nvram-wakeup Command: sudo -H /usr/bin/MythWakeSet "$time"
set nvram-wakeup Restart Command: leave blank!
set Command to reboot: sudo -H shutdown -h -r now
set Command to shutdown: sudo -H shutdown -h -P now
exit mythwelcome setup.
STEP 6 - get everything working
reboot system by
now the system will start with mythwelcome then load mythfrontend.
STEP 7 - prevent mythfrontend from starting on restart
To prevent frontend from starting at next reboot, exit mythfrontend and return to mythwelcome.
Prior to doing this step. You may need lock the system by selecting "m" on the keyboard and selecting lock shutdown. This will prevent the machine from shutting down whilst you are within mythwelcome. Remember to unlock after you are finished otherwise the machine will never shutdown.
Hit "i" on keyboard and untick Automatically Start Myth Frontend. This will prevent mythfrontend from starting next time you reboot
STEP 8 - TEST
Now to test
reboot as before
you should be at the mythwelcome screen
hit select/enter on remote/keyboard to start mythfrontend and schedule a program to record about 30 minutes in the future (not less the 15 minutes).
now return to mythwelcome by pressing stop/Esc button few times
the machine should automatically shutdown in approximately 2 minutes (see count down). If mythwelecome indicates that there are jobs in the queue being processed, it will not shutdown until jobs are complete. You will need to perform a retest after the jobs are completed.
Aproximately 2 minutes prior to the time, the machine should restart and start mythwelcome. The machine should record and on completion and idle, it will shutdown.
Note: you can prevent shutdown at any time by starting mythfrontend within 2 minutes of boot from mythwelcome. But to recommence shutdown, you must return to mythwelcome.
Hope this helps.
This information was taken from a number of sources including
a more detailed explanation can be at these sites.
Note: I had an issue with frontend starting before the backend was ready. For solution see this: