-
Notifications
You must be signed in to change notification settings - Fork 0
/
garage-rgb-led.yaml
466 lines (386 loc) · 12.5 KB
/
garage-rgb-led.yaml
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
esphome:
name: garage-rgb-led
platform: ESP8266
board: d1_mini
wifi:
ssid: "WiFi_SSID"
password: "WiFi_Password123"
ap:
ssid: "garagentorWiFi"
password: "123456789"
captive_portal:
logger:
api:
ota:
password: "TopSecretSuperPasswort"
globals:
# -----------------------------
# -------- CONFIG START -------
# -----------------------------
# Breite des Balkens bei Animationen der LEDs
- id: ANIM_BREITE
type: int
restore_value: no
initial_value: '15'
# Geschwindigkeit der Animation (kleiner = schneller)
- id: DEFAULT_DELAY
type: int
restore_value: no
initial_value: '14'
# Angabe wie viele Sekunden die Spots anbleiben sollen
- id: shutoff_delay_spots
type: int
restore_value: no
initial_value: '120'
# -----------------------------
# -------- CONFIG ENDE --------
# -----------------------------
# INTERNE VARIABLEN! NICHT ÄNDERN!
- id: led_pos
type: int
restore_value: no
initial_value: '0'
- id: forward
type: bool
restore_value: no
initial_value: 'true'
script:
# Programmablauf während Tor sich öffnet
- id: door_opening
mode: restart
then:
- script.execute: stop_running_end_scripts
- light.turn_on:
id: garagentor_leds
effect: "Tor in Bewegung"
- delay: 60s
- light.turn_off:
id: garagentor_leds
# Programmablauf wenn Tor vollständig geöffnet wurde
- id: door_opened
mode: restart
then:
- script.execute: stop_running_moving_scripts
- light.turn_on:
id: garagentor_leds
effect: "Tor fertig"
- delay: 11s
- light.turn_on:
id: garagentor_leds
effect: "Activate Spots"
- delay: !lambda 'return id(shutoff_delay_spots)*1000;'
- light.turn_off: garagentor_leds
# Programmablauf während Tor sich schließt
- id: door_closing
mode: restart
then:
- script.execute: stop_running_end_scripts
- light.turn_on:
id: garagentor_leds
effect: "Tor in Bewegung"
- delay: 60s
- light.turn_off:
id: garagentor_leds
# Programmablauf wenn Tor vollständig geschlossen wurde
- id: door_closed
mode: restart
then:
- script.execute: stop_running_moving_scripts
- light.turn_on:
id: garagentor_leds
effect: "Tor fertig"
- delay: 11s
- light.turn_on:
id: garagentor_leds
effect: "Activate Spots"
- delay: !lambda 'return id(shutoff_delay_spots)*1000;'
- light.turn_off: garagentor_leds
# ggf. aktive Scripte stoppen
- id: stop_running_end_scripts
mode: restart
then:
- if:
condition:
- script.is_running: door_opened
then:
- script.stop: door_opened
- if:
condition:
- script.is_running: door_closed
then:
- script.stop: door_closed
- id: stop_running_moving_scripts
mode: restart
then:
- if:
condition:
- script.is_running: door_opening
then:
- script.stop: door_opening
- if:
condition:
- script.is_running: door_closing
then:
- script.stop: door_closing
switch:
# Relais für Signal an Motor
# mit on_turn_on automatisch wieder abschalten
- platform: gpio
name: "Carport Tor"
id: garagentor_tor_relais
pin: D7
on_turn_on:
- delay: 1s
- switch.turn_off: garagentor_tor_relais
binary_sensor:
# Reed-Kontakt für Tor vollständig geöffnet
- platform: gpio
name: "Carport Tor Offen"
device_class: garage_door
id: garagentor_tor_open_sensor
pin:
number: D5
inverted: true
filters:
- delayed_off: 500ms
- delayed_on: 100ms
on_release:
- text_sensor.template.publish:
id: garagentor_tor_status
state: "Geöffnet"
- script.execute: door_opened
on_press:
- text_sensor.template.publish:
id: garagentor_tor_status
state: "Tor schließt sich"
- script.execute: door_closing
# Reed-Kontakt für Tor vollständig geschlossen
- platform: gpio
name: "Carport Tor geschlossen"
device_class: garage_door
id: garagentor_tor_closed_sensor
pin:
number: D6
inverted: true
filters:
- delayed_off: 500ms
- delayed_on: 100ms
on_release:
- text_sensor.template.publish:
id: garagentor_tor_status
state: "Geschlossen"
- script.execute: door_closed
on_press:
- text_sensor.template.publish:
id: garagentor_tor_status
state: "Tor öffnet sich"
- script.execute: door_opening
# Taster zur manuellen Bedienung des Tores
# schaltet bei Druck das Relais
- platform: gpio
name: "Garagentor Tor Taster"
id: garagentor_tor_btn
pin: D1
filters:
- delayed_off: 500ms
on_press:
then:
- switch.turn_on: garagentor_tor_relais
on_release:
then:
- switch.turn_off: garagentor_tor_relais
text_sensor:
- platform: template
name: "Garagentor Tor-Status"
id: garagentor_tor_status
lambda: |-
if(!id(garagentor_tor_closed_sensor).state){
return {"Geschlossen"};
} else if (!id(garagentor_tor_open_sensor).state){
return {"Geöffnet"};
} else {
return {"In Bewegung"};
}
update_interval: 120s
light:
- platform: neopixelbus
type: GRB
variant: WS2812
name: "Garagentor LEDs"
id: garagentor_leds
pin: D2
num_leds: 150
default_transition_length: 1s
restore_mode: ALWAYS_OFF
effects:
- addressable_rainbow:
name: Rainbow
speed: 10
width: 20
# Animation: 2 rote Blöcke laufen entgegengesetzt hin und her
- addressable_lambda:
name: "Tor in Bewegung"
update_interval: 16ms
lambda: |-
static const int16_t LAST = it.size()-1;
static int16_t pos2 = 0;
if (initial_run) {
id(led_pos) = 0;
id(forward) = true;
}
pos2 = LAST - id(ANIM_BREITE) - id(led_pos) +1;
if(id(forward)){
if(id(led_pos) > 0){
it[id(led_pos)-1] = ESPColor(0,0,0);
it[pos2+id(ANIM_BREITE)] = ESPColor(0,0,0);
}
it.range(id(led_pos), id(led_pos) + id(ANIM_BREITE)) = ESPColor(255,0,0);
it.range(pos2, pos2 + id(ANIM_BREITE)) = ESPColor(255,0,0);
if(id(led_pos) < (LAST - id(ANIM_BREITE)) + 1){
id(led_pos)++;
} else {
id(forward) = false;
}
} else {
if(id(led_pos) < (LAST - id(ANIM_BREITE)) +1){
it[id(led_pos)+id(ANIM_BREITE)] = ESPColor(0,0,0);
it[pos2-1] = ESPColor(0,0,0);
}
it.range(id(led_pos), id(led_pos) + id(ANIM_BREITE)) = ESPColor(255,0,0);
it.range(pos2, pos2 + id(ANIM_BREITE)) = ESPColor(255,0,0);
if(id(led_pos) > 0){
id(led_pos)--;
} else {
id(forward) = true;
}
}
delay(id(DEFAULT_DELAY));
# Animation:
# - LEDs blenden von aussen nach innen vollständig auf rot
# - LEDs blenden über in grün
- addressable_lambda:
name: "Tor fertig"
update_interval: 16ms
lambda: |-
static const int16_t LAST = it.size()-1;
static boolean prepare = true;
static boolean blendInRed = true;
static int16_t pos2 = 0;
static uint8_t r = 255;
if (initial_run) {
r = 255;
blendInRed = true;
prepare = id(led_pos)>0;
}
pos2 = LAST - id(ANIM_BREITE) - id(led_pos) +1;
if(prepare){
if(id(forward)){
if(id(led_pos) > 0){
it[id(led_pos)-1] = ESPColor(0,0,0);
it[pos2+id(ANIM_BREITE)] = ESPColor(0,0,0);
}
it.range(id(led_pos), id(led_pos) + id(ANIM_BREITE)) = ESPColor(255,0,0);
it.range(pos2, pos2 + id(ANIM_BREITE)) = ESPColor(255,0,0);
if(id(led_pos) < (LAST - id(ANIM_BREITE)) +1){
id(led_pos)++;
} else {
id(forward) = false;
}
} else {
if(id(led_pos) < (LAST - id(ANIM_BREITE)) +1){
it[id(led_pos)+id(ANIM_BREITE)] = ESPColor(0,0,0);
it[pos2-1] = ESPColor(0,0,0);
}
it.range(id(led_pos), id(led_pos) + id(ANIM_BREITE)) = ESPColor(255,0,0);
it.range(pos2, pos2 + id(ANIM_BREITE)) = ESPColor(255,0,0);
if(id(led_pos) > 0){
id(led_pos)--;
} else {
prepare = false;
}
}
delay(id(DEFAULT_DELAY));
} else {
if(blendInRed){
it.range(id(led_pos), id(led_pos) + id(ANIM_BREITE)) = ESPColor(r,0,0);
it.range(pos2, pos2 + id(ANIM_BREITE)) = ESPColor(r,0,0);
if(id(led_pos) < (LAST - id(ANIM_BREITE)) +1){
id(led_pos)++;
} else {
blendInRed = false;
}
delay(id(DEFAULT_DELAY));
} else {
it.all() = ESPColor(r, 255-r, 0);
if(r>0){
r=r-5;
}
delay(2);
}
}
# Animation:
# - LEDs blenden in 4 Schritten vollständig auf Weißes Licht ein
# (Lauflicht mit abwechselnder Richtung, wobei jeder Durchlauf heller wird)
# - Überblendung zu Spots durch weiße laufende Spots die die vollständige Beleuchtung "ausradieren"
- addressable_lambda:
name: "Activate Spots"
update_interval: 16ms
lambda: |-
static const int16_t LAST = it.size()-1;
static boolean forward = true;
static boolean ready = false;
static int16_t pos2 = 0;
static int16_t colorVal = 0;
if (initial_run) {
ready = false;
id(led_pos) = 0;
colorVal = 127;
}
pos2 = LAST - id(ANIM_BREITE) - id(led_pos) +1;
if(!ready){
if(forward){
it.range(id(led_pos), id(led_pos) + id(ANIM_BREITE)) = ESPColor(colorVal, colorVal, colorVal);
it.range(pos2, pos2 + id(ANIM_BREITE)) = ESPColor(colorVal, colorVal, colorVal);
if(id(led_pos) < (LAST/2) - id(ANIM_BREITE) +1){
id(led_pos)++;
} else {
forward = false;
colorVal = colorVal+64;
}
} else {
it.range(id(led_pos), id(led_pos) + id(ANIM_BREITE)) = ESPColor(colorVal, colorVal, colorVal);
it.range(pos2, pos2 + id(ANIM_BREITE)) = ESPColor(colorVal, colorVal, colorVal);
if(id(led_pos) > 0){
id(led_pos)--;
} else {
forward = true;
colorVal = colorVal+64;
if(colorVal >= 191){
ready = true;
}
}
}
} else {
if(forward){
it.range(id(led_pos), id(led_pos) + id(ANIM_BREITE)) = ESPColor(255,255,255);
it.range(pos2, pos2 + id(ANIM_BREITE)) = ESPColor(255,255,255);
if(id(led_pos) < (LAST - id(ANIM_BREITE)*2) + 1){
if(id(led_pos) > 0){
it[id(led_pos)-1] = ESPColor(0,0,0);
it[pos2+id(ANIM_BREITE)] = ESPColor(0,0,0);
}
id(led_pos)++;
} else {
if(id(led_pos) < (LAST - id(ANIM_BREITE)) +1){
it[id(led_pos)+id(ANIM_BREITE)] = ESPColor(0,0,0);
it[pos2-1] = ESPColor(0,0,0);
}
it.range(id(led_pos), id(led_pos) + id(ANIM_BREITE)) = ESPColor(255,255,255);
it.range(pos2, pos2 + id(ANIM_BREITE)) = ESPColor(255,255,255);
if(id(led_pos) > id(ANIM_BREITE)+1){
id(led_pos)--;
}
}
}
}
delay(id(DEFAULT_DELAY));