-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.yaml
More file actions
586 lines (516 loc) · 14.4 KB
/
main.yaml
File metadata and controls
586 lines (516 loc) · 14.4 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
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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
esphome:
name: ${name}
on_boot:
- priority: 500
then:
- delay: 66ms
- if:
condition:
binary_sensor.is_on: zone_input
then:
- script.execute:
id: set_effect
type: restore
mode: set
- switch.turn_on: shunt
else:
- script.execute:
id: set_effect
type: restore
mode: restore
- if:
condition:
binary_sensor.is_on: presignal_input
then:
- script.execute: set_presignal
esp32:
board: esp32doit-devkit-v1
#board: esp32dev
framework:
type: esp-idf
external_components:
- source:
type: local
path: components
components: [sequencer]
sequencer:
text_sensor:
- platform: template
name: "Current Effect"
id: "current_effect"
- platform: template
name: "Set Effect"
id: status_effect
- platform: template
name: "Set Effect Type"
id: status_effect_type
button:
- platform: safe_mode
name: Safe Mode Boot
entity_category: diagnostic
- name: Fire Up
id: fire_up
platform: template
on_press:
- script.execute:
id: set_effect
mode: up
type: fire
- name: Fire Down
id: fire_down
platform: template
on_press:
- script.execute:
id: set_effect
mode: down
type: fire
- name: March Up
id: march_up
platform: template
on_press:
- script.execute:
id: set_effect
type: march
mode: up
- name: March Down
id: march_down
platform: template
on_press:
- script.execute:
id: set_effect
type: march
mode: down
- name: Code Up
id: code_up
platform: template
on_press:
- script.execute:
id: set_effect
type: code
mode: up
- name: Code Down
id: code_down
platform: template
on_press:
- script.execute:
id: set_effect
type: code
mode: down
output:
- platform: gpio
pin: ${gpio_code}
id: gpio_code
- platform: gpio
pin: ${gpio_led}
id: gpio_led
inverted: ${gpio_led_invert}
# Template output that mirrors to LED
- platform: template
id: code_output
type: binary
write_action:
- if:
condition:
lambda: 'return state;'
then:
- output.turn_on: gpio_code
- output.turn_on: gpio_led
else:
- output.turn_off: gpio_code
- output.turn_off: gpio_led
switch:
- name: Toggle
id: toggle
platform: template
lambda: 'return (id(shunt).state);'
turn_on_action:
- if:
condition:
binary_sensor.is_on: presignal_input
then:
- script.execute: set_presignal
else:
- script.execute:
id: set_effect
type: restore
mode: set
- delay: 66ms
- switch.turn_on: shunt
turn_off_action:
- if:
condition:
binary_sensor.is_on: in_presignal
then:
- script.execute:
id: set_effect
type: restore
mode: set
else:
- light.turn_off: code
- platform: gpio
pin: ${gpio_reverse}
id: reverse
name: reverse
on_turn_on:
- if:
condition:
lambda: 'return id(code).get_effect_name() == "None";'
then:
- delay: 5000ms
- switch.turn_off: reverse
- platform: gpio
pin: ${gpio_shunt}
id: shunt
name: shunt
on_turn_on:
- if:
condition:
lambda: 'return id(code).get_effect_name() == "None";'
then:
- delay: 5000ms
- switch.turn_off: shunt
- platform: gpio
pin: ${gpio_trigger}
id: trigger
name: trigger
on_turn_on:
- if:
condition:
lambda: 'return id(code).get_effect_name() == "None";'
then:
- delay: 5000ms
- switch.turn_off: trigger
light:
- platform: binary
output: code_output
id: code
name: code
on_state:
- text_sensor.template.publish:
id: current_effect
state: !lambda 'return id(code).get_effect_name();'
- if:
condition:
lambda: 'return id(code).get_effect_name() == "None" && ! id(code).current_values.is_on();'
then:
- switch.turn_off: shunt
- switch.turn_off: reverse
- switch.turn_off: trigger
- globals.set:
id: alarm_active
value: 'false'
- globals.set:
id: presignal_active
value: 'false'
- delay: 10ms
- if:
condition:
lambda: 'return id(code).get_effect_name() == "None" && id(code).current_values.is_on();'
then:
- delay: 5000ms
- light.turn_off: code
globals:
- id: alarm_active
type: bool
restore_value: no
initial_value: 'false'
- id: presignal_active
type: bool
restore_value: no
initial_value: 'false'
- id: effect_type
type: short
restore_value: yes
initial_value: '0'
- id: effect
type: short
restore_value: yes
initial_value: '0'
- id: fire_effects
type: std::vector<std::string>
restore_value: no
initial_value: 'std::vector<std::string>{}'
- id: march_effects
type: std::vector<std::string>
restore_value: no
initial_value: 'std::vector<std::string>{}'
- id: code_effects
type: std::vector<std::string>
restore_value: no
initial_value: 'std::vector<std::string>{}'
- id: firecom_effects
type: std::vector<std::string>
restore_value: no
initial_value: 'std::vector<std::string>{}'
- id: doorbell_effects
type: std::vector<std::string>
restore_value: no
initial_value: 'std::vector<std::string>{}'
# Display navigation
- id: display_screen
type: short
restore_value: no
initial_value: '0'
- id: display_screens
type: std::vector<std::string>
restore_value: no
initial_value: 'std::vector<std::string>{"Status", "Effects"}'
# Extension screen data (populated by modules that add screens)
- id: display_ext_header
type: std::string
restore_value: no
initial_value: '""'
- id: display_ext_header_right
type: std::string
restore_value: no
initial_value: '""'
- id: display_ext_inverted
type: bool
restore_value: no
initial_value: 'false'
- id: display_ext_lines
type: std::vector<std::string>
restore_value: no
initial_value: 'std::vector<std::string>{}'
# Right-aligned text for each line (rendered at fixed pixel position)
- id: display_ext_lines_right
type: std::vector<std::string>
restore_value: no
initial_value: 'std::vector<std::string>{}'
script:
- id: set_effect
parameters:
type: std::string
mode: std::string
then:
- lambda: |-
id(reverse).turn_off();
id(trigger).turn_off();
struct effects {
int id;
std::string type;
std::vector<std::string> list;
};
effects effects_map[] {
{ 0, "fire", id(fire_effects) },
{ 1, "march", id(march_effects) },
{ 2, "code", id(code_effects) },
{ 3, "firecom", id(firecom_effects) },
{ 4, "doorbell", id(doorbell_effects) }
};
effects effect_map;
for ( auto value : effects_map ){
if (type == value.type || (type == "restore" && id(effect_type) == value.id )) {
effect_map = value;
break;
}
}
// Safety check: fallback to fire_effects if list is empty
if (effect_map.list.empty()) {
effect_map = { 0, "fire", id(fire_effects) };
}
// If still empty, bail out - no effects available for this type
if (effect_map.list.empty()) {
ESP_LOGW("set_effect", "No effects available for type: %s", type.c_str());
return;
}
int next_id;
bool not_found = (id(effect_type) == effect_map.id && id(effect) < (int)effect_map.list.size())
? find(effect_map.list.begin(), effect_map.list.end(), effect_map.list[id(effect)]) == effect_map.list.end()
: true;
if (mode == "up" && (not_found || id(effect) - 1 < 0)) {
next_id = effect_map.list.size() - 1;
} else if (mode == "up") {
next_id = id(effect) - 1;
} else if (mode == "down" && (not_found || id(effect) + 1 >= (int)effect_map.list.size())) {
next_id = 0;
} else if (mode == "down") {
next_id = id(effect) + 1;
} else {
next_id = id(effect);
}
// Bounds check next_id
if (next_id < 0 || next_id >= (int)effect_map.list.size()) {
next_id = 0;
}
std::string next_effect = effect_map.list[next_id];
//ESP_LOGD("status", "set_effect - type: %s - mode: %s - list size: %i - item %s - effect: %s", type.c_str(), mode.c_str(), effect_map.list.size(), not_found ? "not found" : "found", next_effect.c_str());
if (mode != "restore") {
auto call = id(code).turn_on();
call.set_effect(next_effect);
call.perform();
id(alarm_active) = true;
}
id(effect_type) = effect_map.id;
id(effect) = next_id;
id(status_effect).publish_state(next_effect);
id(status_effect_type).publish_state(effect_map.type);
- id: set_presignal
then:
- light.turn_on:
id: code
effect: PreSignal
- switch.turn_on: shunt
- globals.set:
id: presignal_active
value: 'true'
# Navigate display screens (menu up/down)
- id: menu_navigate
parameters:
direction: std::string
then:
- lambda: |-
int screen_count = id(display_screens).size();
if (screen_count == 0) return;
int current = id(display_screen);
if (direction == "up") {
current = (current - 1 + screen_count) % screen_count;
} else if (direction == "down") {
current = (current + 1) % screen_count;
}
id(display_screen) = current;
ESP_LOGD("menu", "Screen: %s (%d/%d)",
id(display_screens)[current].c_str(), current + 1, screen_count);
# Cycle effect type (fire/march/code/doorbell) - skips empty types
- id: type_cycle
parameters:
direction: std::string
then:
- lambda: |-
std::vector<std::string>* effect_lists[] = {
&id(fire_effects),
&id(march_effects),
&id(code_effects),
&id(firecom_effects),
&id(doorbell_effects)
};
int type_count = 5;
int current = id(effect_type);
int step = (direction == "up") ? -1 : 1;
// Find next non-empty type
for (int i = 0; i < type_count; i++) {
current = (current + step + type_count) % type_count;
if (!effect_lists[current]->empty()) {
break;
}
}
id(effect_type) = current;
- script.execute:
id: set_effect
type: restore
mode: set
# Extension handlers - modules extend these to handle their screens
- id: ext_type_handler
parameters:
direction: std::string
then: []
- id: ext_select_handler
parameters:
direction: std::string
then: []
# Type button handlers (shared by all button input methods)
- id: type_button
parameters:
direction: std::string
then:
- lambda: |-
if (id(display_screen) >= 2) {
// Extended screen - let modules handle it
id(ext_type_handler).execute(direction);
} else {
// Screens 0-1: cycle effect type
id(type_cycle).execute(direction);
}
# Select button handlers (shared by all button input methods)
- id: select_button
parameters:
direction: std::string
then:
- lambda: |-
if (id(display_screen) >= 2) {
// Extended screen - let modules handle it
id(ext_select_handler).execute(direction);
} else {
// Screens 0-1: scroll effects
id(set_effect).execute("restore", direction);
}
binary_sensor:
- name: In Alarm
id: in_alarm
platform: template
lambda: 'return (id(alarm_active) && id(shunt).state);'
on_press:
- globals.set:
id: presignal_active
value: 'false'
- name: In PreSignal
id: in_presignal
platform: template
lambda: 'return (id(presignal_active) && id(shunt).state);'
- name: PreSignal Input
id: presignal_input
platform: gpio
pin:
number: ${gpio_presignal}
inverted: ${gpio_presignal_invert}
mode:
input: true
pullup: ${gpio_presignal_pullup}
filters:
- delayed_on: 10ms
- delayed_off: 100ms
on_press:
- if:
condition:
binary_sensor.is_off: zone_input
then:
- script.execute: set_presignal
on_release:
- if:
condition:
binary_sensor.is_off: zone_input
then:
- light.turn_off: code
- name: Zone Input
id: zone_input
platform: gpio
pin:
number: ${gpio_zone}
inverted: ${gpio_zone_invert}
mode:
input: true
pullup: true
filters:
- delayed_on: 10ms
- delayed_off: 100ms
on_press:
- script.execute:
id: set_effect
type: restore
mode: set
- delay: 66ms
- switch.turn_on: shunt
on_release:
- light.turn_off: code
# Enable logging
logger:
level: DEBUG
baud_rate: 0
# Enable Home Assistant API
api:
reboot_timeout: 0s
encryption:
key: !secret api_key
ota:
- platform: esphome
password: !secret ota_password
wifi:
reboot_timeout: 0s
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
# ap:
# ssid: !secret wifi_portal_ssid
# password: !secret wifi_portal_password
#
#captive_portal: