First of all I want to thank the LibreELEC developers for their great work.
Maybe I can contribute a little bit with this thread.
I am using LibreELEC 9.0.2 (LibreELEC-Generic.x86_64-9.0.2.img.gz) at home in a client/server structure, which is working pretty fine.
There are only small things (for my special purpose) I couldn't achieve with the available settings and scripts. Maybe I just didn't find the right documentation about it.
One PC is running the TvHeadend Server and is doing all the recordings. To use the least amount of power I wanted to have this server to shutdown automatically and wakeup, if a client requests (wake on LAN) it or if there is a upcoming recording or if it is time to update EPG data.
Following things worked out of the box:
Here are the things that didn't work out of the box:
- Stay awake, if a remote TvHeadend client is connected
- Automatic wakeup for recording or EPG update (even with activated PVR Recording & Power Manger)
For the first point I found part of the solution in the LibreELEC Wiki (Useful shell scripts [LibreELEC.wiki]). I adapted the "Prevent Idle Shutdown" prevent_idle_shutdown.sh to check for remote TvHeadend connections. The local TvHeadend connections are ignored (otherwise it would keep the server always running).
To start the script on LibreELEC startup you have to create/adapt the autostart.sh (Autostart.sh [LibreELEC.wiki]).
nohup /storage/.config/prevent_idle_shutdown.sh &
#/bin/sh
# debug (0 = no debug, 1 = low debug, 2 = high debug)
debug=0
IDLE_SHUTDOWN_ALLOWED_LAST_STATE=-1
while true
do
KODI_RUNNING=`ps -A | grep kodi.bin | grep -v grep | wc -l`
if [ 1 == $KODI_RUNNING ] ; then
SSH_ACTIVE=`netstat -tnpa | grep 'tcp.*:22.*ESTABLISHED.*' | wc -l`
NFS_ACTIVE=`netstat -tnpa | grep 'tcp.*:111.*ESTABLISHED.*' | wc -l`
SMB_ACTIVE=`netstat -tnpa | grep 'tcp.*:445.*ESTABLISHED.*' | wc -l`
TVH_9981_ACTIVE=`netstat -tnpa | grep 'tcp.*:9981.*ESTABLISHED.*' | grep -v 127.0.0.1 | wc -l`
TVH_9982_ACTIVE=`netstat -tnpa | grep 'tcp.*:9982.*ESTABLISHED.*' | grep -v 127.0.0.1 | wc -l`
TVH_ACTIVE=$((TVH_9981_ACTIVE + TVH_9982_ACTIVE))
# debug
if [ "$debug" -eq 2 ]; then
echo "SSH_ACTIVE $SSH_ACTIVE NFS_ACTIVE $NFS_ACTIVE SMB_ACTIVE $SMB_ACTIVE TVH_ACTIVE $TVH_ACTIVE"
fi
[ $SSH_ACTIVE -gt 0 -o $NFS_ACTIVE -gt 0 -o $SMB_ACTIVE -gt 0 -o $TVH_ACTIVE -gt 0 ] && IDLE_SHUTDOWN_ALLOWED=1 || IDLE_SHUTDOWN_ALLOWED=0
if [ $IDLE_SHUTDOWN_ALLOWED_LAST_STATE != $IDLE_SHUTDOWN_ALLOWED ] ; then
IDLE_SHUTDOWN_ALLOWED_LAST_STATE=$IDLE_SHUTDOWN_ALLOWED
# debug
if [ "$debug" -eq 1 -o "$debug" -eq 2 ]; then
echo "kodi-send --action=\"AllowIdleShutdown\""
fi
kodi-send --action="AllowIdleShutdown"
if [ 0 == $IDLE_SHUTDOWN_ALLOWED ] ; then
# debug
if [ "$debug" -eq 1 -o "$debug" -eq 2 ]; then
echo "kodi-send --action=\"InhibitIdleShutdown(false)\""
fi
kodi-send --action="InhibitIdleShutdown(false)"
else
# debug
if [ "$debug" -eq 1 -o "$debug" -eq 2 ]; then
echo "kodi-send --action=\"InhibitIdleShutdown(true)\""
fi
kodi-send --action="InhibitIdleShutdown(true)"
fi
fi
fi
sleep 60
done
Display More
The second point was a little bit more work, but a part of the solution can be again found in the LibreELEC Wiki (Autostart.sh [LibreELEC.wiki]).
A script has to be executed on shutdown, that is setting the wakup time for the next recording or for the EPG update, depending on which comes first. So you have to create/adapt the shutdown.sh to call the script tvh_wakeup.sh.
case "$1" in
halt)
# your commands here
/storage/.config/tvh_wakeup.sh
;;
poweroff)
# your commands here
/storage/.config/tvh_wakeup.sh
;;
reboot)
# your commands here
;;
*)
# your commands here
;;
esac
Display More
#!/bin/bash
# set ACPI Wakeup alarm
# safe_margin - minutes to start up system before the earliest timer
# script does not check if recording is in progress
echo 1 > /storage/timer
# debug (0 = no debug, 1 = low debug, 2 = high debug)
debug=0
# bootup system 120 sec. (boot time) + 180 sec. before timer
safe_margin=300
# daily wakeup at time HH:MM
daily_wakeup=04:30
# modify if different location for tvheadend dvr/log path
cd /storage/.kodi/userdata/addon_data/service.tvheadend42/dvr/log/
######################
start_date=0
stop_date=0
current_date=`date +%s`
#debug
if [ "$debug" -eq 2 ]; then
echo "current_date" $current_date
fi
for i in $( ls ); do
enabled=`cat $i | grep -m 1 '"enabled":' | cut -f 2 -d " " | cut -f 1 -d ","`
tmp_start=`cat $i | grep -m 1 '"start":' | cut -f 2 -d " " | cut -f 1 -d ","`
tmp_stop=`cat $i | grep -m 1 '"stop":' | cut -f 2 -d " " | cut -f 1 -d ","`
#debug
if [ "$debug" -eq 2 ]; then
echo "enabled" $enabled
echo "tmp_start" $tmp_start
echo "tmp_stop" $tmp_stop
fi
# check for outdated timer
if [ "$enabled" = "true" -a "$((tmp_stop))" -gt "$((current_date))" -a "$((tmp_start))" -gt "$((current_date))" ]; then
# take lower value (tmp_start or start_date)
if [ "$((start_date))" -eq 0 -o "$((tmp_start))" -lt "$((start_date))" ]; then
start_date="$tmp_start"
stop_date="$tmp_stop"
fi
fi
done
wake_date="$((start_date-safe_margin))"
# Check whether daily wakeup time is today or tomorrow
daily_wake_date="$((`date +%s -d "$daily_wakeup"`))"
if [ "$((daily_wakeup_date))" -lt "$((`date +%s`))" ]; then
daily_wake_date="$((`date +%s -d "$daily_wakeup"` + 24*60*60))"
fi
#debug
if [ "$debug" -eq 1 -o "$debug" -eq 2 ]; then
echo "current_date" $current_date
echo "daily_wake_date" $daily_wake_date "in about" $(((daily_wake_date-current_date)/3600)) "hours"
echo "timer wake_date" $wake_date "in about" $(((wake_date-current_date)/3600)) "hours"
fi
# take lower value (daily_wake_date or wake_date)
if [ $((start_date)) -eq 0 -o $((daily_wake_date)) -lt $((wake_date)) ]; then
wake_date=$daily_wake_date
fi
#debug
if [ "$debug" -eq 1 -o "$debug" -eq 2 ]; then
echo "used wake_date" $wake_date "in about" $(((wake_date-current_date)/3600)) "hours"
fi
echo $start_date >> /storage/timer
echo $wake_date >> /storage/timer
# set up waleup alarm
if [ $((start_date)) -ne 0 ]; then
echo 2 >> /storage/timer
echo 0 > /sys/class/rtc/rtc0/wakealarm
echo $wake_date > /sys/class/rtc/rtc0/wakealarm
fi
Display More
All scripts have to be stored in folder /storage/.config.
I had to change the tvh_wakeup.sh script to work called from shutdown.sh, as TvHeadend server is already down at that time. The new script now checks the log folder for recordings and you don't need access to TvHeadend website.
Also look at safe_margin, which is the boot time of your system in seconds and to daily_wakeup, which is the time for the EPG update.
Maybe there is someone who knows how to setup LibreELEC to fulfill my requirements without additional scripts. Any ideas?
Otherwise I am happy to give something back to the LibreELEC community with my adapted scripts. They have been tested only on LibreELEC 9.0.2 Generic X86 (AMD / Intel / Nvidia).
For a more generic approach you could use setwakeup.sh $wakeup instead of the last 2 lines in tvh_wakeup.sh.