I've been installed a power button and a status LED on my RPi3B+. This works for RPi4B, too. After SSH login, you can use the nano editor to create or edit all necessary files.
Power Button Hardware Part
Use GPIO03 (Pin #05) and the opposite Ground (Pin #06) to connect a push button for power on / off.
Power Button Scripting Part
Add dtoverlay=gpio-shutdown to config.txt.
Switching off will let the shutdown menu appear.
To shutdown instantly instead, create this /storage/.kodi/userdata/keymaps/keyboard.xml:
Status LED Hardware Part
Use GPIO13 (Pin #33) and the opposite Ground (Pin #34) to connect an LED. Also use a resistor with 330 Ohms or more.
Status LED Add-On Part
Install the Raspberry Pi Tools add-on to use the GPIO programming library in Python.
Status LED Scripting Part
The status LED will be triggered from autostart.sh, which calls the Python script status_led.py . It will switch off automatically at shutdown, no script action required for this part.
Create this /storage/.config/autostart.sh :
Create this /storage/scripts/status_led.py :
#!/usr/bin/python
import sys
sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
import RPi.GPIO as GPIO
# Replace YOUR_CHOSEN_GPIO_NUMBER_HERE with the GPIO pin number you wish to use.
# Make sure you know which rapsberry pi revision you are using first.
# The line should look something like this e.g. "gpio_number = 7".
led_gpio_number = 13
# Use BCM pin numbering (i.e. the GPIO number, not pin number).
# WARNING: this will change between Pi versions.
# Check yours first and adjust accordingly.
GPIO.setmode(GPIO.BCM)
# Switch LED on.
# LED will switch off automatically at shutdown by using normal GPIO state.
GPIO.setup(led_gpio_number, GPIO.OUT)
GPIO.output(led_gpio_number, True)
Display More
Reboot.