-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallclock.py
executable file
·221 lines (192 loc) · 7.77 KB
/
wallclock.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
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
#!/usr/bin/env python3
from rgbmatrix import graphics, RGBMatrix, RGBMatrixOptions
from PIL import Image, ImageDraw, ImageFont
import time
from timewidget import TimeWidget
from secondswidget import SecondsWidget
from datewidget import DateWidget
from sunwidget import SunWidget
from mqttclient import MqttClient
from temperaturewidget import TemperatureWidget, HumidityWidget, AirQualityWidget, NumberWidget
from countdownwidget import CountdownWidget
from pingwidget import PingWidget
from framealert import FrameAlert, ImageAlert, UnicodeAlert
from fensterwidget import FensterWidget, MovementWidget
from onoffbrightness import OnOffBrightness
from house import House
import json
haustuerOffen = ImageAlert(y=22,howlong=30,filename="images/door-5-64.png")
esKlingelt = ImageAlert(y=22,howlong=10,filename="images/bell-64.png")
telefon = UnicodeAlert(y=22, howlong=30, size=35,description="black telephone", color=(255,0,0))
esRegnet = UnicodeAlert(y=22, howlong=600, size=24,description="CLOUD WITH RAIN", color=(0,96,255))
matrixBrightness = 100
def tuerklingelAlert(topic,msg):
global esKligelt
esKlingelt.on()
def haustuerAlert(topic,msg):
global haustuerOffen
haustuerOffen.on()
def setBrightness(topic,msg):
global matrixBrightness
newBrightness = int(msg)
if newBrightness >= 0 and newBrightness <= 255:
matrixBrightness = int(msg)
def dasTelefonKlingelt(topic,msg):
global telefon
telefon.on()
def regenAlert(topic,msg):
global esRegnet
v = int(msg.decode())
if v > 15000:
esRegnet.on()
else:
esRegnet.off()
def regenTropfen(topic,msg):
global esRegnet, rainfall
v = float(msg.decode())
if v > 0.0:
esRegnet.on()
rainfall.update(number=v,off=False)
else:
esRegnet.off()
rainfall.update(number=v,off=True)
if __name__ == "__main__":
options = RGBMatrixOptions()
options.rows = 64
options.cols = 64
options.hardware_mapping = "adafruit-hat-pwm"
options.pwm_bits = 7
options.drop_privileges = False
matrix = RGBMatrix(options = options)
ch5 = House()
ch5.addFloor("2.OG",2)
ch5.addFloor("1.OG",1)
ch5.addFloor("EG",0)
ch5.addFloor("Keller",-1)
ch5.addFloor("Aussen",-2)
ch5.addRoom("Arbeitszimmer","2.OG")
ch5.addRoom("Bad2","2.OG")
ch5.addRoom("Loggia","2.OG")
ch5.addRoom("RaspiBox","2.OG")
ch5.addRoom("3DPrinter","2.OG")
ch5.addRoom("2OG-Loggia","2.OG")
ch5.addRoom("2OG-Flur","2.OG")
ch5.addRoom("1OG-Flur","1.OG")
ch5.addRoom("Schlafzimmer","1.OG")
ch5.addRoom("Bad1","1.OG")
ch5.addRoom("Ankleidezimmer","1.OG")
ch5.addRoom("Wohnzimmer","EG")
ch5.addRoom("Mobile","EG")
ch5.addRoom("Kueche","EG")
ch5.addRoom("Fenster","EG")
ch5.addRoom("EG-Flur","EG")
ch5.addRoom("Heizraum","Keller")
ch5.addRoom("Keller","Keller")
ch5.addRoom("Kellerabgang","Keller")
ch5.addRoom("Fernsehzimmer","Keller")
ch5.addRoom("Keller-Flur","Keller")
ch5.addRoom("Hausanschlussraum","Keller")
ch5.addRoom("Garten","Aussen")
ch5.addRoom("Vorgarten","Aussen")
mytime = TimeWidget(x=0,y=0,color=(0,255,0))
mydate= DateWidget(x=0,y=11,color=(128,128,255))
mycountdown = CountdownWidget(x=0,y=30,size=13,bigat=10)
myseconds = SecondsWidget(x=0,y=0,color=(100,100,0))
gardentemp = TemperatureWidget(x = 45, y = 58, size = 7)
loggiatemp = TemperatureWidget(x = 22, y = 58, size = 7)
vorgartentemp = TemperatureWidget(x = 0, y = 58, size = 7)
arbeitszimmertemp = TemperatureWidget(x = 0, y = 50, size = 7)
arbeitszimmerhum = HumidityWidget(x = 20, y = 50, size = 7)
arbeitszimmerqual = AirQualityWidget(x = 30, y = 50, size = 7)
rainfall = NumberWidget(x=25,y=25,size=7,color=(0,96,255))
pingrouter = PingWidget(x=0,y=63,target="fw01.ch5.garf.de",every=30,color=(0,0,0))
astro = SunWidget(x=46,y=1,size=18)
allefenster = FensterWidget(x=62,y=19,size=2)
motion = MovementWidget(x=60,y=19,size=2)
setbrightness = OnOffBrightness()
aussentemperatur = TemperatureWidget(x=0,y=25,size=12)
widgetlist = []
widgetlist.append(mytime)
widgetlist.append(astro)
widgetlist.append(mydate)
widgetlist.append(myseconds)
widgetlist.append(gardentemp)
widgetlist.append(vorgartentemp)
widgetlist.append(arbeitszimmertemp)
widgetlist.append(arbeitszimmerhum)
widgetlist.append(arbeitszimmerqual)
widgetlist.append(loggiatemp)
widgetlist.append(pingrouter)
widgetlist.append(haustuerOffen)
widgetlist.append(telefon)
widgetlist.append(esKlingelt)
widgetlist.append(esRegnet)
widgetlist.append(allefenster)
widgetlist.append(motion)
widgetlist.append(aussentemperatur)
widgetlist.append(rainfall)
client = MqttClient()
client.subscribe("/Chattenweg5/Garten/temperature",gardentemp.update)
# client.subscribe("/Chattenweg5/Garten/rain",regenAlert)
client.subscribe("/Chattenweg5/2OG-Loggia/sensor/sensor/rain_intensity/state",regenTropfen)
client.subscribe("/Chattenweg5/Vorgarten/temperature",vorgartentemp.update)
client.subscribe("/Chattenweg5/Arbeitszimmer/temperature",arbeitszimmertemp.update)
client.subscribe("/Chattenweg5/Arbeitszimmer/humidity",arbeitszimmerhum.update)
client.subscribe("/Chattenweg5/Arbeitszimmer/CO2",arbeitszimmerqual.update)
client.subscribe("/Chattenweg5/2OG-Loggia/temperature",loggiatemp.update)
client.subscribe("/Wallclock/Countdown",mycountdown.mqttstart)
client.subscribe("/Wallclock/countdown",mycountdown.mqttstart)
client.subscribe("/Chattenweg5/Wallclock/Countdown",mycountdown.mqttstart)
client.subscribe("/Chattenweg5/Wallclock/countdown",mycountdown.mqttstart)
client.subscribe("Chattenweg5/Tuerklingel",tuerklingelAlert)
client.subscribe("Chattenweg5/Fenster/Haustuer",haustuerAlert)
client.subscribe("/Wallclock/Brightness",setBrightness)
client.subscribeRegex("/Chattenweg5/+/motion","/Chattenweg5/.*/motion",motion.mqtthandler)
client.subscribe("/Chattenweg5/Arbeitszimmer/light",setbrightness.mqttlight)
client.subscribe("/Chattenweg5/Residents",setbrightness.mqtthome)
client.subscribe("Chattenweg5/Phone",dasTelefonKlingelt)
client.subscribeRegex("/Chattenweg5/#","/Chattenweg5/.*",ch5.mqtthandler)
while True:
change = False
for w in widgetlist:
w.update()
if w.changed:
change = True
# countdown timer disables date
if mycountdown.started:
mycountdown.started = False
try:
# widgetlist.remove(mydate)
widgetlist.append(mycountdown)
except ValueError:
pass
elif mycountdown.cancelled:
mycountdown.cancelled = False
# widgetlist.append(mydate)
widgetlist.remove(mycountdown)
elif mycountdown.ended:
mycountdown.ended = False
# widgetlist.append(mydate)
widgetlist.remove(mycountdown)
flasher = FrameAlert()
for i in range(5):
flasher.blinkon()
im.alpha_composite(flasher.image)
matrix.SetImage(im.convert("RGB"))
time.sleep(0.1)
flasher.blinkoff()
im.alpha_composite(flasher.image)
matrix.SetImage(im.convert("RGB"))
time.sleep(0.1)
if (setbrightness.changed):
matrix.brightness = setbrightness.brightness
setbrightness.changed=False
print("brightness = ",matrix.brightness)
change = True
if change:
im = Image.new("RGBA",(64,64))
for w in widgetlist:
im.alpha_composite(w.image)
w.changed = False
matrix.SetImage(im.convert("RGB"))
time.sleep(0.5)