Python Forum
Need some help with merging two scripts
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need some help with merging two scripts
#5
Your example worked somewhat. But it wouldnt continiue after pir had seen movement

This is how it looks after ive been tinkering.
The error is here on line 17:
        end time = time.time + (light_on_delay * 60)
And this is the error message:

  File "button.py", line 17
    end time = time.time + (light_on_delay * 60)
           ^
SyntaxError: invalid syntax
import RPi.GPIO as GPIO
import time

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN) #Read output from PIR motion sensor
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)

light_on_delay = 15  # time in min for light to stay on when button pressed
button_pressed = 0

while True:
    # check for button press
    input_state = GPIO.input(18)
    if input_state == False:
        print('Button Pressed')
        end time = time.time + (light_on_delay * 60)
        button_pressed = 1
        #exec(open("./LightsOn.py").read(), globals())
        print('button push')
    
   
    # check if button has been pressed if it has check to see if time is up
    if button_pressed == 1:
        if time.time > end:
            button_pressed = 0
        
    else:
    
        i=GPIO.input(4)
        if i==0:            #When output from motion sensor is LOW
            print ('No movement detected - Turning lights off')
            #exec(open("./LightsOn.py").read(), globals()) 
            print ('off')
            time.sleep(0.1)
        else:               #When output from motion sensor is HIGH
            print ('Movement detected - Turning lights on')
            #exec(open("./LightsOff.py").read(), globals())
            print ('on')
            time.sleep(60 * 15)

    # added delay to prevent program using 100% cpu time.
    time.sleep(0.5)
Reply


Messages In This Thread
Need some help with merging two scripts - by Kimzer - May-23-2018, 04:18 PM
RE: Need some help with merging two scripts - by Kimzer - May-25-2018, 08:32 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020