-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlight-control.py~
More file actions
57 lines (44 loc) · 2 KB
/
light-control.py~
File metadata and controls
57 lines (44 loc) · 2 KB
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
import time
from binascii import unhexlify
import serial
PORT = "/dev/ttyUSB0"
ser = serial.Serial(PORT)
lights = [["Dirty Lab", "26", "labs"], ["Clean Lab Cabinets", "3", "labs"], ["Clean Lab", "4", "labs"], ["South West Bedroom", "6", "living"], ["Downstairs Bedroom", "7", "living"], ["North West Bedroom", "9", "living"], ["North East Bedroom", "21", "living"], ["South East Bedroom", "28", "living"], ["West Balcony", "35", "outside"], ["Front Porch", "35", "outside"], ["Back Porch", "36", "outside"], ["Kitchen", "11", "community"], ["Front Indoor Lights", "12", "community"], ["White Board Lights", "31", "community"], ["Kitchen Cabinets", "38", "community"], ["Main Room", "11", "community"], ["Media Room", "20", "community"], ["Upper Floor", "0", "community"], ["East Upper Bathroom", "17", "bathrooms"], ["West Upper Bathroom", "15", "bathrooms"], ["West Lower Bathroom", "13", "bathrooms"]];
settings = dict()
settings["ON"] = ["182","\\05380079"]
settings["OFF"] = ["62","\\05380001"]
def change(status, whichLights):
if (status != "ON"):
status = "OFF"
for light in whichLights:
tempHex = light
if (len(str(light)) == 1):
tempHex = "0" + tempHex
chksum = bin((int(settings[status][0]) + int(light)) % 256 ).replace("0b","")
newsum = ""
for i in list(str(chksum)):
if i=="1":
newsum += "0"
else:
newsum += "1"
cSum = hex(1+int(newsum,2)).replace("0x","")
fullStr = (settings[status][1] + tempHex + cSum).upper()
finalStr = ""
for i in list(fullStr):
finalStr+=hex(ord(i[0])).replace("0x","")
finalStr+="0D"
ser.write(unhexlify(finalStr))
return finalStr
#
# \ans = "["
for i in range(200):
#ser.write(r"\053800011A28")
change("OFF", ["4"])
print("OFF")
time.sleep(1)
#ser.write(r"\053800011A28")
change("ON", ["26"])
print("On")
time.sleep(1)
print(change("ON", ["26"]).encode())
ser.write(change("OFF", ["26"]).encode())