Update: Starting with LibreELEC (Leia) v8.95.2 BETA it is possible to use dtoverlay=gpio-shutdown. See further down.
Hi! I felt this area is the most appropriate for what I want to contribute.
I was searching for a way to shut down my libreelec-Raspberry with the touch of a button wired to pins 5 & 6, as I do for my other raspberrys. Unfortunately the same approch, setting dtoverlay=gpio-shutdown in config.txt didn't work.
Another solution I found, invoving autostart and a shutdown.sh yielded very strange results in a not-booting raspberry.
The following approach, seems to work though. Maybe It's not correct so please tell me if I did something wrong.
First create a file "/storage/.config/gpio-shutdown" with the following content:
- # monitor GPIO pin X for shutdown signal
- # export GPIO pin X and set to input with pull-up
- echo "$GPIOPIN" > /sys/class/gpio/export
- echo "in" > /sys/class/gpio/gpio$GPIOPIN/direction
- # wait for pin to go low
- while [ true ] ; do
- if [ "$(cat /sys/class/gpio/gpio$GPIOPIN/value)" == '0' ] ; then
- echo "Raspberry Pi Shutting Down!"
- shutdown -h now
- exit 0
- sleep 1
Make it executable with
Then create a file "/storage/.config/autostart.sh" (or adjust its content accordingly)
Make it also executable, then reboot
How does it work?
The autostart.sh is invoked every time libreelec is booted. It will then start "gpio-shutdown" in the background. This script will check every second whether or not the GPIO3 is connected to GND. As soon as this is dicovered, a "shutdown -h now" is executed and the raspberry will shut down. You'll see the usuall 10 blinks after which you can disconnect.
Another touch of the button which connects GPIO3 to GND will boot up your libreelec.