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)

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!

Like & Subscribe!