-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgarage.py
97 lines (81 loc) · 3.03 KB
/
garage.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""
Author: Originally Surendra Kane
Edited by: shrocky2
Script to control your Garge Door using an Amazon Echo.
"""
import fauxmo
import logging
import time
#GPIO Added Information
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
pinList = [7, 11, 13, 15]
for i in pinList:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.HIGH)
time.sleep(.5)
#End GPIO Added Information
from debounce_handler import debounce_handler
logging.basicConfig(level=logging.DEBUG)
print " Control+C to exit program"
#Edit this section to personalize your TV Channels. The channel number is listed after each station.
#----------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------
channels = {'Garage Door':10001,
'Item 1':10002,
'Item 2':10003,
'Item 3':10004,
'Item 4':10005}
#----------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------
class device_handler(debounce_handler):
"""Triggers on/off based on 'device' selected.
Publishes the IP address of the Echo making the request.
"""
TRIGGERS = {"Garage Door":50001,
"Item 1":50002,
"Item 2":50003,
"Item 3":50004,
"Item 4":50005}
def trigger(self,port,state):
if state == True: #If the ON command is given, it will run this code
if port == 10001: #Open/Close Garage Door
GPIO.output(7, GPIO.LOW)
time.sleep(1)
GPIO.output(7, GPIO.HIGH)
print "Open Garage Door"
print " "
else: #If the OFF command is given, it will run this code
if port == 10001: #Open/Close Garage Door
GPIO.output(7, GPIO.LOW)
time.sleep(1)
GPIO.output(7, GPIO.HIGH)
print "Open Garage Door"
print " "
def act(self, client_address, state, name):
print "State", state, "on", name, "from client @", client_address, "port:",channels[str(name)]
self.trigger(channels[str(name)],state)
return True
if __name__ == "__main__":
# Startup the fauxmo server
fauxmo.DEBUG = True
p = fauxmo.poller()
u = fauxmo.upnp_broadcast_responder()
u.init_socket()
p.add(u)
# Register the device callback as a fauxmo handler
d = device_handler()
for trig, port in d.TRIGGERS.items():
fauxmo.fauxmo(trig, u, p, None, port, d)
# Loop and poll for incoming Echo requests
logging.debug("Entering fauxmo polling loop")
print " "
while True:
try:
# Allow time for a ctrl-c to stop the process
p.poll(100)
time.sleep(0.1)
except Exception, e:
logging.critical("Critical exception: " + str(e))
break