[How to] Pimoroni OnOff SHIM with LibreELEC

  • I have been able to install the Pimoroni OnOff SHIM on my RPi running LibreELEC. The OnOff SHIM enables you to completely power off - and power on again - a Raspberry Pi with a single pushbutton. As mentioned elsewhere in this forum, it is not possible to install it using Pimoroni's install script, as this requires use of apt-get to install packages, which is not available under LibreELEC; also, it would be necessary to change paths throughout the script.

    I came across this thread on the Retropie forum, where the author had stripped this down to two simple shell scripts. Inspired by this, I have created the following scripts for LibreELEC.

    The first is a python script, which checks for the button being pressed, and if held for > 1 second (as with the Pimoroni script), invokes the halt (or poweroff) os command. This requires the Raspberry Pi Tools add-on, and should be called from autostart.sh. (I saved it in /storage/.kodi/userdata.)

    The second script, which is called as part of the shutdown process, will flash the SHIM's onboard LED 3 times, and then drive GPIO 4 low, cutting the power to the RPi (as with the Pimoroni script):

    This needs to be saved as /storage/.config/shutdown.sh

    Now, pressing and holding the button - or calling 'Power off system' from the Power options menu, will completely power off the RPi.

    A momentary press of the button will power it up again.

  • Hi guys,

    I just wanted to let you know that I spent around 4 hrs to make my new OnOFF SHIM running on my RPi 3 with LibreELEC 12.0.2. I tried to use the scripts described in the thread [How to] Pimoroni OnOff SHIM with LibreELEC but it didn't work.

    First of all, I had troubles to run the shell scripts because the GPIO points were incorrect.

    Secondly, when making a Python script, I had troubles with RPi.GPIO which was replaced by gpiozero.


    Ad.1.

    While preparing a shell script, I found out that in order to define the GPIO point correctly, you have to add a value of 512 to the number of the GPIO point.


    So my shutdown.sh file looks like this now:

    And after it shuts down RPi, it cuts of the power. So there is a success.


    Ad.2.

    There was a problem with python script. As the script itself, when running from shell, worked like a charm- if I clicked the button, it would shut down the environment. But when the script was executed automatically, there were some errors in the systemctl logs.

    Anyway, my off.py script looks like this now:

    The most important thing was to put that os.environ['LG_WD'] thing so that the internal processes got writable rights to operate in temporary folder and so the script could start running in the background.


    Finally, I created the autostart.sh and entered a line:

    Code
    ( /usr/bin/python /storage/.config/off.py ) &


    So now, I can use the button to shut down the system - the python script initiates the shutdown pocess which cuts of the power eventually. If I use the option within the libreELEC environment, RPi runs the shell script directly.


    I hope this decent post will help someone else who uses the OnOff SHIM by Pimoroni.


    Best Reagards,

    Przemek