-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelay-app.py
executable file
·75 lines (64 loc) · 1.94 KB
/
relay-app.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
import requests
import json
import time
import relay
api_key=""
id1_max=25
id2_max=25
id3_max=25
id1_min=24
id2_min=24
id3_min=24
def temperature_request(api_url):
query_url = api_url
r = requests.get(query_url)
if r.status_code != 200:
print "Error:", r.status_code
json_resp = r.json()
id_temp = float(json_resp['temp_1'])
return id_temp
def run_ac_control():
while True:
try:
id1_temp = temperature_request('http://temp1.local:4444')
id2_temp = temperature_request('http://temp2.local:4446')
id3_temp = temperature_request('http://temp3.local:4447')
relay.trigger_relay(False, 17)
relay.trigger_relay(False, 27)
relay.trigger_relay(False, 22)
if id1_temp >= id1_max and id2_temp >= id2_max and id3_temp >= id3_max:
print("Compressor on")
relay.trigger_relay(False, 23)
relay.trigger_relay(False, 24)
relay.trigger_relay(False, 25)
elif id1_temp <= id1_min and id2_temp <= id2_min and id3_temp <= id3_min:
print("Compressor off")
relay.trigger_relay(True, 23)
relay.trigger_relay(True, 24)
relay.trigger_relay(True, 25)
print("Temp1:"+str(id1_temp))
print("Temp2:"+str(id2_temp))
print("Temp3:"+str(id3_temp))
time.sleep(5)
except requests.exceptions.RequestException as err:
print ("OOps: Something Else",err)
time.sleep(5)
continue
except requests.exceptions.HTTPError as errh:
print ("Http Error:",errh)
time.sleep(5)
continue
except requests.exceptions.ConnectionError as errc:
print ("Error Connecting:",errc)
time.sleep(5)
continue
except requests.exceptions.Timeout as errt:
print ("Timeout Error:",errt)
time.sleep(5)
continue
except KeyboardInterrupt:
print "Quit"
#relay.trigger_relay(True)
if __name__ == '__main__':
run_ac_control()