#! /usr/bin/env python import os import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) # GPIO21 (pin 40) set up as input. It is pulled up GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) try: while True: # wait for the pin to be shorted with GND.. # ..via reed-relais and if so, halt the system GPIO.wait_for_edge(21, GPIO.FALLING) print ("Shutting down...") os.system("sudo /sbin/shutdown -h now") except: GPIO.cleanup()