Shutdown scripts for LibreELEC and OpenELEC


Note : If you prefer the instructions for OpenElec in German language you can find a review and detailed installation instructions here.

The default SSH user name is root, password openelec (password for LibreELEC is libreelec).

The first part of the instructions below adds the main shutdown script for the RemotePi Board to the autostart.sh file, which enables the script to run when the OS starts.

  • Key in (mind the . in front of config !) :
    cd .config
    nano autostart.sh

  • Copy and paste (use shift+ins to paste in nano) the following into the nano editor window. If there is already something in the file, just add the following as the last lines. If the last line is exit 0, then place the following lines before that line.
    #!/bin/bash
    (/storage/.config/irswitch.sh)&
  • Press ctrl+x to exit the editor, y to confirm, enter to save the file
  • Key in
    chmod +x autostart.sh

The next part creates the main RemotePi Board shutdown script. This script shuts down the OS safely, when the button on the RemotePi Board or the off button on the remote is pressed :

  • Key in
    nano irswitch.sh
  • Copy and paste the following text into the editor window
    #!/bin/bash
    # this is the GPIO pin receiving the shut-down signal
    GPIOpin1=14
    echo "$GPIOpin1" > /sys/class/gpio/export
    echo "in" > /sys/class/gpio/gpio$GPIOpin1/direction
    while true; do
      sleep 1
      power=$(cat /sys/class/gpio/gpio$GPIOpin1/value)
      if [ $power != 0 ]; then
        echo "out" > /sys/class/gpio/gpio$GPIOpin1/direction
        echo "1" > /sys/class/gpio/gpio$GPIOpin1/value
        sleep 3
        poweroff
      fi
    done
  • Press ctrl+x to exit, y to confirm, enter to save the file
  • Key in
    chmod +x irswitch.sh

The following additional script enables the RemotePi Board to cut off the power, after OpenElec / LibreELEC has been shut down from the on-screen menu.

  • Key in :
    nano shutdown.sh
  • Copy and paste the following contents
  • #!/bin/bash
    if [ "$1" != "reboot" ]; then
      GPIOpin=15
      GPIOpin1=14
      echo "$GPIOpin" > /sys/class/gpio/export
      # execute shutdown sequence on pin
      echo "out" > /sys/class/gpio/gpio$GPIOpin/direction
      echo "1" > /sys/class/gpio/gpio$GPIOpin/value
      usleep 125000
      echo "0" > /sys/class/gpio/gpio$GPIOpin/value
      usleep 200000
      echo "1" > /sys/class/gpio/gpio$GPIOpin/value
      usleep 400000
      echo "0" > /sys/class/gpio/gpio$GPIOpin/value
      # set GPIO 14 high to feedback shutdown to RemotePi Board
      # because the irswitch.sh has already been terminated
      echo "$GPIOpin1" > /sys/class/gpio/export
      echo "out" > /sys/class/gpio/gpio$GPIOpin1/direction
      echo "1" > /sys/class/gpio/gpio$GPIOpin1/value
      usleep 4000000
    fi
  • Press ctrl+x to exit, y to confirm, enter to save the file
  • Mark the script as executable by keying in
    chmod +x shutdown.sh
     
  • Reboot from the OpenElec or LibreELEC OS GUI.
  • After reboot you can use the RemotePi Board to power cycle OpenElec / LibreELEC

The above scripts have been tested and are confirmed to work with OpenElec 6 to 8.0.4 and LibreELEC up to 9.2.5. Although not yet tested, they will most likely work with newer versions as well.

This page was last updated 25-Aug-2020