def main(): mySettings = settingsClass() # get settings from db mySunrise = sunRiseSet() # Get sunrise and sunset from DB mySunrise.getSunriseset() myWeather = weather() myWeather.getWeather() #inkyphat.set_border(inkyphat.WHITE) if (myWeather.wind_dir in ('South')): inkyphat.set_image("/home/pi/code/watertanks/resources/compass_s.png") elif (myWeather.wind_dir in ('SW', 'SSW')): inkyphat.set_image("/home/pi/code/watertanks/resources/compass_sw.png") elif (myWeather.wind_dir in ('SE', 'SSE')): inkyphat.set_image("/home/pi/code/watertanks/resources/compass_se.png") elif (myWeather.wind_dir in ('North', 'NNW', 'NNE')): inkyphat.set_image("/home/pi/code/watertanks/resources/compass_n.png") elif (myWeather.wind_dir in ('West', 'WSW', 'WNW')): inkyphat.set_image("/home/pi/code/watertanks/resources/compass_w.png") elif (myWeather.wind_dir in ('East', 'ESE', 'ENE')): inkyphat.set_image("/home/pi/code/watertanks/resources/compass_e.png") else: #if (myWeather.wind_dir in ('S', 'SE', 'SW', 'NE', 'N', 'NW', 'W', 'S')): imgFile = "/home/pi/code/watertanks/resources/compass_{0}.png".replace( '{0}', myWeather.wind_dir.lower()) inkyphat.set_image(imgFile) printTitle("Tank") printText(1, "Sunrise:", mySunrise.sunrise.isoformat()[0:8], '') printText(2, "Sunset:", mySunrise.sunset.isoformat()[0:8], '') printText(3, "Water:", mySettings.settings["pumpduration"], 'min') temp_c = str(myWeather.temp_c) windchill_c = str(myWeather.windchill_c) printText(4, "Temp:", temp_c + 'c w/c ' + windchill_c, 'c') printText(5, "Weather:", myWeather.weather, '') wind_mph = str(myWeather.wind_mph) wind_gust_mph = str(myWeather.wind_gust_mph) printText(6, "Wind:", myWeather.wind_dir + " spd: " + wind_mph + 'g: ' + wind_gust_mph, '') inkyphat.show() # And show it!
def main(): fontSize = 16 mySunrise = sunRiseSet() # Get sunrise and sunset from DB mySunrise.getSunriseset(); myWeather = weather() myWeather.getWeather() # Load the built-in FredokaOne font font = ImageFont.truetype(inkyphat.fonts.FredokaOne, fontSize) inkyphat.set_border(inkyphat.BLACK) inkyphat.text((0, fontSize * 0), "Tank", inkyphat.BLACK, font=font) inkyphat.text((0, fontSize * 1), "Sunrise: " + mySunrise.sunrise.isoformat(), inkyphat.BLACK, font=font) inkyphat.text((0, fontSize * 2), "Sunset: " + mySunrise.sunset.isoformat(), inkyphat.BLACK, font=font) inkyphat.text((0, fontSize * 3), "Weather: " + myWeather.weather, inkyphat.BLACK, font=font) # And show it! inkyphat.show()
def get(self): myWeather = weather() returnString = myWeather.getWeatherGraph() return returnString, 200
def main(): gpio.setmode(gpio.BCM) gpio.setup([irrigationPin, hosePin, powerPin], gpio.OUT) gpio.output([irrigationPin, hosePin], gpio.LOW) gpio.output([powerPin], gpio.HIGH) #mqMessage = "" state = -2 # Startup state myWeather = weather() myLedControl = ledcontrol() # init remote led control mySensor = sensorComm() #myMqSensor = mqSensor() #myMqControl = mqControl() mySettings = settingsClass() # get settings from db #mySettings.resetSettings() #automationhat.is_automation_hat() #if automationhat.is_automation_hat(): # init local automation hat #automationhat.light.power.write(1) #automationhat.light.comms.write(1) # setup pwm #pwmLow = mySettings.settings['pwmLow'] pwmMid = mySettings.settings['pwmMid'] pwmHigh = mySettings.settings['pwmHigh'] # Start pwm # serial comm to the Arduino to set/get sensor data. mySensor.pumpPWM = pwmMid mySensor.setValues() #mqMessage = mySensor.setValues() #myMqControl.sendMQ(mqMessage) mySensor.refresh() #mqMessage = mySensor.refresh() #myMqSensor.sendMQ(mqMessage) # Set sunrise sunset vars dayRollover = -1 # get new sunrise sunset times only once! mySunrise = sunRiseSet() # Get sunrise and sunset from DB # Config the display #scrollphathd.set_brightness(0.5) myTimeNow = datetime.datetime.now() currTime = myTimeNow.hour + myTimeNow.minute lastTime = currTime currHour = -1 lastHour = -2 myWeather.getWeather() #automationhat.light.comms.write(0) while True: myTimeNow = datetime.datetime.now() currTime = myTimeNow.hour + myTimeNow.minute currHour = myTimeNow.hour # Update the time string for the display every minute if (currTime != lastTime and state == -1): lastTime = currTime # Update the weather trend (last 24 hours) every hour if (currHour != lastHour): lastHour = currHour myWeather.getWeather() myWeather.getRecentTrend() # get new sunrise and sunset times rollTime = myTimeNow.hour + myTimeNow.minute if (rollTime == 0 and dayRollover == -1): mySunrise = sunRiseSet() dayRollover = 0 elif (rollTime == 0 and dayRollover == 0): dayRollover = 0 else: dayRollover = -1 numStartTime = (myTimeNow.hour * 3600) + (myTimeNow.minute * 60) + myTimeNow.second #automationhat.light.comms.write(1) # Comm light on to show activity. mySensor.refresh() #mqMessage = mySensor.refresh() #myMqSensor.sendMQ(mqMessage) #automationhat.light.comms.write(0) # Comm light on to show activity. # complex if conditions so I pulled them into variables ifWeatherTrend = ((myWeather.isTrend('Rain') or myWeather.isTrend('Snow')) and state != 5) ifSunrise = ((numStartTime >= mySunrise.numSunriseSeconds and numStartTime <= (mySunrise.numSunriseSeconds + (mySettings.settings["pumpduration"] * 60))) and state != 1) ifSunset = ((numStartTime >= mySunrise.numSunsetSeconds and numStartTime <= (mySunrise.numSunsetSeconds + (mySettings.settings["pumpduration"] * 60))) and state != 4) ifIrrigationButton = (str(mySensor.settings['irrigationButton']) =='1'); ifHose = (str(mySensor.settings['hoseButton']) =='1') ; ifBauFromSunrise = (not(numStartTime >= mySunrise.numSunriseSeconds and numStartTime <= (mySunrise.numSunriseSeconds + (mySettings.settings["pumpduration"] * 60))) and state == 1) ifBauFromSunset = (not(numStartTime >= mySunrise.numSunsetSeconds and numStartTime <= (mySunrise.numSunsetSeconds + (mySettings.settings["pumpduration"] * 60))) and state == 4) ifBauFromIrrigationButton = (ifIrrigationButton == False and state == 3) ifBauFromHoseButton = (ifHose == False and state == 2) ifBauFromStartup = ((ifIrrigationButton or ifHose) and state == -2) if (ifWeatherTrend == True and (ifHose == False and state != 2)): state = 5 # Weather is rain or snow #automationhat.light.comms.write(1) # Comm light on to show activity. mySensor.hose = 0 mySensor.irrigation = 0 mySensor.pumpPWM = pwmMid mySensor.setValues() gpio.output([irrigationPin, hosePin], gpio.LOW) #mqMessage = mySensor.setValues() #myMqControl.sendMQ(mqMessage) myLedControl.setIrrigationGreen(0) # update remote display myLedControl.setHoseGreen(0) # update remote display #automationhat.light.comms.write(0) # Comm light off to show activity. elif (ifIrrigationButton and ifHose): #Fail #automationhat.light.comms.write(1) # Comm light on to show activity. mySensor.hose = 0 mySensor.irrigation = 0 mySensor.pumpPWM = pwmHigh mySensor.setValues() gpio.output([irrigationPin, hosePin], gpio.LOW) #mqMessage = mySensor.setValues() #myMqControl.sendMQ(mqMessage) myLedControl.setIrrigationGreen(0) # update remote display myLedControl.setHoseGreen(0) # update remote display #automationhat.light.comms.write(0) # Comm light off to show activity. elif (ifSunrise): # sunrise irrigation requested state = 1 # Sunrise state #automationhat.light.comms.write(1) # Comm light on to show activity. mySensor.hose = 0 mySensor.irrigation = 1 mySensor.pumpPWM = pwmHigh mySensor.setValues() gpio.output([irrigationPin], gpio.HIGH) gpio.output([hosePin], gpio.LOW) #mqMessage = mySensor.setValues() #myMqControl.sendMQ(mqMessage) myLedControl.setIrrigationGreen(1) # update remote display myLedControl.setHoseGreen(0) # update remote display #automationhat.light.comms.write(0) # Comm light off to show activity. elif (ifSunset): # sunrise irrigation requested state = 4 # Sunset state #automationhat.light.comms.write(1) # Comm light on to show activity. mySensor.hose = 0 mySensor.irrigation = 1 mySensor.pumpPWM = pwmHigh mySensor.setValues() gpio.output([irrigationPin], gpio.HIGH) gpio.output([hosePin], gpio.LOW) #mqMessage = mySensor.setValues() #myMqControl.sendMQ(mqMessage) myLedControl.setIrrigationGreen(1) # update remote display myLedControl.setHoseGreen(0) # update remote display #automationhat.light.comms.write(0) # Comm light off to show activity. elif (ifIrrigationButton and state != 3): # sunrise irrigation requested state = 3 # Sunrise state #automationhat.light.comms.write(1) # Comm light on to show activity. mySensor.hose = 0 mySensor.irrigation = 1 mySensor.pumpPWM = pwmHigh mySensor.setValues() gpio.output([irrigationPin], gpio.HIGH) gpio.output([hosePin], gpio.LOW) #mqMessage = mySensor.setValues() #myMqControl.sendMQ(mqMessage) myLedControl.setIrrigationGreen(1) # update remote display myLedControl.setHoseGreen(0) # update remote display #automationhat.light.comms.write(0) # Comm light off to show activity. elif (ifHose and state != 2): # hose requested on state = 2 # Hose state #automationhat.light.comms.write(1) # Comm light on to show activity. mySensor.hose = 1 mySensor.irrigation = 0 mySensor.pumpPWM = pwmHigh mySensor.setValues() gpio.output([irrigationPin], gpio.LOW) gpio.output([hosePin], gpio.HIGH) #mqMessage = mySensor.setValues() #myMqControl.sendMQ(mqMessage) myLedControl.setIrrigationGreen(0) # update remote display myLedControl.setHoseGreen(1) # update remote display #automationhat.light.comms.write(0) # Comm light off to show activity. elif (ifBauFromSunrise or ifBauFromSunset or ifBauFromStartup or ifBauFromIrrigationButton or ifBauFromHoseButton): # BAU state state = -1 #automationhat.light.comms.write(1) # Comm light on to show activity. mySensor.hose = 0 mySensor.irrigation = 0 mySensor.pumpPWM = pwmMid mySensor.setValues() gpio.output([irrigationPin, hosePin], gpio.LOW) #mqMessage = mySensor.setValues() #myMqControl.sendMQ(mqMessage) myLedControl.setIrrigationGreen(0) # update remote display myLedControl.setHoseGreen(0) # update remote display
def main(): # i2c bus = smbus.SMBus(1) # send works on bus 1 DEVICE_ADDRESS = 0x14 DEVICE_REG_MODE1 = 0x00 bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG_MODE1, 0x01) #bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG_MODE1, 0x02) # pwm high #displayBrightness = 0.5 state = -2 # Startup state myWeather = weather() myLedControl = ledcontrol() # init remote led control if automationhat.is_automation_hat(): # init local automation hat automationhat.light.power.write(1) automationhat.light.comms.write(1) #time.sleep(0.05) # sleep to give the system time to set the LEDs mySettings = settingsClass() # get settings from db #mySettings.resetSettings() # setup pwm #outpin = mySettings.settings['pwmPin'] #pwmLow = mySettings.settings['pwmLow'] #pwmMid = mySettings.settings['pwmMid'] #pwmHigh = mySettings.settings['pwmHigh'] # Start pwm #gpio.setmode(gpio.BCM) #gpio.setup(outpin, gpio.OUT) #myPwm = gpio.PWM(outpin, mySettings.settings['pwmFrequency']) #myPwm.start(pwmMid) # pump init # Set sunrise sunset vars dayRollover = -1 # get new sunrise sunset times only once! mySunrise = sunRiseSet() # Get sunrise and sunset from DB # Config the display #scrollphathd.set_brightness(0.5) automationhat.light.comms.write(0) myTimeNow = datetime.datetime.now() currTime = myTimeNow.hour + myTimeNow.minute lastTime = currTime currHour = -1 lastHour = -2 while True: myTimeNow = datetime.datetime.now() currTime = myTimeNow.hour + myTimeNow.minute currHour = myTimeNow.hour # Update the time string for the display every minute if (currTime != lastTime and state == -1): lastTime = currTime #scrollphathd.clear() #scrollphathd.write_string(getStatusText(str(mySunrise.sunrise), str(mySunrise.sunset)) , x=0, y=0, font=font5x7, brightness=0.5) # Update the weather trend (last 24 hours) every hour if (currHour != lastHour): lastHour = currHour myWeather.getWeather() myWeather.getRecentTrend() # get new sunrise and sunset times rollTime = myTimeNow.hour + myTimeNow.minute if (rollTime == 0 and dayRollover == -1): mySunrise = sunRiseSet() dayRollover = 0 elif (rollTime == 0 and dayRollover == 0): dayRollover = 0 else: dayRollover = -1 numStartTime = (myTimeNow.hour * 3600) + (myTimeNow.minute * 60) + myTimeNow.second # i2c read #time.sleep(1) i2cRead = bus.read_byte_data(DEVICE_ADDRESS, 0) # complex if conditions so I pulled them into variables ifWeatherTrend = ((myWeather.isTrend('Rain') or myWeather.isTrend('Snow')) and state != 5) ifSunrise = ((numStartTime >= mySunrise.numSunriseSeconds and numStartTime <= (mySunrise.numSunriseSeconds + (mySettings.settings["pumpduration"] * 60))) and state != 1) ifSunset = ((numStartTime >= mySunrise.numSunsetSeconds and numStartTime <= (mySunrise.numSunsetSeconds + (mySettings.settings["pumpduration"] * 60))) and state != 4) ifIrrigationButton = (i2cRead == 12 and state != 3) ifHose = (i2cRead == 10 and state != 2) #ifIrrigationAndHose = (automationhat.input.one.read() == True and automationhat.input.two.read() == True) ifBauFromSunrise = (not(numStartTime >= mySunrise.numSunriseSeconds and numStartTime <= (mySunrise.numSunriseSeconds + (mySettings.settings["pumpduration"] * 60))) and state == 1) ifBauFromSunset = (not(numStartTime >= mySunrise.numSunsetSeconds and numStartTime <= (mySunrise.numSunsetSeconds + (mySettings.settings["pumpduration"] * 60))) and state == 4) ifBauFromIrrigationButton = (automationhat.input.two.read() == False and state == 3) ifBauFromStartup = ((automationhat.input.one.read() == False and state == 2) or state == -2) if (ifWeatherTrend == True and (ifHose == False and state != 2)): state = 5 # Sunrise state automationhat.light.comms.write(1) # Comm light on to show activity. automationhat.output.one.write(0) # irrigation solenoid on automationhat.output.two.write(0) # hose solenoid off bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG_MODE1, 0x02) # pwm high myLedControl.setIrrigationGreen(0) # update remote display myLedControl.setHoseGreen(0) # update remote display automationhat.light.comms.write(0) # Comm light off to show activity. elif (automationhat.input.one.read() == True and automationhat.input.two.read() == True): #Fail automationhat.light.comms.write(1) # Comm light on to show activity. automationhat.output.one.write(0) # irrigation solenoid on automationhat.output.two.write(0) # hose solenoid off bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG_MODE1, 0x02) # pwm high myLedControl.setIrrigationGreen(0) # update remote display myLedControl.setHoseGreen(0) # update remote display automationhat.light.comms.write(0) # Comm light off to show activity. elif (ifSunrise): # sunrise irrigation requested state = 1 # Sunrise state automationhat.light.comms.write(1) # Comm light on to show activity. #scrollphathd.clear() #scrollphathd.write_string(' irrigation on: ' + str(mySettings.settings["pumpduration"]) + ' mins', x=0, y=0, font=font5x7, brightness = displayBrightness) # action the water solenoid and pump automationhat.output.one.write(1) # irrigation solenoid on automationhat.output.two.write(0) # hose solenoid off bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG_MODE1, 0x02) # pwm high myLedControl.setIrrigationGreen(1) # update remote display myLedControl.setHoseGreen(0) # update remote display automationhat.light.comms.write(0) # Comm light off to show activity. elif (ifSunset): # sunrise irrigation requested state = 4 # Sunset state automationhat.light.comms.write(1) # Comm light on to show activity. #scrollphathd.clear() #scrollphathd.write_string(' irrigation on: ' + str(mySettings.settings["pumpduration"]) + ' mins', x=0, y=0, font=font5x7, brightness = displayBrightness) # action the water solenoid and pump automationhat.output.one.write(1) # irrigation solenoid on automationhat.output.two.write(0) # hose solenoid off bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG_MODE1, 0x02) # pwm high myLedControl.setIrrigationGreen(1) # update remote display myLedControl.setHoseGreen(0) # update remote display automationhat.light.comms.write(0) # Comm light off to show activity. elif (ifIrrigationButton): # sunrise irrigation requested state = 3 # Sunrise state automationhat.light.comms.write(1) # Comm light on to show activity. #scrollphathd.clear() #scrollphathd.write_string(' irrigation on: ' + str(mySettings.settings["pumpduration"]) + ' mins', x=0, y=0, font=font5x7, brightness = displayBrightness) automationhat.output.one.write(1) # irrigation solenoid on automationhat.output.two.write(0) # hose solenoid off bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG_MODE1, 0x02) # pwm high myLedControl.setIrrigationGreen(1) # update remote display myLedControl.setHoseGreen(0) # update remote display automationhat.light.comms.write(0) # Comm light off to show activity. elif (ifHose): # hose requested on state = 2 # Hose state automationhat.light.comms.write(1) # Comm light on to show activity. #scrollphathd.clear() #scrollphathd.write_string(' hose On', x=0, y=0, font=font5x7, brightness = displayBrightness) # action the water solenoid and pump automationhat.output.two.write(0) # irrigation solenoid off automationhat.output.two.write(1) # hose solenoid on bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG_MODE1, 0x02) # pwm high myLedControl.setIrrigationGreen(0) # update remote display myLedControl.setHoseGreen(1) # update remote display automationhat.light.comms.write(0) # Comm light off to show activity. elif (ifBauFromSunrise or ifBauFromSunset or ifBauFromStartup or ifBauFromIrrigationButton): # BAU state state = -1 automationhat.light.comms.write(1) # Comm light on to show activity. #scrollphathd.clear() #scrollphathd.write_string(getStatusText(str(mySunrise.sunrise), str(mySunrise.sunset)) , x=0, y=0, font=font5x7, brightness = displayBrightness) # action the water solenoid and pump automationhat.output.one.write(0) # irrigation led off automationhat.output.two.write(0) # hose led off bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG_MODE1, 0x01) # pwm mid myLedControl.setIrrigationGreen(0) # update remote display myLedControl.setHoseGreen(0) # update remote display automationhat.light.comms.write(0) # Comm light off to show activity.
def getWeatherGraph(): myWeather = weather() returnString = myWeather.getWeatherGraph() return json.dumps(returnString)