-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsupersensor.yaml
More file actions
2009 lines (1858 loc) · 59.8 KB
/
Copy pathsupersensor.yaml
File metadata and controls
2009 lines (1858 loc) · 59.8 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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
###############################################################################
# SuperSensor v3.0 ESPHome configuration
###############################################################################
#
# Copyright (C) 2025 Joshua M. Boniface <joshua@boniface.me>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
###############################################################################
esphome:
name: supersensor
name_add_mac_suffix: true
friendly_name: "Supersensor"
project:
name: joshuaboniface.supersensor
version: "3.0"
min_version: 2026.3.0
on_boot:
- priority: 600
then:
- light.turn_on:
id: output_led
- delay: 0.25s
- light.turn_off:
id: output_led
- delay: 0.25s
- light.turn_on:
id: output_led
- delay: 0.25s
- light.turn_off:
id: output_led
- lambda: |-
id(supersensor_occupancy).publish_state(false);
id(pir_presence).publish_state(false);
id(light_presence).publish_state(false);
id(radar_presence).publish_state(false);
id(ld2410c_calibration_status).publish_state("Idle");
- priority: -100
then:
- if:
condition:
- switch.is_on: enable_voice_support
then:
- micro_wake_word.start:
preferences:
flash_write_interval: 15sec
dashboard_import:
package_import_url: github://joshuaboniface/supersensor/supersensor.yaml@v3.x
esp32:
variant: esp32s3
flash_size: 8MB
cpu_frequency: 240MHz
framework:
type: esp-idf
psram:
# We use an ESP32-S3-N8R2 as reference
mode: quad
speed: 80MHz
globals:
#
# SHT45 offsets
#
- id: temperature_offset
type: float
restore_value: true
initial_value: "-2.0"
- id: humidity_offset
type: float
restore_value: true
initial_value: "0.0"
#
# Room Health settings
#
- id: room_health_temperature_min
type: float
restore_value: true
initial_value: "21.0"
- id: room_health_temperature_max
type: float
restore_value: true
initial_value: "24.0"
- id: room_health_temperature_penalty
type: float
restore_value: true
initial_value: "10.0"
- id: room_health_humidity_min
type: float
restore_value: true
initial_value: "40.0"
- id: room_health_humidity_max
type: float
restore_value: true
initial_value: "60.0"
- id: room_health_humidity_penalty
type: float
restore_value: true
initial_value: "5.0"
- id: room_health_voc_weight
type: float
restore_value: true
initial_value: "0.4"
- id: room_health_temperature_weight
type: float
restore_value: true
initial_value: "0.3"
- id: room_health_humidity_weight
type: float
restore_value: true
initial_value: "0.3"
#
# PIR settings
#
- id: pir_hold_time
type: int
restore_value: true
initial_value: "15"
#
# Light settings
#
- id: light_presence_threshold
type: int
restore_value: true
initial_value: "30"
#
# Occupancy settings
#
- id: occupancy_detect_mode
type: int
restore_value: true
initial_value: "0"
- id: occupancy_clear_mode
type: int
restore_value: true
initial_value: "0"
#
# API connection tracker
#
- id: last_api_connected_time
type: uint32_t
restore_value: no
initial_value: "0"
#
# LD2410C ACK tracking (for the calibration sequence)
#
- id: ld2410_last_ack_cmd
type: int
restore_value: no
initial_value: "-1"
- id: ld2410_last_ack_status
type: int
restore_value: no
initial_value: "-1"
#
# Wake Word settings
#
- id: current_wake_word
type: std::string
restore_value: yes
initial_value: '"mww_computer"'
#
# LED Brightness settings
#
- id: led_presence_brightness
type: int
restore_value: yes
initial_value: '25'
- id: led_listening_brightness
type: int
restore_value: yes
initial_value: '100'
- id: led_processing_brightness
type: int
restore_value: yes
initial_value: '75'
- id: led_responding_brightness
type: int
restore_value: yes
initial_value: '100'
#
# LED State Machine (priority-based)
#
- id: led_state
type: int
restore_value: no
initial_value: '0' # 0=idle, 1=hold, 2=pipeline
- id: led_substate
type: int
restore_value: no
initial_value: '0' # 0 idle, 1 listen, 2 stt, 3 success, 4 fail
- id: led_hold_until
type: uint32_t
restore_value: no
initial_value: '0'
script:
#
# LED State Machine (priority-based)
#
# Idle -> VA Listening -> VA STT -> VA Responding -> 5s --|
# 0,0 2,1 2,2 1,3/4 | |
# ^ ^ v |
# | |------------------------------------------+ v
# --------------------------------------------------------+
#
- id: led_start
mode: queued
then:
- if:
condition:
lambda: 'return id(led_state)<2;'
then:
# If we're in idle or holding state, just re-render (triggered by holds themselves and idle LED updates)
- script.execute: led_render
else:
# If we're in pipeline state, stop any existing holds and clear them, then re-render
- script.stop: led_hold_timer
- script.execute: led_clear_hold
- script.execute: led_render
- id: led_hold_timer
mode: restart
then:
# Hold execution; delay for 5s, then clear the hold and re-render
- delay: 5s
- script.execute: led_clear_hold
- script.execute: led_render
- id: led_clear_hold
then:
# Clear an existing hold state if applicable
- lambda: |-
if (id(led_state)==1) {
id(led_state)=0;
id(led_substate)=0;
}
- id: led_render
then:
# Render LED colours based on current state and substate
- if:
condition:
lambda: 'return id(led_state)==2 && id(led_substate)==1;'
then:
- script.execute: led_blue
- if:
condition:
lambda: 'return id(led_state)==2 && id(led_substate)==2;'
then:
- script.execute: led_cyan
- if:
condition:
lambda: 'return id(led_state)==1 && id(led_substate)==3;'
then:
- script.execute: led_green
- if:
condition:
lambda: 'return id(led_state)==1 && id(led_substate)==4;'
then:
- script.execute: led_red
- if:
condition:
lambda: 'return id(led_state)==0;'
then:
- if:
condition:
- binary_sensor.is_on: supersensor_occupancy
- switch.is_on: enable_presence_led
then:
- script.execute: led_dim_white
else:
- script.execute: led_off
- id: led_blue
then:
- light.turn_on:
id: output_led
red: 0
green: 0
blue: 1
brightness: !lambda 'return id(led_listening_brightness) / 100.0;'
- id: led_cyan
then:
- light.turn_on:
id: output_led
red: 0
green: 1
blue: 1
brightness: !lambda 'return id(led_processing_brightness) / 100.0;'
- id: led_green
then:
- light.turn_on:
id: output_led
red: 0
green: 1
blue: 0
brightness: !lambda 'return id(led_responding_brightness) / 100.0;'
- id: led_red
then:
- light.turn_on:
id: output_led
red: 1
green: 0
blue: 0
brightness: !lambda 'return id(led_responding_brightness) / 100.0;'
- id: led_dim_white
then:
- light.turn_on:
id: output_led
red: 1
green: 1
blue: 1
brightness: !lambda 'return id(led_presence_brightness) / 100.0;'
- id: led_off
then:
- light.turn_off:
id: output_led
#
# Occupancy handlers
#
- id: pir_handler
then:
- lambda: |-
id(pir_presence).publish_state(true);
- while:
condition:
binary_sensor.is_on: pir_gpio
then:
- delay: !lambda 'return(id(pir_hold_time) * 1000);'
- lambda: |-
id(pir_presence).publish_state(false);
- id: light_handler
then:
- lambda: |-
if (id(tsl2591_lux).state >= id(light_presence_threshold)) {
id(light_presence).publish_state(true);
} else {
id(light_presence).publish_state(false);
}
- id: occupancy_detect_handler
then:
- lambda: |-
ESP_LOGD("occupancy_detect_handler", "Occupancy detect handler triggered");
// Get the current values of our presence sensors
bool pir = id(pir_presence).state;
bool radar = id(radar_presence).state;
bool light = id(light_presence).state;
// Determine if PIR counts (2nd bit of presence_type)
int pir_counts = (id(occupancy_detect_mode) & ( 1 << 2 )) >> 2;
// Determine if Radar counts (1st bit of presence_type)
int radar_counts = (id(occupancy_detect_mode) & ( 1 << 1 )) >> 1;
// Determine if Light counts (0th bit of presence_type)
int light_counts = (id(occupancy_detect_mode) & ( 1 << 0 )) >> 0;
// Determine our results
bool new_state = false;
if (pir_counts & radar_counts & light_counts) {
// Logical AND of pir & radar & light
new_state = pir & radar & light;
} else if (pir_counts & radar_counts) {
// Logical AND of pir & radar
new_state = pir & radar;
} else if (pir_counts & light_counts) {
// Logical AND of pir & light
new_state = pir & light;
} else if (radar_counts & light_counts) {
// Logical AND of radar & light
new_state = radar & light;
} else if (pir_counts) {
// Only pir
new_state = pir;
} else if (radar_counts) {
// Only radar
new_state = radar;
} else if (light_counts) {
// Only light
new_state = light;
}
ESP_LOGD("occupancy_detect_handler", "New state: %s", new_state ? "true" : "false");
// Force update even if state hasn't changed
id(supersensor_occupancy).publish_state(new_state);
// Add a delayed re-publish to ensure state propagation
if (new_state) {
id(supersensor_occupancy).publish_state(new_state);
}
- id: occupancy_clear_handler
then:
- lambda: |-
ESP_LOGD("occupancy_clear_handler", "Occupancy clear handler triggered");
// Get the current values of our presence sensors
bool pir = id(pir_presence).state;
bool radar = id(radar_presence).state;
bool light = id(light_presence).state;
// Determine if PIR counts (2nd bit of presence_type)
int pir_counts = (id(occupancy_clear_mode) & ( 1 << 2 )) >> 2;
// Determine if Radar counts (1st bit of presence_type)
int radar_counts = (id(occupancy_clear_mode) & ( 1 << 1 )) >> 1;
// Determine if Light counts (0th bit of presence_type)
int light_counts = (id(occupancy_clear_mode) & ( 1 << 0 )) >> 0;
// Determine our results
bool new_state = false;
if (pir_counts & radar_counts & light_counts) {
// Logical AND of pir & radar & light
new_state = pir & radar & light;
} else if (pir_counts & radar_counts) {
// Logical AND of pir & radar
new_state = pir & radar;
} else if (pir_counts & light_counts) {
// Logical AND of pir & light
new_state = pir & light;
} else if (radar_counts & light_counts) {
// Logical AND of radar & light
new_state = radar & light;
} else if (pir_counts) {
// Only pir
new_state = pir;
} else if (radar_counts) {
// Only radar
new_state = radar;
} else if (light_counts) {
// Only light
new_state = light;
}
ESP_LOGD("occupancy_clear_handler", "New state: %s", new_state ? "true" : "false");
// Force update even if state hasn't changed
id(supersensor_occupancy).publish_state(new_state);
// Add a delayed re-publish to ensure state propagation
if (!new_state) {
id(supersensor_occupancy).publish_state(new_state);
}
#
# LD2410C calibration handlers
#
# Runs the LD2410C's built-in auto-threshold (background noise) calibration
# for 900 seconds, then adds +2 headroom to every gate threshold it found,
# since the auto routine reports measured maximums and we want a safe margin.
# Courtesy of esauvisky on https://community.home-assistant.io/t/ld2410-esphome-tips/477058/811
#
- id: ld2410_calibration
mode: single
then:
# 1. Give the user 10 seconds to clear the room
- logger.log: "INFO: Starting LD2410 calibration sequence... You have 10 seconds to clear the room!"
- lambda: 'id(ld2410c_calibration_status).publish_state("Waiting");'
- delay: 10s
# 2. Enable Configuration Mode
- logger.log: "DEBUG: Sending Enable Configuration command (0x00FF)"
- lambda: 'id(ld2410_last_ack_cmd) = -1; id(ld2410_last_ack_status) = -1;'
- uart.write:
id: ld2410_uart
# Data: HDR | LEN=4 | CMD=0xFF | VAL=0x01 | FTR
data: [0xFD, 0xFC, 0xFB, 0xFA, 0x04, 0x00, 0xFF, 0x00, 0x01, 0x00, 0x04, 0x03, 0x02, 0x01]
- delay: 1000ms
- if:
condition:
lambda: 'return !(id(ld2410_last_ack_cmd) == 0xFF && id(ld2410_last_ack_status) == 0);'
then:
- script.execute: ld2410_calibration_fail
- script.stop: ld2410_calibration
# 3. Start the auto-calibration (900 seconds)
- logger.log: "DEBUG: Sending Start Calibration command (0x000B, 900s)"
- lambda: 'id(ld2410_last_ack_cmd) = -1; id(ld2410_last_ack_status) = -1;'
- uart.write:
id: ld2410_uart
# Data: HDR | LEN=4 | CMD=0x0B | VAL=0x0384 (900, little-endian) | FTR
data: [0xFD, 0xFC, 0xFB, 0xFA, 0x04, 0x00, 0x0B, 0x00, 0x84, 0x03, 0x04, 0x03, 0x02, 0x01]
- delay: 1000ms
- if:
condition:
lambda: 'return !(id(ld2410_last_ack_cmd) == 0x0B && id(ld2410_last_ack_status) == 0);'
then:
- script.execute: ld2410_calibration_fail
- script.stop: ld2410_calibration
# 4. Disable Configuration Mode
- logger.log: "DEBUG: Sending End Configuration command (0x00FE)"
- uart.write:
id: ld2410_uart
# Data: HDR | LEN=2 | CMD=0xFE | FTR (No value needed)
data: [0xFD, 0xFC, 0xFB, 0xFA, 0x02, 0x00, 0xFE, 0x00, 0x04, 0x03, 0x02, 0x01]
- logger.log: "INFO: LD2410 calibration sequence sent. Ensure room remains empty for 930+ seconds!"
- lambda: 'id(ld2410c_calibration_status).publish_state("Calibrating");'
# 5. Wait 930s (900s run + 30s of buffer) and then query parameters
- delay: 930s
- lambda: 'id(ld2410c_calibration_status).publish_state("Polling");'
- button.press: ld2410c_query_params
- delay: 5s
# 6. Add +2 headroom to each gate threshold found by the auto-calibration
- logger.log: "INFO: Adding +2 headroom to all LD2410 gate thresholds"
- repeat:
count: 9
then:
- lambda: |-
number::Number *move_thresholds[9] = {
id(ld2410c_g0_move_threshold), id(ld2410c_g1_move_threshold),
id(ld2410c_g2_move_threshold), id(ld2410c_g3_move_threshold),
id(ld2410c_g4_move_threshold), id(ld2410c_g5_move_threshold),
id(ld2410c_g6_move_threshold), id(ld2410c_g7_move_threshold),
id(ld2410c_g8_move_threshold)
};
number::Number *still_thresholds[9] = {
id(ld2410c_g0_still_threshold), id(ld2410c_g1_still_threshold),
id(ld2410c_g2_still_threshold), id(ld2410c_g3_still_threshold),
id(ld2410c_g4_still_threshold), id(ld2410c_g5_still_threshold),
id(ld2410c_g6_still_threshold), id(ld2410c_g7_still_threshold),
id(ld2410c_g8_still_threshold)
};
auto bump = [](number::Number *threshold) {
if (isnan(threshold->state)) return;
float value = threshold->state + 2.0f;
if (value > 100.0f) value = 100.0f;
auto call = threshold->make_call();
call.set_value(value);
call.perform();
};
bump(move_thresholds[iteration]);
bump(still_thresholds[iteration]);
- delay: 500ms
# 7. Re-query parameters to confirm the final values
- button.press: ld2410c_query_params
- delay: 5s
- lambda: 'id(ld2410c_calibration_status).publish_state("Done");'
- logger.log: "INFO: LD2410 calibration finished."
- id: ld2410_calibration_fail
then:
- logger.log:
level: ERROR
format: "LD2410 calibration failed (last ACK command: %d, status: %d)"
args: ['id(ld2410_last_ack_cmd)', 'id(ld2410_last_ack_status)']
- lambda: 'id(ld2410c_calibration_status).publish_state("Failed");'
# Try to leave Configuration Mode cleanly in case it was enabled
- uart.write:
id: ld2410_uart
# Data: HDR | LEN=2 | CMD=0xFE | FTR (No value needed)
data: [0xFD, 0xFC, 0xFB, 0xFA, 0x02, 0x00, 0xFE, 0x00, 0x04, 0x03, 0x02, 0x01]
interval:
# Regular LD2410C state check every 30s (skipped while calibration is running)
- interval: 30s
then:
- if:
condition:
- not:
script.is_running: ld2410_calibration
then:
- lambda: |-
if(isnan(id(ld2410c_presence_distance).state)) {
ESP_LOGI("radar_watchdog", "LD2410C not reporting stats; restarting");
id(ld2410c_restart).press();
}
# Regular MWW state check every 30s
- interval: 30s
then:
- if:
condition:
- switch.is_on: enable_voice_support
- not:
micro_wake_word.is_running
then:
- micro_wake_word.start:
# Regular occupancy state reporting to HASS every 30s
- interval: 30s
then:
- lambda: |-
bool current_state = id(supersensor_occupancy).state;
ESP_LOGD("state_reporter", "Republishing occupancy state: %s", current_state ? "true" : "false");
id(supersensor_occupancy).publish_state(current_state);
# API watchdog every 5 minutes
- interval: 300s
then:
- lambda: |-
if (api::global_api_server->is_connected()) {
id(last_api_connected_time) = millis();
} else if (millis() - id(last_api_connected_time) > 300000) {
ESP_LOGE("api_watchdog", "API disconnected for too long, rebooting...");
App.safe_reboot();
}
logger:
level: DEBUG
baud_rate: 115200
# Log to COM output USB port
hardware_uart: UART0
# Ensure boot logs are captured when opening the port
deassert_rts_dtr: true
api:
reboot_timeout: 15min
ota:
platform: esphome
web_server:
port: 80
captive_portal:
mdns:
disabled: false
wifi:
ap: {}
domain: ""
output_power: 8.5dB
reboot_timeout: 15min
power_save_mode: none
time:
- platform: homeassistant
id: homeassistant_time
on_time_sync:
then:
- logger.log: "Time synchronized with Home Assistant"
debug:
update_interval: 15s
uart:
id: ld2410_uart
rx_pin: GPIO18
tx_pin: GPIO17
baud_rate: 256000
data_bits: 8
stop_bits: 1
parity: NONE
# Tap RX traffic to capture LD2410 command ACK frames for the calibration
# sequence; this observes the data without consuming it from the ld2410
# component, so normal operation is unaffected
debug:
direction: RX
after:
delimiter: [0x04, 0x03, 0x02, 0x01]
sequence:
- lambda: |-
// Scan for LD2410 ACK frames:
// HDR (FD FC FB FA) | LEN | CMD|0x0100 | STATUS | ... | FTR (04 03 02 01)
// Status 0 = success, 1 = failure
for (size_t i = 0; i + 9 < bytes.size(); i++) {
if (bytes[i] == 0xFD && bytes[i+1] == 0xFC && bytes[i+2] == 0xFB && bytes[i+3] == 0xFA) {
uint16_t cmd = bytes[i+6] | (bytes[i+7] << 8);
uint16_t status = bytes[i+8] | (bytes[i+9] << 8);
if ((cmd & 0xFF00) == 0x0100) {
id(ld2410_last_ack_cmd) = cmd & 0x00FF;
id(ld2410_last_ack_status) = status;
ESP_LOGD("ld2410_ack", "Got ACK for command 0x%02X with status %d", cmd & 0x00FF, status);
}
}
}
i2c:
sda: GPIO35
scl: GPIO36
scan: true
i2s_audio:
- id: i2s_input
i2s_lrclk_pin:
number: GPIO5 # WS
i2s_bclk_pin:
number: GPIO6 # SCK
# Dummy I2S audio pipeline for "speaker"
- id: i2s_dummy
i2s_lrclk_pin:
number: GPIO12 # WS
i2s_bclk_pin:
number: GPIO14 # SCK
microphone:
- platform: i2s_audio
id: mic
i2s_audio_id: i2s_input
i2s_din_pin: GPIO4 # SD
adc_type: external
pdm: false
channel: left
speaker:
# Dummy speaker to fix home-assistant/core#142363
- platform: i2s_audio
id: dummy_speaker
i2s_audio_id: i2s_dummy
i2s_dout_pin: GPIO13
dac_type: external
bits_per_sample: 16bit
sample_rate: 16000
channel: mono
buffer_duration: 60ms
micro_wake_word:
id: mww
microphone:
microphone: mic
gain_factor: 4
stop_after_detection: false
models:
- model: github://joshuaboniface/Custom_V2_MicroWakeWords/models/computer/computer.json
id: mww_computer
- model: github://esphome/micro-wake-word-models/models/v2/hey_jarvis.json
id: mww_hey_jarvis
- model: github://esphome/micro-wake-word-models/models/v2/hey_mycroft.json
id: mww_hey_mycroft
- model: github://esphome/micro-wake-word-models/models/v2/okay_nabu.json
id: mww_okay_nabu
- model: github://esphome/micro-wake-word-models/models/v2/alexa.json
id: mww_alexa
- model: github://joshuaboniface/Custom_V2_MicroWakeWords/models/hey_friday/hey_friday.json
id: mww_hey_friday
- model: github://joshuaboniface/Custom_V2_MicroWakeWords/models/hey_wabi/hey_wabi.json
id: mww_hey_wabi
- model: github://joshuaboniface/Custom_V2_MicroWakeWords/models/wasabi/wasabi.json
id: mww_wasabi
vad:
on_wake_word_detected:
- logger.log: "A wake word was detected!"
- if:
condition:
voice_assistant.is_running:
then:
voice_assistant.stop:
- voice_assistant.start:
wake_word: !lambda return wake_word;
voice_assistant:
id: va
microphone: mic
speaker: dummy_speaker
micro_wake_word: mww
use_wake_word: false
noise_suppression_level: 3
auto_gain: 31 dbfs
volume_multiplier: 4
on_wake_word_detected:
- logger.log: "Wake word detected in VA pipeline"
on_listening:
- logger.log: "Listening for commands"
# Trigger LED state - pipeline, listen
- lambda: 'id(led_state)=2; id(led_substate)=1;'
- script.execute: led_start
on_stt_vad_end:
- logger.log: "Processing STT result"
# Trigger LED state - pipeline, stt
- lambda: 'id(led_state)=2; id(led_substate)=2;'
- script.execute: led_start
on_error:
# Trigger LED state - off
- lambda: 'id(led_state)=0; id(led_substate)=0;'
- script.execute: led_start
on_tts_start:
- if:
condition:
- lambda: |-
ESP_LOGI("tts_response", "%s", x.c_str());
return x.rfind("Sorry", 0) == 0;
then:
- logger.log: "Command failed!"
# Trigger LED state - hold, failure
- lambda: 'id(led_state)=1; id(led_substate)=4;'
- script.execute: led_start
- script.execute: led_hold_timer
- voice_assistant.stop:
else:
- logger.log: "Command successful!"
# Trigger LED state - hold, success
- lambda: 'id(led_state)=1; id(led_substate)=3;'
- script.execute: led_start
- script.execute: led_hold_timer
- voice_assistant.stop:
on_tts_end:
- logger.log: "Finished STT result"
- voice_assistant.stop:
light:
- platform: rgb
id: output_led
red: rgb_r
green: rgb_g
blue: rgb_b
default_transition_length: 0.15s
flash_transition_length: 0.15s
effects:
- strobe:
name: flash_white
colors:
- state: true
brightness: 25%
red: 100%
green: 90%
blue: 90%
duration: 0.5s
- state: false
duration: 0.5s
output:
- platform: ledc
id: rgb_r
pin: GPIO39
- platform: ledc
id: rgb_g
pin: GPIO40
- platform: ledc
id: rgb_b
pin: GPIO41
ld2410:
id: ld2410_radar
uart_id: ld2410_uart
sensor:
- platform: uptime
name: "ESP32 Uptime"
icon: mdi:clock-alert
update_interval: 5s
entity_category: diagnostic
- platform: wifi_signal
name: "WiFi RSSI"
icon: mdi:wifi-strength-2
update_interval: 5s
entity_category: diagnostic
- platform: internal_temperature
name: "ESP32 Temperature"
icon: mdi:thermometer
unit_of_measurement: °C
device_class: TEMPERATURE
update_interval: 5s
entity_category: diagnostic
- platform: template
name: "ESP32 Free Memory"
icon: mdi:memory
unit_of_measurement: 'kB'
state_class: measurement
update_interval: 5s
lambda: |-
return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
entity_category: diagnostic
- platform: debug
free:
name: "ESP32 Heap Free"
block:
name: "ESP32 Heap Max Block"
psram:
name: "ESP32 PSRAM Free"
loop_time:
name: "ESP32 Loop Time"
cpu_frequency:
name: "ESP32 CPU Frequency"
- platform: sgp4x
voc:
name: "SGP41 VOC Index"
id: sgp41_voc_index
accuracy_decimals: 0
icon: mdi:waves-arrow-up
filters:
- sliding_window_moving_average: # We take a reading every 15 seconds, but calculate the sliding
window_size: 12 # average over 12 readings i.e. 60 seconds/1 minute to normalize
send_every: 3 # brief spikes while still sending a value every 15 seconds.
nox:
name: "SGP41 NOx Index"
id: sgp41_nox_index
accuracy_decimals: 0
icon: mdi:waves-arrow-up
filters:
- sliding_window_moving_average:
window_size: 12
send_every: 3
compensation:
temperature_source: sht45_temperature
humidity_source: sht45_humidity
store_baseline: true
update_interval: 5s
- platform: template
name: "SGP41 TVOC (µg⁄m³)"
id: sgp41_tvoc_ugm3
icon: mdi:molecule
lambda: |-
float i = id(sgp41_voc_index).state;
if (i < 1) return NAN;
float tvoc = (log(501.0 - i) - 6.24) * -878.53;
return tvoc;
unit_of_measurement: "µg⁄m³"
accuracy_decimals: 0
update_interval: 15s
- platform: template
name: "SGP41 TVOC (ppb)"
id: sgp41_tvoc_ppb
icon: mdi:molecule
lambda: |-
float tvoc_ugm3 = id(sgp41_tvoc_ugm3).state;
float tvoc_ppm = tvoc_ugm3 * 0.436; // ppb estimated using isobutylene MW (56.1 g/mol)
return tvoc_ppm;
unit_of_measurement: "ppb"
accuracy_decimals: 0
update_interval: 15s
- platform: template
name: "SGP41 eCO2 (appr.)"
id: sgp41_eco2_appr
icon: mdi:molecule-co2
lambda: |-
float tvoc_ppb = id(sgp41_tvoc_ppb).state;
float eco2_ppm = 400.0 + 1.5 * tvoc_ppb;
if (eco2_ppm > 2000) eco2_ppm = 2000;
return eco2_ppm;
unit_of_measurement: "ppm"
accuracy_decimals: 0
update_interval: 15s
- platform: sht4x
temperature:
name: "SHT45 Temperature"
id: sht45_temperature
accuracy_decimals: 1
filters:
- offset: !lambda return id(temperature_offset);
- sliding_window_moving_average:
window_size: 4
send_every: 1