Purpose of this script is to make shutdown & reboot (+LED) buttons on RetroFlag NesPi Plus case to work on Raspberry Pi LibreELEC.
Here's script for RetroFlag NesPi+ case which I modified for my needs from recalbox_SafeShutdown.py. No need to download or install anything from linked github page. Save the code I shared for example as "nespi_shutdown.py" and copy it to your LibreELEC sd card.
On LibreELEC install following add-ons:
- LibreELEC repository: rpi-tools (I'm not sure about exact addon name, might have been also RPi.GPIO or something)
- KODI add-on repository: Kodi Callbacks
From "Kodi Callbacks" settings set "nespi_shutdown.py" to run on KODI start. There's also other ways to run scripts on Kodi start but I have used this add-on because of my limited skills 
Also "Safe ShutDown" switch inside NesPi+ case needs to be turned ON.
I don't have knowledge to say if my modified script is 100% correct but power button, reset button & LED seem to work correct. Although LED doesn't blink correctly for a short time after reboot button is pushed (maybe because LibreELEC reboots much faster than Recalbox). If there's any improvements to be done please share 
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
import RPi.GPIO as GPIO
import os
import time
from multiprocessing import Process
#initialize pins
powerPin = 3 #pin 5
ledPin = 14 #TXD
resetPin = 2 #pin 13
powerenPin = 4 #pin 5
#initialize GPIO settings
def init():
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(powerPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(resetPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(ledPin, GPIO.OUT)
    GPIO.setup(powerenPin, GPIO.OUT)
    GPIO.output(powerenPin, GPIO.HIGH)
    GPIO.setwarnings(False)
#waits for user to hold button up to 1 second before issuing poweroff command
def poweroff():
    while True:
        GPIO.wait_for_edge(powerPin, GPIO.FALLING)
        os.system("shutdown -h now")
#blinks the LED to signal button being pushed
def ledBlink():
    while True:
        GPIO.output(ledPin, GPIO.HIGH)
        GPIO.wait_for_edge(powerPin, GPIO.FALLING)
        start = time.time()
        while GPIO.input(powerPin) == GPIO.LOW:
            GPIO.output(ledPin, GPIO.LOW)
            time.sleep(0.2)
            GPIO.output(ledPin, GPIO.HIGH)
            time.sleep(0.2)
#resets the pi
def reset():
    while True:
        GPIO.wait_for_edge(resetPin, GPIO.FALLING)
        os.system("shutdown -r now")
if __name__ == "__main__":
    #initialize GPIO settings
    init()
    #create a multiprocessing.Process instance for each function to enable parallelism 
    powerProcess = Process(target = poweroff)
    powerProcess.start()
    ledProcess = Process(target = ledBlink)
    ledProcess.start()
    resetProcess = Process(target = reset)
    resetProcess.start()
    powerProcess.join()
    ledProcess.join()
    resetProcess.join()
    GPIO.cleanup() 
		