Got some more help on another forum, but this also really helped me along.
Currently stuck here, line 50 is causing issues and im not able to see why.
Currently stuck here, line 50 is causing issues and im not able to see why.
import RPi.GPIO as GPIO import time import requests def LightsOn(): colors = { 'dailywhite':'{"on":true,"bri":255,"sat":0,"hue":0}', 'latewhite':'{"on":true,"bri":255,"sat":80,"hue":357}', 'midnight':'{"on":true,"bri":255,"sat":68,"hue":357}', 'afterparty':'{"on":true,"bri":255,"sat":255,"hue":0,"effect":"colorloop"}' } hour = time.localtime().tm_hour time_colors = {(0,2):'midnight', (2,7):'afterparty', (7, 20):'dailywhite', (20,24):'latewhite'} color_schema = {hour:color for hours, color in time_colors.items() for hour in range(hours[0], hours[1])} color = colors[color_schema[hour]] headers = { 'Accept': 'application/json', } requests.put('http://192.168.1.47/api/xxxxxxxxxxxxxxxxxxxxxx/lights/2/state', headers=headers, data=color) def LightsOff(): time.sleep(0.1) headers = { 'Accept': 'application/json', } data = '{"on":false}' requests.put('http://192.168.1.47/api/xxxxxxxxxxxxxxxxxxxxxxxxx/lights/2/state', headers=headers, data=data) GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) 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 LightsOn() # 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",i LightsOn() time.sleep(0.1) else: #When output from motion sensor is HIGH print "Movement detected - Turning lights on",i LightsOff() time.sleep(60 * 15) # added delay to prevent program using 100% cpu time. time.sleep(0.5)