I have a program to control lots of the things about my hen house including opening and closing the door at set times. Occasionally something happens and the door doesn't open or close and I have now got it to send an email when this happens. The problem is it will send 6 or more emails and I have been trying to work out how to limit it to send only one which is possible using while or if - but then I need to re-set it so that if happens again on another day it will send another email. This is the loop that I have
def loop():
# retrieve current datetime
now = datetime.time(datetime.datetime.now().hour, datetime.datetime.now().minute)
# Open door on all days at the correct time
if ((now.hour == HOUR_ON.hour) and (now.minute == HOUR_ON.minute)):
if (gpio.digitalRead(17) == 0):
openplay()
# Close door on all days at the correct time
if ((now.hour == HOUR_OFF.hour) and (now.minute == HOUR_OFF.minute)):
if (gpio.digitalRead(22) == 1):
closeplay()
# check if door is open, 2 minutes after set time
if ((now.hour == HOUR_ON.hour) and (now.minute == HOUR_ON.minute + 120) and (now.second == 0) and (gpio.digitalRead(25) == 0)):
# send email
sendemail()
# check if door is closed, 2 minutes after set time
if ((now.hour == HOUR_OFF.hour) and (now.minute == HOUR_OFF.minute + 120) and (now.second == 0) and (gpio.digitalRead(25) == 1)):
# send email
sendemail()
# gives CPU some time before looping again
webiopi.sleep(1)
This is just a hobby and I put together things from mostly searching but can't crack this so would appreciate any help with it