Button on GPIO for OFF / Reboot

Hello,
I wanted to connect a button on Raspberry using GPIO to get two functions.

  1. Press OFF Raspberry for X seconds
  2. Press for Y seconds REBOOT Raspberry
  3. Don’t use OH, I need it just when I have problems in OH

I ask for help for:

  1. What is the correct procedure for REBOOT, give the command sudo reboot or first sudo systemctl stop openhab2.service?
  2. Someone at a script to perform these two functions?

Thank you

  1. You can just issue the reboot. That will try to nicely shutdown openHAB for you so there is no need for the systemctl command.

  2. There are tons and tons of examples on the web for turning off or rebooting an RPi using a button wired to GPIO. Search around and you are sure to find one.

1 Like

Hello,
I found what I was looking for on the net.
It’s a python code two years ago, I was wondering if the two calls were current ?

from subprocess import check_call

check_call(['/sbin/poweroff'])
check_call(['/sbin/reboot'])