-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosram_control.py
More file actions
360 lines (287 loc) · 10.2 KB
/
osram_control.py
File metadata and controls
360 lines (287 loc) · 10.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
from lightify import Lightify
import time
import random
import argparse
import sys
parser = argparse.ArgumentParser('Group Lighting Control')
parser.add_argument("-g", "--group", action='store', help="Enter the name of the group")
parser.add_argument("-l", "--light", action='store', help="Enter the name of a light in the group")
parser.add_argument("-a", "--action", nargs=1, help="Valid Actions are on, off, dim, bright, color, temp_up, temp_down, temp_min, temp_max")
if not sys.argv[1:]:
sys.argv.extend(['-h'])
args = parser.parse_args(sys.argv[1:])
# the group should contain at least two lights
GATEWAY_ADDR = "192.168.1.13"
#LIGHT1 = 'Great Room 01'
LIGHT1 = args.light
#GROUP_NAME = 'Great Room'
GROUP_NAME = args.group
TIME = 0
print(args)
gateway = Lightify(GATEWAY_ADDR)
gateway.update_all_light_status()
gateway.update_group_list()
if args.group is not None:
group = gateway.groups()[GROUP_NAME]
lights = ([gateway.lights()[addr] for addr in group.lights()])
light = gateway.light_byname(LIGHT1)
class groups():
def red():
group.set_rgb(255, 0, 0, TIME)
groups.COLOR_CHOICE = 'Red'
def lime():
group.set_rgb(0, 255, 0, TIME)
groups.COLOR_CHOICE = 'Lime'
def blue():
group.set_rgb(0, 0, 255, TIME)
groups.COLOR_CHOICE = 'Blue'
def yellow():
group.set_rgb(255, 255, 0, TIME)
groups.COLOR_CHOICE = 'Yellow'
def aqua():
group.set_rgb(0, 255, 255, TIME)
groups.COLOR_CHOICE = 'Agua'
def magenta():
group.set_rgb(255, 0, 255, TIME)
groups.COLOR_CHOICE = 'Magenta'
def silver():
group.set_rgb(192, 192, 192, TIME)
groups.COLOR_CHOICE = 'Silver'
def gray():
group.set_rgb(128, 128, 128, TIME)
groups.COLOR_CHOICE = 'Gray'
def maroon():
group.set_rgb(128, 0, 0, TIME)
groups.COLOR_CHOICE = 'Maroon'
def olive():
group.set_rgb(128, 128, 0, TIME)
groups.COLOR_CHOICE = 'Olive'
def green():
group.set_rgb(0, 128, 0, TIME)
groups.COLOR_CHOICE = 'Green'
def purple():
group.set_rgb(128, 0, 128, TIME)
groups.COLOR_CHOICE = 'Purple'
def teal():
group.set_rgb(0, 128, 128, TIME)
groups.COLOR_CHOICE = 'Teal'
def navy():
group.set_rgb(0, 0, 128 , TIME)
groups.COLOR_CHOICE = 'Navy'
def temp_up():
old_on, old_lum, old_temp, old_r, old_g, old_b = gateway.update_light_status(light)
global groups_temp
if old_temp < 5801:
for i in range(old_temp, old_temp + 500, 100):
group.set_temperature(i, 0)
groups_temp = i
else:
groups_temp = old_temp
print("Already at Max")
def temp_down():
old_on, old_lum, old_temp, old_r, old_g, old_b = gateway.update_light_status(light)
global groups_temp
if old_temp > 2700:
for i in range(old_temp, old_temp - 500, -100):
group.set_temperature(i, 0)
groups_temp = i
else:
groups_temp = old_temp
print("Already at Min")
def temp_max():
group.set_temperature(6500, 0)
global groups_temp
groups_temp = 6500
def temp_min():
group.set_temperature(2200, 0)
global groups_temp
groups_temp = 2200
def dim():
old_on, old_lum, old_temp, old_r, old_g, old_b = gateway.update_light_status(light)
global groups_level
if old_lum > 20:
for i in range(old_lum, old_lum - 20, -5):
group.set_luminance(i, 0)
groups_level = i
time.sleep(0.5)
else:
groups_level = old_lum
print("Already at Min")
def bright():
old_on, old_lum, old_temp, old_r, old_g, old_b = gateway.update_light_status(light)
global groups_level
if old_lum < 100:
for i in range(old_lum, old_lum + 20, 5):
group.set_luminance(i, 0)
groups_level = i
time.sleep(0.5)
else:
groups_level = old_lum
print("Already at Max")
def on():
group.set_temperature(2500, 0)
group.set_luminance(100, 0)
group.set_onoff(1)
def off():
group.set_onoff(0)
def color():
random.choice(GROUP_COLORS)()
GROUP_COLORS = [groups.red, groups.lime, groups.blue, groups.yellow, groups.aqua, groups.magenta, groups.silver,
groups.gray, groups.maroon, groups.olive, groups.green, groups.purple, groups.teal, groups.navy]
class single():
def red():
light.set_rgb(255, 0, 0, TIME)
single.COLOR_CHOICE = 'Red'
def lime():
light.set_rgb(0, 255, 0, TIME)
single.COLOR_CHOICE = 'Lime'
def blue():
light.set_rgb(0, 0, 255, TIME)
single.COLOR_CHOICE = 'Blue'
def yellow():
light.set_rgb(255, 255, 0, TIME)
single.COLOR_CHOICE = 'Yellow'
def aqua():
light.set_rgb(0, 255, 255, TIME)
single.COLOR_CHOICE = 'Aqua'
def magenta():
light.set_rgb(255, 0, 255, TIME)
single.COLOR_CHOICE = 'Magenta'
def silver():
light.set_rgb(192, 192, 192, TIME)
single.COLOR_CHOICE = 'Silver'
def gray():
light.set_rgb(128, 128, 128, TIME)
single.COLOR_CHOICE = 'Gray'
def maroon():
light.set_rgb(128, 0, 0, TIME)
single.COLOR_CHOICE = 'Maroon'
def olive():
light.set_rgb(128, 128, 0, TIME)
single.COLOR_CHOICE = 'Olive'
def green():
light.set_rgb(0, 128, 0, TIME)
single.COLOR_CHOICE = 'Green'
def purple():
light.set_rgb(128, 0, 128, TIME)
single.COLOR_CHOICE = 'Purple'
def teal():
light.set_rgb(0, 128, 128, TIME)
single.COLOR_CHOICE = 'Teal'
def navy():
light.set_rgb(0, 0, 128 , TIME)
single.COLOR_CHOICE = 'Navy'
def temp_up():
old_on, old_lum, old_temp, old_r, old_g, old_b = gateway.update_light_status(light)
global single_temp
if old_temp < 5801:
for i in range(old_temp, old_temp + 500, 100):
light.set_temperature(i, 0)
single_temp = i
else:
single_temp = old_temp
print("Already at Max")
def temp_down():
old_on, old_lum, old_temp, old_r, old_g, old_b = gateway.update_light_status(light)
global single_temp
if old_temp > 2700:
for i in range(old_temp, old_temp - 500, -100):
light.set_temperature(i, 0)
single_temp = i
else:
single_temp = old_temp
print("Already at Min")
def temp_max():
light.set_temperature(6500, 0)
global single_temp
single_temp = 6500
def temp_min():
light.set_temperature(2200, 0)
global single_temp
single_temp = 2200
def dim():
old_on, old_lum, old_temp, old_r, old_g, old_b = gateway.update_light_status(light)
global single_level
if old_lum > 20:
for i in range(old_lum, old_lum - 20, -5):
light.set_luminance(i, 0)
single_level = i
time.sleep(0.5)
else:
single_level = old_lum
print("Already at Min")
def bright():
old_on, old_lum, old_temp, old_r, old_g, old_b = gateway.update_light_status(light)
global single_level
if old_lum < 100:
for i in range(old_lum, old_lum + 20, 5):
light.set_luminance(i, 0)
single_level = i
time.sleep(0.5)
else:
single_level = old_lum
print("Already at Max")
def on():
light.set_temperature(2500, 0)
light.set_luminance(100, 0)
light.set_onoff(1)
def off():
light.set_onoff(0)
def color():
random.choice(SINGLE_COLOR)()
SINGLE_COLOR = [single.red, single.lime, single.blue, single.yellow, single.aqua, single.magenta, single.silver, single.gray, single.maroon, single.olive, single.green, single.purple, single.teal, single.navy]
if args.action == ['on'] and args.group is not None:
groups.on()
print(GROUP_NAME, "is now on")
elif args.action == ['on']:
single.on()
print(LIGHT1, "is now on")
if args.action == ['off'] and args.group is not None:
groups.off()
print(GROUP_NAME, "is now off")
elif args.action == ['off']:
single.off()
print(LIGHT1, "light is now off")
if args.action == ['bright'] and args.group is not None:
groups.bright()
print(GROUP_NAME, "level is now set to", groups_level)
elif args.action == ['bright']:
single.bright()
print(LIGHT1, "level is now set to", single_level)
if args.action == ['dim'] and args.group is not None:
groups.dim()
print(GROUP_NAME, "level is now set to", groups_level)
elif args.action == ['dim']:
single.dim()
print(LIGHT1, "level is now set to", single_level)
if args.action == ['color'] and args.group is not None:
groups.color()
print(GROUP_NAME, "is now", groups.COLOR_CHOICE)
elif args.action == ['color']:
single.color()
print(LIGHT1, "is now", single.COLOR_CHOICE)
if args.action == ['temp_up'] and args.group is not None:
groups.temp_up()
print(GROUP_NAME, "temp has been raised to", groups_temp)
elif args.action == ['temp_up']:
single.temp_up()
print(LIGHT1, "temp has been raised to", single_temp)
if args.action == ['temp_down'] and args.group is not None:
groups.temp_down()
print(GROUP_NAME, "temp has been lowered to", groups_temp)
elif args.action == ['temp_down']:
single.temp_down()
print(LIGHT1, "temp has been lowered to", single_temp)
if args.action == ['temp_min'] and args.group is not None:
groups.temp_min()
print(GROUP_NAME, "is now at minimum levels of", groups_temp)
elif args.action == ['temp_min']:
single.temp_min()
print(LIGHT1, "is now at minimum levels of", single_temp)
if args.action == ['temp_max'] and args.group is not None:
groups.temp_max()
print(GROUP_NAME, "is now at maximum levels of", groups_temp)
elif args.action == ['temp_max']:
single.temp_max()
print(LIGHT1, "is now at maximum levels of", single_temp)
gateway.update_all_light_status()