Hello All,
I have a raspberry pi zero w outside in my wifes garden. It has a couple relays that control water valves and a button that I use to allow her to manually water it in addition to my automatic program. This is the code for the manual watering. Last year it worked well, Any time I pushed the button it would turn on and water. This year it doesnt seem to be working. I have another program that uses the same GPIO pins to automatically water the garden at 12:00 pm. At 12:30 pm the system reboots. This program as you see below runs at boot. If I push the button shortly after it reboots then it works. If I wait say 5 or 6 hours and push the button...it doenst work. It does have a lockout so that it can only be pushed once per day....this is so the kids dont water it too much. Any advice appreciated.
I have a raspberry pi zero w outside in my wifes garden. It has a couple relays that control water valves and a button that I use to allow her to manually water it in addition to my automatic program. This is the code for the manual watering. Last year it worked well, Any time I pushed the button it would turn on and water. This year it doesnt seem to be working. I have another program that uses the same GPIO pins to automatically water the garden at 12:00 pm. At 12:30 pm the system reboots. This program as you see below runs at boot. If I push the button shortly after it reboots then it works. If I wait say 5 or 6 hours and push the button...it doenst work. It does have a lockout so that it can only be pushed once per day....this is so the kids dont water it too much. Any advice appreciated.
Code:
import gpiozerofrom gpiozero import Button,OutputDeviceimport timeimport message as sendmailfrom signal import pause# Lenth of time to water manuallymanual_time=2manual_time2=5#Initialize buttonbutton=Button(6)#Send Feedback to notify that program is activatedtime.sleep(3)#sendmail.send_message("Your manual watering button is ready","7708536981")time.sleep(3)#Manual Watering Functiondef manual():global waterCountglobal waterCount2valve=gpiozero.OutputDevice(26)valve2=gpiozero.OutputDevice(4)#sendmail.send_message("Anna pushed the buton","7708536981")if valve.value!=True and waterCount<1:valve.on()time.sleep(1)#sendmail.send_message('The valve is on and the current valve state is: %s' % valve.value,"7708536981")time.sleep(manual_time*60)valve.off()#sendmail.send_message("the valve is off and the current valve state is: %s" % valve.value,"7708536981")#sendmail.send_message("Watering Complete","7708536981")valve.close()waterCount+=1else:#sendmail.send_message("The garden was already watered today","7708536981")print("Garden already watered today")time.sleep(5)if valve2.value!=True and waterCount2<1:valve2.on()time.sleep(1)#sendmail.send_message('The valve is on and the current valve state is: %s' % valve2.value, "7708536981")time.sleep(manual_time2*60)valve2.off()#sendmail.send_message("The valve is off and the current valve state is: %s" % valve2.value,"7708536981")#sendmail.send_message("Watering Complete","7708536981")valve2.close()waterCount2+=1else:#sendmail.send_message("The garden was already watered today", "7708536981")print("Garden already watered today")# set initial waterCountwaterCount=0waterCount2=0#Listen for Button Pressbutton.when_pressed=manualpause()
Statistics: Posted by Crimson0087 — Fri Jun 07, 2024 12:29 am