Setting up the Shutdown Button on LibreELEC (Plusberry Pi)

This tutorial is for owners of the Plusberry Pi case designed for the Raspberry Pi. The goal is to setup the shutdown button to work with LibreELEC. If you are running OpenELEC, you can follow the original tutorial provided by the Plusberry Pi team here. No copyright intended.  I simply added a few steps that are crucial to setting this up in LibreELEC. In summary, we will be creating the shutdown.sh, adding the script from the original guide, and finally adding the script to the autostart.sh.

Connecting the wires

Basically, you can use any available input, but this example will use pin #24. There is a connector with 3 wires (blue/black/green) coming from the left of the Plusberry board (it’s labeled “UART”). Connect the BLUE wire to pin #24. (see image below)

diagram-rpi

When you press the power button (short press), the GPIO will go from high to low, signaling the RPi to shut down. Now, of course, you need to write a script to actually shut down the RPi when getting the signal.

SSH into LibreELEC

Open up your ssh/telnet client to begin. Putty is a great utility for Windows users. For Mac, the built-in Terminal app is sufficient.

ssh root@insert.ip.address.here

When asked if you are sure type the following

yes

When asked for a password type the following

libreelec

Creating shutdown.sh

Change directory by typing the following

cd /storage/.config/

Create the file by typing the following

nano shutdown.sh

Copy and Paste the following in the empty space

#!/bin/bash

# monitor GPIO pin 24 (wiringPi pin 1) for shutdown signal

# export GPIO pin 24 and set to input with pull-up

echo "24" > /sys/class/gpio/export

echo "in" > /sys/class/gpio/gpio24/direction

# wait for pin to go low


while [ true ]

do

if [ "$(cat /sys/class/gpio/gpio24/value)" == '0' ]

then

 echo "Raspberry Pi Shutting Down!"

 halt &

 exit 0

fi

sleep 1

done

Save the file according to the program you’re using

On Mac, you simply press Control + X on your keyboard

Say yes by typing the following

y

Leave the filename default

Should be named “shutdown.sh”

Press enter

Add the script to autostart.sh

Type the following

nano /storage/.config/autostart.sh

Paste the following in the empty space

(

   /storage/.config/shutdown.sh &

)&

Save the file according to the program you’re using

Say yes by typing the following

y

Leave the filename default

Should be named “autostart.sh”
Press enter

Reboot the system and test it out!

7 thoughts to “Setting up the Shutdown Button on LibreELEC (Plusberry Pi)”

  1. What does the wiring diagram look like for a Model B which has a smaller GPIO header? I could use GPIO #4 for the shutdown button and then GPIO 5, the 3.3V pin and the ground pin for the IR Sensor. What about the other 2 wires. What are those used for?

    1. The diagram is the same. Just ignore the extra pins on the image above. Your model appears to have 26 pins so just stop there. If pin #4 works then by all means use that. Pin #24 is just what they suggested. The Plusberry team did not specify what those extra wires are for. I just left them alone to the side. Everything seems to work without them.

    1. I am not sure, I just copied the steps from the OpenELEC tutorial and changed a few things. Everything else is the same. I didn’t create the script so I have no idea how to help.

  2. Good afternoon. I followed all the steps according to the instructions, only replaced GPIO24 with GPIO3. But the switch does not work. RPI 3 Libreelec 8.0.2 On which version of LE does this script work?

  3. Hi. Thanks for the post. I had to do a couple of modifications to adapt the code for my PI. Otherwise was not working properly.

    1. The autostart.sh above was not working for me. Instead I used the following query for the autostart.sh

    #!/bin/bash
    (sh /storage/.config/shutdown.sh)&
    exit

    2. I needed to used GPIO03 (SLC1 or Pin#05) instead of GPIO24. Just replaced the 24’s for 5’s in the shutdown.sh (switch “24” to “5” and “/gpio24/” to “/gpio5/”).

    I’m using Libreelec 8.0.2. Hope this info helps someone as the scripts above helped me.

    BR

    1. Thank you! But still does not work. Could you send me your files autostrt.sh and shutdown.sh. Maybe I’m typing the wrong code ..

Leave a Reply