Script: Myth Suspend Alarm
What it does: Sets an ACPI alarm based on the next scheduled MythTV recording and suspends the machine. I don't use the MythTV frontend, nor do I use MythWelcome. I needed a script that not only checked what MythTV was doing, but also whether XBMC was active.
Who might want to use it: Anyone running a MythTV backend on the same machine as the XBMC frontend (may just be me...).
Legal bit: I make no guarantees that this script won't harm your system, so if it does, don't come running to me as I accept no liability. It works for me. That's all I can guarantee.
How it works:
The script performs a series of tests and, if all are passed, sets an ACPI and suspends/hibernates the machine.
The tests are as follows:
- Get MythTV backend status and check if recording/transcoding/running user jobs etc
- Check if XBMC has any active players
- Check if there are any active sessions e.g. ssh
Tested on: Dharma
How to use:
(I'll be honest, there's a bit of effort needed on the user's part! But the idea is once it's working, you can forget all about it.)
Unzip the script folder to your addons folder.
There are 2 bash scripts which need to be configured so the script can use them:
setwakealarm: this sets the ACPI alarm. It needs to be executable and, more importantly, able to run as sudo without a password (so you'll need to edit the sudoers file to do this).
mythshutdownstatus: this script outputs the status code (to stdout) of the "mythshutdown -s" command. Again, make sure this script is executable.
Ok, that's the easy bit.
You now need to figure out what your motherboard needs to do to use the ACPI alarm. This is out of the scope of my plugin, but I found the steps on this page http://www.mythtv.org/wiki/ACPI_Wakeup very helpful.
The key thing for the script is to know whether the ACPI alarm needed is a UTC time, or an incremental time (e.g. +600 for an alarm 10 minutes from now). You may need to experiment on the command line first.
NB: you should also test whether your backend is able to record after waking from suspend (see here for my fix: http://ubuntuforums.org/showpost.php?p=1...stcount=18)
You may also want to consider setting up your system to wake from your remote.
Once you've got ACPI suspend/wake working outside of xbmc you can configure the script.
Restart xbmc. The script should appear in addons menu.
The first time you use it, you must configure the script first - the important settings are the paths to the two scripts above and the mythtv database settings.
Once that's done you can try running the script.
The script can be run as a cron job e.g. by putting the following line in your crontab file:
0 * * * * xbmc-send -a "RunScript(script.mythsuspendalarm, cron)"
This is version 0.1 so there are bound to be bugs, so all comments bug reports are welcome. However, I'm not a python developer (this is the first python code I ever wrote) so I don't guarantee I can fix the problems!!