so my next project is a light control with PIR sensors.
I have one input to my raspberry and one output to the light relay.
The PIR sensor give me one 5 sec signal to my input, if he is detect any motion.
Now I want a python handling to turn the light on.
But not only light "on" - if a input form the sensor. I want also an off delay, if no more input, than hold on the light an turn it off after 30 sec.
So this is not my main problem, but if the PIR sensor make a new input signal in the off delay, then he doesn't extend the delay.
I found one diagramm that explain the plan:

I hope you unterstand my situation and have a solution for this problem.
Currently I have only a script from github with minimal edit:
Code: Select all
#!/usr/bin/python
# -*- coding: utf8 -*-
import RPi.GPIO as GPIO
import time
import datetime
GPIO.setmode(GPIO.BOARD)
GPIO.setup(35, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(12, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO_PIR = [16]
print "Ready"
# GPIO Input
GPIO.setup(GPIO_PIR,GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
Current_State = 0
Previous_State = 0
try:
print "Ready"
while GPIO.input(GPIO_PIR)==1:
Current_State = 0
while True :
Current_State = GPIO.input(GPIO_PIR)
if Current_State==1 and Previous_State==0:
GPIO.setup(40, GPIO.OUT)
GPIO.output(40, GPIO.LOW)
Previous_State=1
elif Current_State==0 and Previous_State==1:
Previous_State=0
GPIO.setup(40, GPIO.OUT)
time.sleep(80)
GPIO.output(40, GPIO.HIGH)
elif GPIO.input(12) == GPIO.HIGH:
GPIO.setup(40, GPIO.OUT)
GPIO.output(40, GPIO.HIGH)
time.sleep(80)
GPIO.output(40, GPIO.LOW)
elif GPIO.input(35) == GPIO.HIGH:
GPIO.setup(40, GPIO.OUT)
GPIO.output(40, GPIO.HIGH)
time.sleep(80)
GPIO.output(40, GPIO.LOW
except KeyboardInterrupt:
print " -- End"
GPIO.cleanup()Roman