Jun-04-2018, 09:05 PM
Hi all..
Looking for some help here.
Using below script.
Trying to add the following functions:
I want the pir sensor to basically do nothing between midnight and 0500. So disabled at certain times, but button should work still.
I want to be able to send different colors to the lights at certain times of the day.
So if motion is detected between 7am and 12 am it will be this color code sendt {"on" : True, "bri" : 255, "sat" : 0, "hue" : 0} but when its between 8pm and 23pm this will be sendt {"on" : True, "bri" : 255, "sat" : 173, "hue" : 333} for example.
Any easy way of achieving this? I have tried defining the command called when sending the color codes but im at a standstill here.
Looking for some help here.
Using below script.
Trying to add the following functions:
I want the pir sensor to basically do nothing between midnight and 0500. So disabled at certain times, but button should work still.
I want to be able to send different colors to the lights at certain times of the day.
So if motion is detected between 7am and 12 am it will be this color code sendt {"on" : True, "bri" : 255, "sat" : 0, "hue" : 0} but when its between 8pm and 23pm this will be sendt {"on" : True, "bri" : 255, "sat" : 173, "hue" : 333} for example.
Any easy way of achieving this? I have tried defining the command called when sending the color codes but im at a standstill here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import sys sys.path.append( "/home/pi/.local/lib/python2.7/site-packages" ) from phue import Bridge import RPi.GPIO as GPIO import time import datetime print 'Waiting for network...' time.sleep( 30 ) print 'The wait is over. It\'s showtime!' 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) #Read output from button. b = Bridge( '192.168.1.47' ) try : b.connect() except ImportError: print "Import error occurred!" print "Connected to Hue bridge!" lightson = b.get_light( 2 , "on" ) if lightson: print "Lights are already on." print 'Entering infinite loop...' 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 = (light_on_delay * 1 ) + time.time() button_pressed = 1 command = { "on" : True , "bri" : 255 , "sat" : 0 , "hue" : 0 } b.set_group( 2 , command) lightson = True print ( 'Lights are on for 15 minutes' ) # 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 ) timestamp = datetime.datetime.now().time() if (timestamp < offstarttime and timestamp > offendtime): if i = = 0 : #When output from motion sensor is LOW print ( 'No movement detected - Turning lights off' ) b.set_group( 2 , 'on' , False ) lightson = False print ( 'Lights are off' ) time.sleep( 0.1 ) else : #When output from motion sensor is HIGH print ( 'Movement detected - Turning lights on' ) command = { "on" : True , "bri" : 255 , "sat" : 0 , "hue" : 0 } b.set_group( 2 , command) lightson = True print ( 'Lights are on.' ) time.sleep( 5 ) # added delay to prevent program using 100% cpu time. time.sleep( 0.5 ) |