So I've managed to make a script that does a reasonable job of putting the system to sleep when it isn't needed.
It means rather than being on 24/7 it's only on about 6 hours a day.
I've used the exact 95_timer.sh from here - https://tvheadend.org/projects/tvheadend/wiki/Wakeup
For the 99_htpc.sh detailed in the Wakeup page on the wiki I have tweaked it slightly due to different DVB cards and the system in question being a standalone TVH server with no XBMC etc.
I have a TBS 6981 and two TBS 8920s. Not totally sure if I need to unload and load all these modules but it does the job.
#!/bin/sh
case "$1" in
suspend|hibernate)
/etc/init.d/tvheadend stop
rmmod cx88_dvb
rmmod cx8802
rmmod cx8800
rmmod cx25840
rmmod cx23885
rmmod cx2341x
;;
resume|thaw)
modprobe cx88_dvb
modprobe cx8802
modprobe cx8800
modprobe cx25840
modprobe cx23885
modprobe cx2341x
sleep 1
/etc/init.d/tvheadend start
;;
esac
To put the system to sleep I have the following (edited) script running as a cron job every 10 mins.
It can obviously be improved but so far it works fairly well.
#!/bin/sh
#
rm -rf /tmp/tvhsleep
mkdir -p /tmp/tvhsleep
cd /tmp/tvhsleep
wget -q --user=tv --password=tv http://127.0.0.1:9981/status.xml
subs="`cat status.xml | grep -i subs | grep -o "[0-9]"`"
recn="`cat status.xml | grep -i next | grep -Eo '[0-9]{1,9}'`"
rm status.xml
# Checks if HTPC is online.
if ping -c 1 -w 1 xxx.xxx.xxx.xxx
then
echo "htpc online"
echo "Stay Awake"
exit
else
echo "htpc offline"
:
fi
# Check for any subscriptions
if [ "$subs" -gt 0 ]
then
echo $subs "subscriptions"
echo "Stay Awake"
exit
elif [ "$subs" -eq 0 ]
then
echo "No subs - check DVR"
:
fi
# Check pending recordings
if [ -z "$recn" ]
then
echo "No recs scheduled"
echo "sleep"
/usr/sbin/pm-suspend
elif [ "$recn" -lt 10 ]
then
echo "Next rec less than 10 mins"
echo "Stay Awake"
exit
else
echo "Next rec more than 10 mins"
echo "sleep"
/usr/sbin/pm-suspend
fi
The structure/idea might be useful to someone!
To wake the system I have my OpenELEC HTPCs sending a WOL packet on boot.