TvHeadend Server with Automatic Shutdown and WakeUp with remote TvHeadend Client

  • First of all I want to thank the LibreELEC developers for their great work. :thumbup:

    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:

    1. Stay awake, if a remote TvHeadend client is connected
    2. 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]).

    Bash: autostart.sh
    nohup /storage/.config/prevent_idle_shutdown.sh &

    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.

    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.

    Edited once, last by relaxx (August 8, 2019 at 5:43 PM).

  • Here are the things that didn't work out of the box:
    1. Stay awake, if a remote TvHeadend client is connected
    2. Automatic wakeup for recording or EPG update (even with activated PVR Recording & Power Manger)

    Finally I found my missing piece by reading a longer thread: [RELEASE] PVR Recording & Power Manager - Addon releases - Kodinerds.net - Deutschsprachiges Forum zum Kodi Entertainment Center

    The PVR Recording & Power Manager is independent of other addons or kodi functions, but it deactivates itself after user activity or after waking up (e.g. from WOL) without a recording in near future. I have been missing this piece of information.

    You can make everything work without all my scripts. You just need 2 addons:

    • PVR Recording & Power Manger (or TvHeadend Recording & Power Manager)
    • Sleepy Watchdog

    The internal idle timeout does not work, as you need to call service.pvr.manager,poweroff instead of a normal shutdown. This makes sure that wakeup time is set independent of the wakeup reason.

    To call service.pvr.manager,poweroff you can use the Sleepy Watchdog Addon.