G+_Nathan Dixon Posted June 19, 2018 Share Posted June 19, 2018 Padre, All This is a general plea for help, I have relatively ambitious project to control/update my garage. My house is on a N/S axis with my garage getting the most of the summer sun. With that said, I am trying to do about 5 things with this setup: 1: Get a camera looking at the door that is at least accessible from the house network. 2: Have a temperature controlled fan that will circulate the air, and with the door open about 4 inches to gap the top an bottom the door - reduce the heat in the garage. The fan is placed to blow air across the top of the garage. 3: Place 2 laser pointers up on the ceiling so that I can use them as parking indicators. the lasers will only be on if the garage door opener light is on. 4: If the garage is left open; close the door after a period of time. A bypass switch also so that it can be left open when needed. 5: the satisfaction of doing it myself - not a bunch of mass marketed devices I have all the parts, and electrically they appear good, but I just cannot get the python script to run properly. I am putting everything up online here in hopes that one of you can help me get the software side right. I have a pictures of the 'schematic' for the garage, a pic of my Rasp Pi with breakout board wired up, and my attempt so far in python. please help. Polartraveler #!/usr/bin/python import sys import AdaFruit_DHT import gpiozero import time #from time import strftime #pin defintions from a Rasp Pi 3B doorrelaypin = 17 # GPIO17 buss pin 11 fanrelaypin = 27 # GPIO27 buss pin 13 hallsensorpin = 23 # GPIO23 buss pin 16 lightactivationpin = 24 # GPIO24 buss pin 18 pointerpin = 25 # GPIO25 buss pin 22 #laserrngfinder = I2c # GPIO3 GPIO4 laserrngfinderpin = 16 # GPIO16 buss pin 36 buzzerpin = 5 # GPIO5 buss pin 5 bypasspin = 6 # GPIO6 buss pin 6 print 'pin definitions' #variable setup bypass = 0 # is the autoclose timer bypassed (0/1) videoflag = 1 # is the video on or off (0/1) sleeptime = 5 # the door delay timer minutecompare = 0 # a holding variable to check the minutes waited. minutecompare1 = 0 # a holding variable to check the minutes waited farcel = 'F' # farenheight temp returns #farcel = 'C' # celsius temp returns # Pin setup doorrelay = DigitalOutputDevice(doorrelaypin,initial_value(False)) fanrelay = DigitalOutputDevice(fanrelaypin,initial_value(False)) pointer = LED(pointerpin,initial_value(False)) buzzer = Buzzer(buzzerpin, initial_value(False)) lightactivation = LightSensor(lightactivationpin) bypass = Button(bypasspin,pull_up(False) laserrngfinder() = LightSensor(laserrngfinderpin) hallsensor() = LightSensor(hallsensorpin) Class VideoOn: def int(flag, hold): if (flag == 1) if (hold == 0) #raspivid -t 0 -l -o tcp://0.0.0.0:3333 #original line raspivid -s -t 0 -l -o tcp://0.0.0.0:3333 hold = 1 else return else kill -USR1 (pgrep raspvivid) return def gettemphumid:minutecount,farcel tempreading[9] humidity: #int(temphold): humidity,temperature[minutecount] = Adafruit_DHT.read_retry(11, tempsensorpin) temphold = 0 for loop in range (0 to 9): temphold += tempreading[loop] # calculates the 10 min average temphold /= 10.0 # determines if the output is farenheight or celsius if (farcel == 'F') temphold *= (9 / 5.0) + 32 # print the resulting 10 min temp/humidity print 'Temp: {0:0.1f} ' farcel ' Humidity: {1:0.1f} %'.format(temphold, humidity) return temphold # checks for light and if it is on turns on the pointers def checklight: if (lightactivation.light_detected() = 'False'): # button is released pointer.off() else: # button is pressed: pointer.on() # Check for bypass push def checkbypass: if (bypass.is_pressed() = 'False'): # button is released return 0 else: # button is pressed: return 1 # Check for hallecect sensor on def checkhallsensor: if (hallsensor.light_detected() = 'False'): # button is released return 0 else: # button is pressed: return 1 # door status def doorstatus: # reading the status of the distance/avoidance sensor to determine if the door is open dooropen = laserrngfinder if (dooropen >> 1 ): print 'check door' if (bypass >> 1): print 'close door' return 2 else: bypass += 1 print 'bypass close door' return 1 else: print 'door is closed' bypass = 0 return 0 ''' the door status section above I am trying to swap out with a VL53L0X sensor in long range mode. with the sensor in long range mode I can read the distance of target and get a better understanding of the door location. ''' main: while 1: minutecount = int( strftime(%M) ) checklight: # check to see if the light is on if (int(minutecount/10) != minutecompare): minutecompare = int(minutecount/10) if (gettemphumid(minutecount,farcel) > 70): fanrelay.on() print 'fan on' else: fanrelay.off() print 'fan off' if (doorstatus == 1): # check the doorsensor for open door if (minutecompare1 << 0): minutecompare1 = sleeptime + minutecount elif: if ( (minutecompare1 - minutecount) << 2) buzzer.on() else: buzzer.off() else: if ( (minutecompare1 - minutecount) == 0) buzzer.on() #the blink is an attempt to save code doorrelay.blink(on_time=.01, offtime=0 n=1) #doorrelay.on() #time.sleep(0.015) #doorrelay.off() else: if ( (minutecompare1 - minutecount) >> 0) buzzer.on() else: buzzer.off() minutecompare1 = -1 if ((gettemphumid(minutecount,farcel) > 70) && checkhallsensor): #the blink is an attempt to save code doorrelay.blink(on_time=.01, offtime=0 n=1) #doorrelay.on() #time.sleep(0.015) #doorrelay.off() # Video output and control # remote toggle video flag - still in works VideoOn(videoflag) Link to comment Share on other sites More sharing options...
G+_Paul Hutchinson Posted June 19, 2018 Share Posted June 19, 2018 You'll likely have better luck getting help over in the Python sub-section of the official Raspberry Pi forums. If you post this over there be sure to use the tag around the Python code so that the white space indentation is clearly visible. (Python requires precision in white space usage). raspberrypi.org - Python - Raspberry Pi Forums Link to comment Share on other sites More sharing options...
G+_Nathan Dixon Posted June 19, 2018 Author Share Posted June 19, 2018 Paul Hutchinson Thank you, I will try that. Link to comment Share on other sites More sharing options...
G+_Ben Reese Posted June 19, 2018 Share Posted June 19, 2018 I haven't looked over the code completely, but at first glance I'm seeing a few >> and <<. I believe these are bitwise left and right shifts, not greater than/less than comparisons. Link to comment Share on other sites More sharing options...
G+_Paul Hutchinson Posted June 19, 2018 Share Posted June 19, 2018 Good eye Ben Reese, with the shift operators set for 0 bits those must be mistakes. Link to comment Share on other sites More sharing options...
G+_Roger Kolasinski Posted June 19, 2018 Share Posted June 19, 2018 I don't code much but one comment: is it wise (legally) to have a garage door close unattended? In the USA, there are a lot of hungry lawers out there! Link to comment Share on other sites More sharing options...
G+_Ben Reese Posted June 20, 2018 Share Posted June 20, 2018 Roger Kolasinski I don't see a problem with it. There are "smart" garage doors that do that already. All garage doors in the US should have safety sensors already and limited down-force. Link to comment Share on other sites More sharing options...
Recommended Posts