-
Notifications
You must be signed in to change notification settings - Fork 8
/
example.py
62 lines (42 loc) · 1.59 KB
/
example.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
import time
from isy994.controller import Controller
url = '192.168.1.127'
#url = None # use autodiscovery
dimmer_address = '14 26 A6 1' # dimmer to flash on/off
#dimmer_address = '42 C8 99 1' # dimmer to flash on/off
#dimmer_address = '0 5A B8 1' # switch to flash on/off
switch_address = '0 5A B8 1' # switch to flash on/off
dimmer = None
switch = None
def isy_event_handler(container,item,event,*args):
if container.container_type == 'Device':
print ('Event {} from {}: {} {}'.format(event,container.container_type,item.name,*args))
if container.container_type == 'Device' and event == 'add' and item.address == dimmer_address:
global dimmer
dimmer = item
if container.container_type == 'Device' and event == 'add' and item.address == switch_address:
global switch
#switch = item
c = None
try:
c = Controller(url,username='admin',password='admin',use_https=False,event_handler=isy_event_handler)
while True:
if dimmer is not None:
success, response = dimmer.set_level (0)
#print ("dimmer {} ---------- {}".format(success, response))
if switch is not None:
print ("switch {} {}".format(switch.turn_off()))
time.sleep(10)
if dimmer is not None:
dimmer.set_level (20)
#dimmer.get_status()
if switch is not None:
switch.turn_on()
#switch.get_status()
time.sleep(10)
except KeyboardInterrupt:
print("KeyboardInterrupt has been caught.")
c.close()
print ('Closed session')
finally:
print ('Done')