-
Notifications
You must be signed in to change notification settings - Fork 0
/
dryeriftttnotify.py
60 lines (53 loc) · 1.81 KB
/
dryeriftttnotify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import requests as req
import RPi.GPIO as GPIO
import sys
from time import sleep
import datetime
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(4,GPIO.IN)
GPIO.setup(25,GPIO.OUT)
NotificationSeconds = 300
def CallIfTTT(url,whoto):
response = req.get(url)
if (response.status_code == 200):
print("Message has been sent to " + whoto)
return True
else:
return False
lastnotify = None
while True:
dryerdone = False
if (GPIO.input(4)):
dryerdone = False
else:
dryerdone = True
GPIO.output(25,dryerdone)
cannotify = False
if (lastnotify == None):
cannotify = True
else:
diffvalue = datetime.datetime.now() - lastnotify
if (diffvalue.seconds > NotificationSeconds):
cannotify = True
else:
cannotify = False
if (dryerdone == True and cannotify):
print ("sending ifttt messages")
peggy = CallIfTTT("YOUR MAKER IFTTT.COM URL","peggy")
ken = CallIfTTT("YOUR MAKER IFTTT.COM URL","ken")
if (peggy and ken):
lastnotify = datetime.datetime.now()
print("sent ifttt message at " + lastnotify.strftime("%m/%d/%Y, %H:%M:%S"))
else:
if (dryerdone):
if (lastnotify == None):
print("The Dryer is done but we are trying to reach you.")
else:
print("The Dryer is done but already notified you at: " + lastnotify.strftime("%m/%d/%Y, %H:%M:%S"))
else:
if (lastnotify == None):
print("Waiting for the dryer to be done never notified before.")
else:
print("Waiting for the dryer to be done: " + lastnotify.strftime("%m/%d/%Y, %H:%M:%S"))
sleep(2)