#!/usr/bin/python import RPi.GPIO as GPIO from time import sleep import datetime import sys GPIO.setmode(GPIO.BCM) GPIO.setup(23,GPIO.OUT) GPIO_PIR = 7 print ("PIR Module Test (CTRL-C to exit)") # Set pin as input GPIO.setup(GPIO_PIR,GPIO.IN) Current_State = 0 Previous_State = 0 exitst = 0 f = open("/home/pi/pir/wz_zeit.txt", "r") stdvor = int(f.readline()) f.close() print (stdvor) print ("Waiting for PIR to settle ...") # Loop until PIR output is 0 while GPIO.input(GPIO_PIR) == 1: Current_State = 0 print (" Ready") # Read PIR state while True: Current_State = GPIO.input(GPIO_PIR) dt = datetime.datetime.now() std = int(dt.strftime("%H")) if std >= 14 and stdvor >= 14: print (" Vormittag abgelaufen!") exitst = 2 f = open("/home/pi/pir/wz_zeit.txt", "w") f.write("09") f.close() break if std >= 22: print (" Nachmittag abgelaufen!") exitst = 1 f = open("/home/pi/pir/wz_zeit.txt", "w") f.write("15") f.close() break if Current_State==1 and Previous_State==0: # PIR is triggered print (" Motion detected!") f = open("/home/pi/pir/wz_zeit.txt", "w") f.write(str(std)) f.close() # Record previous state GPIO.output(23,GPIO.HIGH) sleep(2) GPIO.output(23,GPIO.LOW) Previous_State=1 exitst = 0 #Test exitst = 1 break sleep (0.1) # clean up gpio pins when we exit the script print ("Status = " + str(exitst)) print ("Quit") # Reset GPIO settings GPIO.cleanup() sys.exit(exitst)