import os from datetime import datetime from time import sleep import time import pifacedigitalio as pfio pfio.init() #Initialise the board pifacedigital = pfio.PiFaceDigital() # Set the times that the pump will run from # E.g. Start_hour = 08 & Start_mins = 10 & Duration_mins = 5 will turn the pump on for 5 mins from 8am at 10 mins past the hour # Hours between: Start_hour = "07" End_hour = "18" # Mins Between: Start_mins = "11" #submins takes the last digit of the minutes Eg "15" would become "5" which allows us to run the pump every 10 mins at 5,15,25... mins Start_submins = "1" #Duration for pump (In mins) Duration_mins = 1 # Grab the current datetime which will be used to work out when to turn the pump on d = datetime.now() initYear = "%04d" % (d.year) initMonth = "%02d" % (d.month) initDate = "%02d" % (d.day) initHour = "%02d" % (d.hour) initMins = "%02d" % (d.minute) status = "Nothing!" submin = initMins[-1:] #flash an LED to show its working! print "---" pifacedigital.leds[7].turn_on() ## Turn on time.sleep(1) print "---" pifacedigital.leds[7].turn_off() ## Turn off time.sleep(1) print "---" pifacedigital.leds[7].turn_on() ## Turn on time.sleep(1) print "---" pifacedigital.leds[7].turn_off() ## Turn off time.sleep(1) print "Current Time :",time.strftime('%d-%m-%Y %H:%M') date = time.strftime('%d-%m-%Y %H:%M') if initHour >= Start_hour and initHour <= End_hour: print "---Within the hour rules..." if submin == Start_submins: #or.... if initMins == Start_mins: print "---Within the minute rules..." print "---Turning on the Pump!!" #Turn on the pump pfio.digital_write(1,1) #Write pin 1 high time.sleep(Duration_mins*60) #Turn it off after the desired period pfio.digital_write(1,0) #Write pin 1 low print "---Turning off the Pump!!" status = "Pump on:" f = open("/var/www/test.txt", 'a') f.write(" ") f.write(status) f.write(" ") f.write(date+"\n") f.close() else: print "---Outside the minute rules..." print "---leaving the pump off..." #do nothing! pfio.digital_write(1,0) #Write pin 1 low #time.sleep(30) status = "No pump (Outside the minute rules):" else: print "---Outside the hour rules" print "---leaving the pump off..." #check the pump is off... pfio.digital_write(1,0) #Write pin 1 low status = "No pump (Outside the hour rules):" #do nothing! #Print full output to the log (Inc on and Off status) #f = open("/var/www/test.txt", 'a') #f.write(" ") #f.write(status) #f.write(" ") #f.write(date+"\n") #f.close()