1
|
|
|
from datetime import datetime |
2
|
|
|
|
3
|
|
|
from PyDMXControl import Colors |
4
|
|
|
from PyDMXControl.controllers import uDMXController as Controller |
5
|
|
|
from PyDMXControl.profiles.Eyourlife import Small_Flat_Par |
6
|
|
|
from PyDMXControl.profiles.Stairville import LED_Par_10mm, LED_Par_36 |
7
|
|
|
|
8
|
|
|
# This is my home setup, which also acts as a great demo of some of what this library is capable of doing. |
9
|
|
|
# See the tests directory for other recent/new features that I've possibly been working on. |
10
|
|
|
|
11
|
|
|
# Create our controller |
12
|
|
|
dmx = Controller() |
13
|
|
|
|
14
|
|
|
# Load some fixtures from JSON |
15
|
|
|
dmx.json.load_config('json/home.json') |
16
|
|
|
|
17
|
|
|
""" |
18
|
|
|
dmx.add_fixture(LED_Par_10mm, name="Flood") |
19
|
|
|
|
20
|
|
|
dmx.add_fixture(LED_Par_36, name="S1 Art Left") |
21
|
|
|
dmx.add_fixture(LED_Par_36, name="S2 Board") |
22
|
|
|
dmx.add_fixture(LED_Par_36, name="S3 Art Right") |
23
|
|
|
dmx.add_fixture(LED_Par_36, name="S4 Books") |
24
|
|
|
|
25
|
|
|
dmx.add_fixture(Small_Flat_Par, name="F1 Desk Right") |
26
|
|
|
dmx.add_fixture(Small_Flat_Par, name="F2 Desk Left") |
27
|
|
|
""" |
28
|
|
|
|
29
|
|
|
# Define all the methods the callback will use |
30
|
|
|
custom_blue = [0, 16, 255] |
31
|
|
|
custom_white = [255, 140, 70] |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
def normal(): |
35
|
|
|
for f in dmx.get_fixtures_by_profile(LED_Par_10mm): |
36
|
|
|
f.color(Colors.Warm, 10000) |
37
|
|
|
|
38
|
|
|
# Chase.group_apply(dmx.get_fixtures_by_profile(LED_Par_36), 15 * 1000, colors=[Colors.Blue, Colors.Cyan]) |
39
|
|
|
for f in dmx.get_fixtures_by_profile(LED_Par_36): |
40
|
|
|
f.color(custom_blue, 10000) |
41
|
|
|
|
42
|
|
|
for f in dmx.get_fixtures_by_profile(Small_Flat_Par): |
43
|
|
|
f.color(custom_white, 10000) |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
def dimmer(): |
47
|
|
|
for f in dmx.get_fixtures_by_profile(LED_Par_10mm): |
48
|
|
|
f.color(Colors.Black, 10000) |
49
|
|
|
|
50
|
|
|
# dmx.clear_all_effects() |
51
|
|
|
for f in dmx.get_fixtures_by_profile(LED_Par_36): |
52
|
|
|
f.color(custom_blue, 10000) |
53
|
|
|
|
54
|
|
|
for f in dmx.get_fixtures_by_profile(Small_Flat_Par): |
55
|
|
|
f.color(Colors.Warm, 10000) |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
# Timed lights |
59
|
|
|
last_state = None |
60
|
|
|
last_state_type = None |
61
|
|
|
times = [ |
62
|
|
|
[(700, 740), (1600, 2200)], # Monday |
63
|
|
|
[(700, 740), (1600, 2200)], # Tuesday |
64
|
|
|
[(700, 740), (1330, 2200)], # Wednesday |
65
|
|
|
[(700, 740), (1600, 2200)], # Thursday |
66
|
|
|
[(700, 740), (1330, 2200)], # Friday |
67
|
|
|
[(800, 2200)], # Saturday |
68
|
|
|
[(800, 2200)], # Sunday |
69
|
|
|
] |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
# Create the callback to turn lights on/off and change colors at certain times |
73
|
|
|
def callback(): |
74
|
|
|
global last_state, last_state_type, times |
75
|
|
|
|
76
|
|
|
# Get limits for today an current time |
77
|
|
|
time_limit = times[datetime.today().weekday()] |
78
|
|
|
time = int(datetime.today().strftime('%H%M')) |
79
|
|
|
|
80
|
|
|
# Check if current time is within limits |
81
|
|
|
in_range = False |
82
|
|
|
for time_range in time_limit: |
83
|
|
|
if time_range[0] <= time <= time_range[1]: |
84
|
|
|
in_range = True |
85
|
|
|
|
86
|
|
|
# On if within limits else off |
87
|
|
|
if in_range: |
88
|
|
|
if last_state != 1: |
89
|
|
|
dmx.all_on(10000) |
90
|
|
|
last_state = 1 |
91
|
|
|
else: |
92
|
|
|
if last_state != 0: |
93
|
|
|
dmx.all_off(10000) |
94
|
|
|
last_state = 0 |
95
|
|
|
|
96
|
|
|
# Dim the lights before/after certain times |
97
|
|
|
if time >= 2100 or time <= 715: |
98
|
|
|
if last_state_type != 1: |
99
|
|
|
dimmer() |
100
|
|
|
last_state_type = 1 |
101
|
|
|
else: |
102
|
|
|
if last_state_type != 0: |
103
|
|
|
normal() |
104
|
|
|
last_state_type = 0 |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
# Enable the callback |
108
|
|
|
dmx.ticker.set_interval(500) |
109
|
|
|
dmx.ticker.set_callback(callback) |
110
|
|
|
|
111
|
|
|
# Debug |
112
|
|
|
callbacks = { |
113
|
|
|
"normal": normal, |
114
|
|
|
"dimmer": dimmer |
115
|
|
|
} |
116
|
|
|
dmx.web_control(callbacks=callbacks) |
117
|
|
|
# dmx.debug_control(callbacks) |
118
|
|
|
|
119
|
|
|
# Close the controller once we're done |
120
|
|
|
dmx.sleep_till_enter() |
121
|
|
|
dmx.close() |
122
|
|
|
|