configuration.yaml
Kopieren 1 esphome :
2 name : led - strip - controller
3 friendly_name : LED Strip Controller
4
5 esp32 :
6 board : esp32 - c3 - devkitm - 1
7 framework :
8 type : esp - idf
9
10 logger :
11
12 api :
13
14 ota :
15 - platform : esphome
16
17 wifi :
18 networks :
19 - ssid : !secret wifi_ssid
20 password : !secret wifi_password
21 min_auth_mode : WPA2
22 output_power : 20dB
23 power_save_mode : none
24 manual_ip :
25 static_ip : 192.168.178.151
26 gateway : 192.168.178.1
27 subnet : 255.255.255.0
28 ap :
29 ssid : "LED-Strip-Fallback"
30 password : "fallback1234"
31
32 captive_portal :
33
34 web_server :
35
36 # ── Mikrofon-Schalter ──────────────────────────────────────────────────────────
37 switch :
38 - platform : template
39 id : mic_enabled
40 name : "Mikrofon aktiv"
41 optimistic : true
42 restore_mode : RESTORE_DEFAULT_OFF
43
44 # ── Globale Variablen ──────────────────────────────────────────────────────────
45 globals :
46 - id : effect_index
47 type : int
48 restore_value : no
49 initial_value : '0'
50 - id : brightness_val
51 type : float
52 restore_value : no
53 initial_value : '1.0'
54 - id : effect_speed
55 type : int
56 restore_value : no
57 initial_value : '10'
58
59 # ── ADC-Sensor (Mikrofon) ──────────────────────────────────────────────────────
60 sensor :
61 - platform : adc
62 pin : GPIO0
63 id : mic_adc
64 name : "Microphone ADC"
65 update_interval : never
66 attenuation : auto
67 filters :
68 - exponential_moving_average :
69 alpha : 0.8
70 send_every : 1
71
72 # ── Intervall: ADC nur abfragen wenn Mikrofon aktiv ───────────────────────────
73 interval :
74 - interval : 20ms
75 then :
76 - if :
77 condition :
78 switch.is_on : mic_enabled
79 then :
80 - component.update : mic_adc
81
82 # ── LED Strip ──────────────────────────────────────────────────────────────────
83 light :
84 - platform : esp32_rmt_led_strip
85 id : strip
86 name : "LED Strip"
87 pin : GPIO2
88 num_leds : 160
89 rgb_order : BRG
90 rmt_symbols : 64
91 bit0_high : 350ns
92 bit0_low : 900ns
93 bit1_high : 800ns
94 bit1_low : 350ns
95 reset_high : 0us
96 reset_low : 300us
97 max_refresh_rate : 12ms
98 default_transition_length : 0s
99 restore_mode : RESTORE_DEFAULT_OFF
100
101 on_turn_off :
102 - switch.turn_off : mic_enabled
103
104 effects :
105 - addressable_rainbow :
106 name : "Rainbow"
107 speed : 10
108 width : 50
109 - addressable_color_wipe :
110 name : "Color Wipe"
111 - addressable_scan :
112 name : "Scan"
113 - addressable_twinkle :
114 name : "Twinkle"
115 - addressable_fireworks :
116 name : "Fireworks"
117 - addressable_lambda :
118 name : "Sound Reactive"
119 update_interval : 20ms
120 lambda : | -
121 float v = id(mic_adc).state;
122 float intensity = 0.0f;
123 if (v > 0.04f) {
124 intensity = (v - 0.04f) / 0.21f;
125 }
126 if (intensity > 1.0f) intensity = 1.0f;
127 static float hue = 0.0f;
128 static float last_intensity = 0.0f;
129 if (intensity > last_intensity + 0.01f) {
130 hue += 25.0f;
131 if (hue > = 360.0f) hue - = 360.0f;
132 }
133 last_intensity = intensity;
134 float h = hue / 60.0f;
135 int hi = (int)h % 6;
136 float f = h - (int)h;
137 uint8_t v8 = (uint8_t)(intensity * 255);
138 uint8_t p = 0;
139 uint8_t q = (uint8_t)(intensity * (1.0f - f) * 255);
140 uint8_t t8 = (uint8_t)(intensity * f * 255);
141 Color c;
142 if (hi == 0) c = Color(v8 , t8 , p);
143 else if (hi == 1) c = Color(q , v8 , p);
144 else if (hi == 2) c = Color(p , v8 , t8);
145 else if (hi == 3) c = Color(p , q , v8);
146 else if (hi == 4) c = Color(t8 , p , v8);
147 else c = Color(v8 , p , q);
148 it.all() = c;
149
150 # ── Buttons ────────────────────────────────────────────────────────────────────
151 binary_sensor :
152 - platform : gpio
153 id : btn_1
154 name : "Button 1"
155 pin :
156 number : GPIO3
157 mode : INPUT_PULLUP
158 inverted : true
159 on_press :
160 - light.turn_on :
161 id : strip
162 effect : "none"
163 - light.turn_on :
164 id : strip
165 red : !lambda "return random_float();"
166 green : !lambda "return random_float();"
167 blue : !lambda "return random_float();"
168
169 - platform : gpio
170 id : btn_2
171 name : "Button 2"
172 pin :
173 number : GPIO6
174 mode :
175 input : true
176 pullup : true
177 inverted : true
178 filters :
179 - delayed_on : 10ms
180 - delayed_off : 10ms
181 on_press :
182 - light.toggle : strip
183 on_multi_click :
184 - timing :
185 - ON for at least 800ms
186 then :
187 - switch.turn_on : mic_enabled
188 - light.turn_on :
189 id : strip
190 effect : "Sound Reactive"
191
192 - platform : gpio
193 id : btn_3
194 name : "Button 3"
195 pin :
196 number : GPIO7
197 mode :
198 input : true
199 pullup : true
200 inverted : true
201 on_press :
202 - lambda : | -
203 id(effect_index) = (id(effect_index) + 1) % 5;
204 - if :
205 condition :
206 lambda : "return id(effect_index) == 0;"
207 then :
208 - light.turn_on :
209 id : strip
210 effect : "Rainbow"
211 - if :
212 condition :
213 lambda : "return id(effect_index) == 1;"
214 then :
215 - light.turn_on :
216 id : strip
217 effect : "Color Wipe"
218 - if :
219 condition :
220 lambda : "return id(effect_index) == 2;"
221 then :
222 - light.turn_on :
223 id : strip
224 effect : "Scan"
225 - if :
226 condition :
227 lambda : "return id(effect_index) == 3;"
228 then :
229 - light.turn_on :
230 id : strip
231 effect : "Twinkle"
232 - if :
233 condition :
234 lambda : "return id(effect_index) == 4;"
235 then :
236 - light.turn_on :
237 id : strip
238 effect : "Fireworks"
239
240 # ── IR-Empfänger ───────────────────────────────────────────────────────────────
241 remote_receiver :
242 pin :
243 number : GPIO4
244 inverted : true
245 mode :
246 input : true
247 pullup : true
248 filter : 50us
249 idle : 20ms
250 #dump: nec #zum IR Code auslesen
251 on_nec :
252 # ── ON ────────────────────────────────────────────────────────────────────
253 - if :
254 condition :
255 lambda : 'return x.address == 0xFBE2 && x.command == 0xD926;'
256 then :
257 - light.turn_on : strip
258
259 # ── OFF ───────────────────────────────────────────────────────────────────
260 - if :
261 condition :
262 lambda : 'return x.address == 0xFBE2 && x.command == 0xDA25;'
263 then :
264 - light.turn_off : strip
265
266 # ── ROT ───────────────────────────────────────────────────────────────────
267 - if :
268 condition :
269 lambda : 'return x.address == 0xFBE2 && x.command == 0xF906;'
270 then :
271 - light.turn_on :
272 id : strip
273 effect : "none"
274 red : 1.0
275 green : 0.0
276 blue : 0.0
277
278 # ── GRÜN ──────────────────────────────────────────────────────────────────
279 - if :
280 condition :
281 lambda : 'return x.address == 0xFBE2 && x.command == 0xF708;'
282 then :
283 - light.turn_on :
284 id : strip
285 effect : "none"
286 red : 0.0
287 green : 1.0
288 blue : 0.0
289
290 # ── BLAU ──────────────────────────────────────────────────────────────────
291 - if :
292 condition :
293 lambda : 'return x.address == 0xFBE2 && x.command == 0xA55A;'
294 then :
295 - light.turn_on :
296 id : strip
297 effect : "none"
298 red : 0.0
299 green : 0.0
300 blue : 1.0
301
302 # ── WEISS ─────────────────────────────────────────────────────────────────
303 - if :
304 condition :
305 lambda : 'return x.address == 0xFBE2 && x.command == 0xE51A;'
306 then :
307 - light.turn_on :
308 id : strip
309 effect : "none"
310 red : 1.0
311 green : 1.0
312 blue : 1.0
313
314 # ── HELLIGKEIT + ──────────────────────────────────────────────────────────
315 - if :
316 condition :
317 lambda : 'return x.address == 0xFBE2 && x.command == 0xF00F;'
318 then :
319 - lambda : | -
320 auto call = id(strip).make_call();
321 float b = id(strip).current_values.get_brightness();
322 b = min(b + 0.1f , 1.0f);
323 call.set_brightness(b);
324 call.perform();
325
326 # ── HELLIGKEIT - ──────────────────────────────────────────────────────────
327 - if :
328 condition :
329 lambda : 'return x.address == 0xFBE2 && x.command == 0x916E;'
330 then :
331 - lambda : | -
332 auto call = id(strip).make_call();
333 float b = id(strip).current_values.get_brightness();
334 b = max(b - 0.1f , 0.1f);
335 call.set_brightness(b);
336 call.perform();
337
338 # ── AUTO → Rainbow ────────────────────────────────────────────────────────
339 - if :
340 condition :
341 lambda : 'return x.address == 0xFBE2 && x.command == 0xD22D;'
342 then :
343 - light.turn_on :
344 id : strip
345 effect : "Rainbow"
346
347 # ── MODE + (nächster Effekt) ───────────────────────────────────────────────
348 - if :
349 condition :
350 lambda : 'return x.address == 0xFBE2 && x.command == 0xF40B;'
351 then :
352 - lambda : | -
353 id(effect_index) = (id(effect_index) + 1) % 5;
354 - if :
355 condition :
356 lambda : "return id(effect_index) == 0;"
357 then :
358 - light.turn_on :
359 id : strip
360 effect : "Rainbow"
361 - if :
362 condition :
363 lambda : "return id(effect_index) == 1;"
364 then :
365 - light.turn_on :
366 id : strip
367 effect : "Color Wipe"
368 - if :
369 condition :
370 lambda : "return id(effect_index) == 2;"
371 then :
372 - light.turn_on :
373 id : strip
374 effect : "Scan"
375 - if :
376 condition :
377 lambda : "return id(effect_index) == 3;"
378 then :
379 - light.turn_on :
380 id : strip
381 effect : "Twinkle"
382 - if :
383 condition :
384 lambda : "return id(effect_index) == 4;"
385 then :
386 - light.turn_on :
387 id : strip
388 effect : "Fireworks"
389
390 # ── MODE - (vorheriger Effekt) ─────────────────────────────────────────────
391 - if :
392 condition :
393 lambda : 'return x.address == 0xFBE2 && x.command == 0xF50A;'
394 then :
395 - lambda : | -
396 id(effect_index) = (id(effect_index) + 4) % 5;
397 - if :
398 condition :
399 lambda : "return id(effect_index) == 0;"
400 then :
401 - light.turn_on :
402 id : strip
403 effect : "Rainbow"
404 - if :
405 condition :
406 lambda : "return id(effect_index) == 1;"
407 then :
408 - light.turn_on :
409 id : strip
410 effect : "Color Wipe"
411 - if :
412 condition :
413 lambda : "return id(effect_index) == 2;"
414 then :
415 - light.turn_on :
416 id : strip
417 effect : "Scan"
418 - if :
419 condition :
420 lambda : "return id(effect_index) == 3;"
421 then :
422 - light.turn_on :
423 id : strip
424 effect : "Twinkle"
425 - if :
426 condition :
427 lambda : "return id(effect_index) == 4;"
428 then :
429 - light.turn_on :
430 id : strip
431 effect : "Fireworks"
432
433 # ── QUICK (Rainbow schneller) ──────────────────────────────────────────────
434 - if :
435 condition :
436 lambda : 'return x.address == 0xFBE2 && x.command == 0xA45B;'
437 then :
438 - lambda : | -
439 id(effect_speed) = min(id(effect_speed) + 5 , 50);
440 - light.turn_on :
441 id : strip
442 effect : "Rainbow"
443
444 # ── SLOW (Rainbow langsamer) ───────────────────────────────────────────────
445 - if :
446 condition :
447 lambda : 'return x.address == 0xFBE2 && x.command == 0xA35C;'
448 then :
449 - lambda : | -
450 id(effect_speed) = max(id(effect_speed) - 5 , 1);
451 - light.turn_on :
452 id : strip
453 effect : "Rainbow"
454
455 # ── MUSIK LINKS → Sound Reactive ──────────────────────────────────────────
456 - if :
457 condition :
458 lambda : 'return x.address == 0xFBE2 && x.command == 0xFE01;'
459 then :
460 - switch.turn_on : mic_enabled
461 - light.turn_on :
462 id : strip
463 effect : "Sound Reactive"
464
465 # ── MUSIK RECHTS → Zufällige Farbe ────────────────────────────────────────
466 - if :
467 condition :
468 lambda : 'return x.address == 0xFBE2 && x.command == 0xFD02;'
469 then :
470 - light.turn_on :
471 id : strip
472 effect : "none"
473 - light.turn_on :
474 id : strip
475 red : !lambda "return random_float();"
476 green : !lambda "return random_float();"
477 blue : !lambda "return random_float();"
478
479 text_sensor :
480 - platform : version
481 name : "ESPHome Version"