forked from nirnachmani/ESP32-S3-Box-3-Firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ESP32-S3-Box-3-Custom.yaml
1667 lines (1551 loc) · 56.3 KB
/
ESP32-S3-Box-3-Custom.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
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
---
substitutions:
name: esp32-s3-box-3
friendly_name: ESP32 S3 Box 3
loading_illustration_file: https://github.com/esphome/firmware/raw/main/voice-assistant/casita/loading_320_240.png
idle_illustration_file: https://github.com/esphome/firmware/raw/main/voice-assistant/casita/idle_320_240.png
listening_illustration_file: https://github.com/esphome/firmware/raw/main/voice-assistant/casita/listening_320_240.png
thinking_illustration_file: https://github.com/esphome/firmware/raw/main/voice-assistant/casita/thinking_320_240.png
replying_illustration_file: https://github.com/esphome/firmware/raw/main/voice-assistant/casita/replying_320_240.png
error_illustration_file: https://github.com/esphome/firmware/raw/main/voice-assistant/casita/error_320_240.png
timer_finished_illustration_file: https://github.com/esphome/firmware/raw/main/voice-assistant/casita/timer_finished_320_240.png
loading_illustration_background_color: "000000"
idle_illustration_background_color: "000000"
listening_illustration_background_color: "FFFFFF"
thinking_illustration_background_color: "FFFFFF"
replying_illustration_background_color: "FFFFFF"
error_illustration_background_color: "000000"
text_outline_color: "888888"
voice_assist_idle_phase_id: "1"
voice_assist_listening_phase_id: "2"
voice_assist_thinking_phase_id: "3"
voice_assist_replying_phase_id: "4"
voice_assist_not_ready_phase_id: "10"
voice_assist_error_phase_id: "11"
voice_assist_playing_id: "12"
volume_up_phase_id: "13"
volume_down_phase_id: "14"
voice_assist_timer_finished_phase_id: "20"
# Replace "Area_Name" with the Room / Area name you want to Display to the Temperature & Humidity Sensor of the AHT20 (if used with DOCK)
sensor_area: "Art room"
# These unique characters have been extracted from every test file of every language available on https://github.com/home-assistant/intents (14 March 2024)
allowed_characters: " !#%\"'()+,-./0123456789:;<>?@ABCDEFGHIJKLMNOPQRSTUVWYZ[]_abcdefghijklmnopqrstuvwxyz{|}°²³µ¿ÁÂÄÅÉÖÚßàáâãäåæçèéêëìíîðñòóôõöøùúûüýþāăąćčďĐđēėęěğĮįıļľŁłńňőřśšťũūůűųźŻżŽžơưșțΆΈΌΐΑΒΓΔΕΖΗΘΚΜΝΠΡΣΤΥΦάέήίαβγδεζηθικλμνξοπρςστυφχψωϊόύώАБВГДЕЖЗИКЛМНОПРСТУХЦЧШЪЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюяёђєіїјљњћאבגדהוזחטיכלםמןנסעפץצקרשת،ءآأإئابةتجحخدذرزسشصضطظعغفقكلمنهوىيٹپچڈکگںھہیےংকচতধনফবযরলশষস়ািু্చయలిెొ్ംഅആഇഈഉഎഓകഗങചജഞടഡണതദധനപഫബഭമയരറലളവശസഹാിീുൂെേൈ്ൺൻർൽൾაბგდევზთილმნოპრსტუფქყშჩცძჭხạảấầẩậắặẹẽếềểệỉịọỏốồổỗộớờởợụủứừửữựỳ—、一上不个中为主乾了些亮人任低佔何作供依侧係個側偵充光入全关冇冷几切到制前動區卧厅厨及口另右吊后吗启吸呀咗哪唔問啟嗎嘅嘛器圍在场執場外多大始安定客室家密寵对將小少左已帘常幫幾库度庫廊廚廳开式後恆感態成我戲戶户房所扇手打执把拔换掉控插摄整斯新明是景暗更最會有未本模機檯櫃欄次正氏水沒没洗活派温測源溫漏潮激濕灯為無煙照熱燈燥物狀玄现現瓦用發的盞目着睡私空窗立笛管節簾籬紅線红罐置聚聲脚腦腳臥色节著行衣解設調請謝警设调走路車车运連遊運過道邊部都量鎖锁門閂閉開關门闭除隱離電震霧面音頂題顏颜風风食餅餵가간감갔강개거게겨결경고공과관그금급기길깥꺼껐꼽나난내네놀누는능니다닫담대더데도동됐되된됨둡드든등디때떤뜨라래러렇렌려로료른를리림링마많명몇모무문물뭐바밝방배변보부불블빨뽑사산상색서설성세센션소쇼수스습시신실싱아안않알았애야어얼업없었에여연열옆오온완외왼요운움워원위으은을음의이인일임입있작잠장재전절정제져조족종주줄중줘지직진짐쪽차창천최추출충치침커컴켜켰쿠크키탁탄태탬터텔통트튼티파팬퍼폰표퓨플핑한함해했행혀현화활후휴힘,?"
micro_wake_word_model: hey_jarvis
starting_up: "Starting up..."
wake_word_prompt: "Say \\\"Hey Jarvis\\\""
listening_prompt: "How can I help?"
error_prompt: "Sorry, error."
esphome:
name: ${name}
friendly_name: ${friendly_name}
min_version: 2024.6.0
name_add_mac_suffix: true
platformio_options:
board_build.flash_mode: dio
project:
name: esphome.voice-assistant
version: "2.0"
on_boot:
priority: 600
then:
- script.execute: draw_display
- lambda: id(speaker_volume) = id(startup_volume).state;
- script.execute: set_volume
- delay: 30s
- if:
condition:
lambda: return id(init_in_progress);
then:
- lambda: id(init_in_progress) = false;
- script.execute: draw_display # Draw the display again in case the on_client_connected cannot do so
esp32:
board: esp32s3box
flash_size: 16MB
framework:
type: esp-idf
sdkconfig_options:
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: "y"
CONFIG_ESP32S3_DATA_CACHE_64KB: "y"
CONFIG_ESP32S3_DATA_CACHE_LINE_64B: "y"
CONFIG_AUDIO_BOARD_CUSTOM: "y"
CONFIG_ESP32_S3_BOX_3_BOARD: "y"
components:
- name: esp32_s3_box_3_board
source: github://jesserockz/esp32-s3-box-3-board@main
refresh: 0s
psram:
mode: octal
speed: 80MHz
external_components:
- source: github://pr#5230
components: esp_adf
refresh: 0s
- source:
type: git
url: https://github.com/gnumpi/esphome_audio
ref: dev-next
#type: local
#path: components
components: [ adf_pipeline, i2s_audio ]
captive_portal:
api:
on_client_connected:
- script.execute: draw_display
on_client_disconnected:
- script.execute: draw_display
logger:
hardware_uart: USB_SERIAL_JTAG
dashboard_import:
package_import_url: github://esphome/firmware/wake-word-voice-assistant/esp32-s3-box-3.yaml@main
wifi:
on_connect:
- script.execute: draw_display
- delay: 5s # Gives time for improv results to be transmitted
- ble.disable:
on_disconnect:
- script.execute: draw_display
- ble.enable:
ap:
ssid: "Esp32-S3-Box-3 Fallback Hotspot"
password: "P1NTQC2LiPNH"
improv_serial:
esp32_improv:
authorizer: none
button:
- platform: factory_reset
id: factory_reset_btn
name: Factory reset
binary_sensor:
- platform: gpio
pin:
number: GPIO1
inverted: true
name: "Mute"
id: mute_switch
disabled_by_default: true
entity_category: diagnostic
on_release:
then:
- switch.turn_off: mute
on_press:
then:
- switch.turn_on: mute
- platform: gpio
pin:
number: GPIO21
name: "Presence detect"
disabled_by_default: false
publish_initial_state: true
device_class: "occupancy"
filters:
- delayed_off: !lambda return id(radar_delayed_off).state * 1000;
on_release:
then:
- if:
condition:
and:
- switch.is_on: mute_when_absent
- switch.is_on: enable_radar
then:
- lambda: id(mute_backup) = id(mute).state;
- switch.turn_on: mute
- light.turn_off: led
on_press:
then:
- if:
condition:
switch.is_on: mute_when_absent
then:
- if:
condition:
- lambda: return !id(mute_backup);
then:
- switch.turn_off: mute
- light.turn_on: led
- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: true
ignore_strapping_warning: true
name: Top Left Button
id: top_left_button
disabled_by_default: true
entity_category: diagnostic
on_multi_click:
- timing:
- ON for at least 50ms
- OFF for at least 50ms
then:
- switch.turn_off: timer_ringing
- timing:
- ON for at least 10s
then:
- button.press: factory_reset_btn
- platform: gt911
name: Home Button
index: 0
on_press:
then:
- logger.log: "Home pressed"
- platform: touchscreen
name: Volume Minus
x_min: 0
x_max: 80
y_min: 160
y_max: 234
on_press:
then:
- logger.log: "Volume Minus pressed"
- lambda: |-
id(speaker_volume) = static_cast<int>(id(adf_media_player).volume * 100);
id(speaker_volume) = id(speaker_volume) - (id(speaker_volume) % 5); // rounded to 5
- if:
condition:
lambda: return id(speaker_volume) > 0;
then:
- lambda: id(speaker_volume) -= 5;
- lambda: id(voice_assistant_phase_backup) = id(voice_assistant_phase);
- lambda: id(voice_assistant_phase) = ${volume_down_phase_id};
- script.execute: draw_display
- script.execute: set_volume
- lambda: id(voice_assistant_phase) = id(voice_assistant_phase_backup);
- script.execute: draw_display
- platform: touchscreen
name: Volume Plus
x_min: 260
x_max: 320
y_min: 160
y_max: 234
on_press:
then:
- logger.log: "Volume Plus pressed"
- lambda: |-
id(speaker_volume) = static_cast<int>(id(adf_media_player).volume * 100);
id(speaker_volume) = id(speaker_volume) - (id(speaker_volume) % 5); // rounded to 5
- if:
condition:
lambda: return id(speaker_volume) < 100;
then:
- lambda: id(speaker_volume) += 5;
- lambda: id(voice_assistant_phase_backup) = id(voice_assistant_phase);
- lambda: id(voice_assistant_phase) = ${volume_up_phase_id};
- script.execute: draw_display
- script.execute: set_volume
- lambda: id(voice_assistant_phase) = id(voice_assistant_phase_backup);
- script.execute: draw_display
- platform: touchscreen
name: Play Pause
x_min: 0
x_max: 320
y_min: 0
y_max: 240
on_press:
then:
- if:
condition:
- switch.is_on: timer_ringing
then:
- switch.turn_off: timer_ringing
- platform: touchscreen
name: Mute Microphone
x_min: 0
x_max: 80
y_min: 0
y_max: 159
on_press:
then:
- switch.toggle: mute
- platform: touchscreen
name: Mute Speaker
x_min: 260
x_max: 320
y_min: 0
y_max: 159
on_press:
then:
- switch.toggle: mute_speaker
output:
- platform: ledc
pin: GPIO47
id: backlight_output
light:
- platform: monochromatic
id: led
name: LCD Backlight
entity_category: config
output: backlight_output
restore_mode: RESTORE_DEFAULT_ON
default_transition_length: 250ms
at581x:
id: "Radar"
i2c_id: bus_b
i2c:
- id: bus_a
sda: GPIO8
scl: GPIO18
frequency: 100kHz
scan: True
- id: bus_b
sda: GPIO41
scl: GPIO40
frequency: 100kHz
i2s_audio:
- id: i2s_shared
i2s_lrclk_pin: GPIO45
i2s_bclk_pin: GPIO17
i2s_mclk_pin: GPIO2
access_mode: duplex
adf_pipeline:
- platform: i2s_audio
type: audio_out
id: adf_i2s_out
i2s_audio_id: i2s_shared
i2s_dout_pin: GPIO15
adf_alc: false
dac:
i2c_id: bus_a
model: es8311
address: 0x18
enable_pin: GPIO46
sample_rate: 16000
bits_per_sample: 16bit
fixed_settings: true
- platform: i2s_audio
type: audio_in
id: adf_i2s_in
i2s_audio_id: i2s_shared
i2s_din_pin: GPIO16
pdm: false
adc:
i2c_id: bus_a
model: es7210
address: 0x40
sample_rate: 16000
bits_per_sample: 16bit
fixed_settings: true
media_player:
- platform: adf_pipeline
id: adf_media_player
name: s3-box_media_player
internal: false
keep_pipeline_alive: true
announcement_audio:
sample_rate: 22050
bits_per_sample: 16
num_channels: 1
pipeline:
- self
- resampler
- adf_i2s_out
on_idle:
- if:
condition:
- lambda: return (id(acknowledge) == false);
then:
- logger.log: "NOT Acknowledging.."
- if:
condition:
- lambda: return (id(replying_to_query) == true);
then:
- if:
condition:
and:
- switch.is_on: continued_conversation
- switch.is_off: timer_ringing
then:
- delay: 300ms
- lambda: id(voice_assistant_phase) = ${voice_assist_listening_phase_id};
- script.execute: stt_timeout_to_idle
- script.execute: draw_display
else:
- lambda: id(voice_assistant_phase) = ${voice_assist_idle_phase_id};
- script.execute: draw_display
- lambda: id(replying_to_query) = false;
else:
- if:
condition:
- switch.is_off: timer_ringing
then:
- lambda: id(voice_assistant_phase) = ${voice_assist_idle_phase_id};
- script.execute: draw_display
else:
- logger.log: "Acknowledging.."
- lambda: id(acknowledge) = false;
# on_play:
# - if:
# condition:
# - switch.is_off: timer_ringing
# then:
# - lambda: id(voice_assistant_phase) = ${voice_assist_playing_id};
# - script.execute: draw_display
on_announcement:
- lambda: id(voice_assistant_phase) = ${voice_assist_replying_phase_id};
- script.execute: draw_display
microphone:
- platform: adf_pipeline
id: box_mic
keep_pipeline_alive: true
pipeline:
- adf_i2s_in
- resampler
- self
#speaker:
# - platform: esp_adf
# id: box_speaker
micro_wake_word:
models:
- model: ${micro_wake_word_model}
on_wake_word_detected:
- media_player.pause:
- delay: 100ms
- lambda: id(acknowledge) = true;
- media_player.play_media:
id: adf_media_player
media_url: 'http://homeassistant.local:8123/local/sounds/acknowledge.mp3'
- delay: 400ms
- if:
condition:
switch.is_on: continued_conversation
then:
- lambda: id(va).set_use_wake_word(false);
- voice_assistant.start_continuous: # wake_word: !lambda return wake_word; not yet supported for continuous
else:
- lambda: id(va).set_use_wake_word(false);
- voice_assistant.start:
wake_word: !lambda return wake_word;
voice_assistant:
id: va
microphone: box_mic
media_player: adf_media_player
use_wake_word: true
noise_suppression_level: 3
auto_gain: 31dBFS
volume_multiplier: 2.0
#vad_threshold: 3
on_listening:
- lambda: id(voice_assistant_phase) = ${voice_assist_listening_phase_id};
- if:
condition:
- switch.is_off: continued_conversation
then:
- text_sensor.template.publish:
id: text_request
state: "..."
- text_sensor.template.publish:
id: text_response
state: "..."
- script.execute: draw_display
- if:
condition:
- switch.is_on: continued_conversation
then:
- text_sensor.template.publish:
id: text_request
state: ""
- text_sensor.template.publish:
id: text_response
state: ""
- script.execute: stt_timeout_to_idle
- lambda: id(va).set_use_wake_word(false);
on_stt_vad_end:
- lambda: id(voice_assistant_phase) = ${voice_assist_thinking_phase_id};
- script.execute: draw_display
on_stt_end:
- text_sensor.template.publish:
id: text_request
state: !lambda return x;
- script.execute: draw_display
- if:
condition:
switch.is_on: continued_conversation
then:
- if:
condition:
- lambda: |-
bool contains_letters = false;
for (char c : x) {
if (std::isalpha(c)) {
contains_letters = true;
break;
}
}
return contains_letters;
then:
- script.execute: stt_timeout_to_idle
else:
- logger.log: "STT has no text"
- voice_assistant.stop
- script.execute: return_to_idle
on_tts_start:
- text_sensor.template.publish:
id: text_response
state: !lambda return x;
- if:
condition:
and:
# When using extended openai conversation, add the following to the prompt
# If you feel the user has finished and doesn't want to talk anymore, just respond with the exact phrase "Ok, bye."
- lambda: return (x == "Ok, bye.");
- switch.is_on: continued_conversation
then:
- script.execute: return_to_idle
on_tts_end:
- lambda: id(voice_assistant_phase) = ${voice_assist_replying_phase_id};
- script.execute: draw_display
- if:
condition:
- switch.is_on: continued_conversation
then:
- lambda: id(replying_to_query) = true;
- script.execute: stt_timeout_to_idle
# on_tts_stream_start:
# - lambda: id(voice_assistant_phase) = ${voice_assist_replying_phase_id};
# - script.execute: draw_display
# - if:
# condition:
# - switch.is_on: continued_conversation
# then:
# - script.execute: stt_timeout_to_idle
# on_tts_stream_end:
# - if:
# condition:
# - switch.is_on: continued_conversation
# then:
# - lambda: id(voice_assistant_phase) = ${voice_assist_listening_phase_id};
# - script.execute: stt_timeout_to_idle
# else:
# - lambda: id(voice_assistant_phase) = ${voice_assist_idle_phase_id};
# - script.execute: draw_display
on_end:
- if:
condition:
and:
- switch.is_off: mute
- lambda: return id(wake_word_engine_location).state == "On device";
- switch.is_off: continued_conversation
then:
- script.execute: return_to_idle
on_error:
- if:
condition:
and:
- lambda: return !id(init_in_progress);
- lambda: return !(code == "stt-no-text-recognized");
then:
- lambda: id(voice_assistant_phase) = ${voice_assist_error_phase_id};
- script.execute: draw_display
- delay: 1s
- script.stop: stt_timeout_to_idle
- script.execute: draw_display
on_client_connected:
- script.execute: return_to_idle
- lambda: id(init_in_progress) = false;
- script.execute: draw_display
on_client_disconnected:
- if:
condition:
lambda: return id(wake_word_engine_location).state == "In Home Assistant";
then:
- lambda: id(va).set_use_wake_word(false);
- voice_assistant.stop
- if:
condition:
lambda: return id(wake_word_engine_location).state == "On device";
then:
- micro_wake_word.stop
- lambda: id(voice_assistant_phase) = ${voice_assist_not_ready_phase_id};
- script.execute: draw_display
on_timer_started:
- script.execute: draw_display
on_timer_cancelled:
- script.execute: draw_display
on_timer_updated:
- script.execute: draw_display
on_timer_tick:
- script.execute: draw_display
on_timer_finished:
- script.execute: stop_voice_assistant
- lambda: id(voice_assistant_phase) = ${voice_assist_timer_finished_phase_id};
- switch.turn_on: timer_ringing
- script.execute: draw_display
- wait_until:
not:
microphone.is_capturing:
- while:
condition:
switch.is_on: timer_ringing
then:
- media_player.play_media:
id: adf_media_player
media_url: 'http://homeassistant.local:8123/local/sounds/timer.mp3'
- delay: 1s
- wait_until:
not:
media_player.is_playing:
- switch.turn_off: timer_ringing
- media_player.stop
- script.execute: return_to_idle
script:
- id: set_volume
then:
- media_player.volume_set:
volume: !lambda return id(speaker_volume) * 0.01 ;
- id: stt_timeout_to_idle
mode: restart # restart the timer if called before timeout
then:
if:
condition:
switch.is_on: continued_conversation
then:
- delay: !lambda "return id(continued_timeout).state * 1000;"
- if:
condition:
lambda: return (id(voice_assistant_phase) == ${voice_assist_replying_phase_id});
then:
- wait_until:
condition:
lambda: return !(id(voice_assistant_phase) == ${voice_assist_replying_phase_id});
# normally this would complete and move to next phase with on_tts_stream_end,
# but sometimes this is missed so put a time limit on the wait
timeout: 5s
- delay: 1s # Give time for the stream to end and the phase to be switched back to listening and this timeout to be reset
- script.execute: stt_timeout_to_idle
- if:
condition:
lambda: return (id(voice_assistant_phase) == ${voice_assist_timer_finished_phase_id});
then:
- wait_until:
condition:
lambda: return !(id(voice_assistant_phase) == ${voice_assist_timer_finished_phase_id});
# normally this would complete and move to next phase with on_tts_stream_end,
# but sometimes this is missed so put a time limit on the wait
timeout: 5s
- delay: 1s # Give time for the stream to end and the phase to be switched back to listening and this timeout to be reset
- script.execute: stt_timeout_to_idle
- script.execute: return_to_idle
- id: return_to_idle
then:
- if:
condition:
lambda: return id(wake_word_engine_location).state == "On device";
then:
- script.stop: stt_timeout_to_idle
- if:
condition:
voice_assistant.is_running
then:
- lambda: id(va).set_use_wake_word(false);
- voice_assistant.stop
- wait_until:
condition:
not:
voice_assistant.is_running
timeout: 5s
- if:
condition:
not:
micro_wake_word.is_running
then:
- micro_wake_word.start
- if:
condition:
lambda: return id(wake_word_engine_location).state == "In Home Assistant";
then:
- if:
condition:
micro_wake_word.is_running
then:
- micro_wake_word.stop
- wait_until:
condition:
not:
micro_wake_word.is_running
timeout: 5s
- wait_until:
condition:
not:
voice_assistant.is_running
timeout: 5s
- lambda: id(va).set_use_wake_word(true);
- if:
condition:
- not:
voice_assistant.is_running
then:
- voice_assistant.start_continuous
- lambda: id(voice_assistant_phase) = ${voice_assist_idle_phase_id};
- script.execute: draw_display
- id: draw_display
then:
- if:
condition:
lambda: return !id(init_in_progress);
then:
- if:
condition:
wifi.connected:
then:
- if:
condition:
api.connected:
then:
- lambda: |
switch(id(voice_assistant_phase)) {
case ${voice_assist_listening_phase_id}:
id(s3_box_lcd).show_page(listening_page);
id(s3_box_lcd).update();
break;
case ${voice_assist_thinking_phase_id}:
id(s3_box_lcd).show_page(thinking_page);
id(s3_box_lcd).update();
break;
case ${voice_assist_replying_phase_id}:
id(s3_box_lcd).show_page(replying_page);
id(s3_box_lcd).update();
break;
case ${voice_assist_error_phase_id}:
id(s3_box_lcd).show_page(error_page);
id(s3_box_lcd).update();
break;
case ${voice_assist_not_ready_phase_id}:
id(s3_box_lcd).show_page(no_ha_page);
id(s3_box_lcd).update();
break;
case ${voice_assist_timer_finished_phase_id}:
id(s3_box_lcd).show_page(timer_finished_page);
id(s3_box_lcd).update();
break;
case ${voice_assist_playing_id}:
id(s3_box_lcd).show_page(playing_page);
id(s3_box_lcd).update();
break;
case ${volume_up_phase_id}:
id(s3_box_lcd).show_page(volume_up_page);
id(s3_box_lcd).update();
break;
case ${volume_down_phase_id}:
id(s3_box_lcd).show_page(volume_down_page);
id(s3_box_lcd).update();
break;
default:
id(s3_box_lcd).show_page(idle_page);
id(s3_box_lcd).update();
}
else:
- display.page.show: no_ha_page
- component.update: s3_box_lcd
else:
- display.page.show: no_wifi_page
- component.update: s3_box_lcd
else:
- display.page.show: initializing_page
- component.update: s3_box_lcd
# finds the active timer with the least amount of time left from the collection of timers and assigns it to a global variable
- id: fetch_first_active_timer
then:
- lambda: |
const auto timers = id(va).get_timers();
auto output_timer = timers.begin()->second;
for (auto &iterable_timer : timers) {
if (iterable_timer.second.is_active && iterable_timer.second.seconds_left <= output_timer.seconds_left) {
output_timer = iterable_timer.second;
}
}
id(global_first_active_timer) = output_timer;
- id: check_if_timers_active
then:
- lambda: |
const auto timers = id(va).get_timers();
bool output = false;
if (timers.size() > 0) {
for (auto &iterable_timer : timers) {
if(iterable_timer.second.is_active) {
output = true;
}
}
}
id(global_is_timer_active) = output;
- id: fetch_first_timer
then:
- lambda: |
const auto timers = id(va).get_timers();
auto output_timer = timers.begin()->second;
for (auto &iterable_timer : timers) {
if (iterable_timer.second.seconds_left <= output_timer.seconds_left) {
output_timer = iterable_timer.second;
}
}
id(global_first_timer) = output_timer;
- id: check_if_timers
then:
- lambda: |
const auto timers = id(va).get_timers();
bool output = false;
if (timers.size() > 0) {
output = true;
}
id(global_is_timer) = output;
- id: draw_timer_timeline
then:
- lambda: |
id(check_if_timers_active).execute();
id(check_if_timers).execute();
if (id(global_is_timer_active)){
id(fetch_first_active_timer).execute();
int active_pixels = round( 320 * id(global_first_active_timer).seconds_left / max(id(global_first_active_timer).total_seconds , static_cast<uint32_t>(1)) );
if (active_pixels > 0){
id(s3_box_lcd).filled_rectangle(0 , 225 , 320 , 15 , Color::WHITE );
id(s3_box_lcd).filled_rectangle(0 , 226 , active_pixels , 13 , id(active_timer_color) );
}
} else if (id(global_is_timer)){
id(fetch_first_timer).execute();
int active_pixels = round( 320 * id(global_first_timer).seconds_left / max(id(global_first_timer).total_seconds , static_cast<uint32_t>(1)));
if (active_pixels > 0){
id(s3_box_lcd).filled_rectangle(0 , 225 , 320 , 15 , Color::WHITE );
id(s3_box_lcd).filled_rectangle(0 , 226 , active_pixels , 13 , id(paused_timer_color) );
}
}
- id: stop_voice_assistant
then:
- if:
condition:
lambda: return id(wake_word_engine_location).state == "In Home Assistant";
then:
- lambda: id(va).set_use_wake_word(false);
- voice_assistant.stop
- if:
condition:
lambda: return id(wake_word_engine_location).state == "On device";
then:
- voice_assistant.stop
- micro_wake_word.stop
- lambda: id(voice_assistant_phase) = ${voice_assist_not_ready_phase_id};
switch:
- platform: template
name: Display conversation
id: display_conversation
optimistic: true
restore_mode: RESTORE_DEFAULT_ON
entity_category: config
on_turn_off:
- script.execute: draw_display
on_turn_on:
- script.execute: draw_display
- platform: template
name: Display text prompts
id: display_text
optimistic: true
restore_mode: RESTORE_DEFAULT_ON
entity_category: config
on_turn_off:
- script.execute: draw_display
on_turn_on:
- script.execute: draw_display
- platform: template
name: Mute
id: mute
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF
entity_category: config
on_turn_off:
- if:
condition:
lambda: return !id(init_in_progress);
then:
- script.execute: return_to_idle
on_turn_on:
- if:
condition:
lambda: return !id(init_in_progress);
then:
- lambda: id(va).set_use_wake_word(false);
- if:
condition:
- voice_assistant.is_running
then:
- voice_assistant.stop
- if:
condition:
- micro_wake_word.is_running
then:
- micro_wake_word.stop
- script.execute: draw_display
- platform: template
id: timer_ringing
optimistic: true
internal: true
restore_mode: ALWAYS_OFF
on_turn_on:
- delay: 2min
- switch.turn_off: timer_ringing
- platform: template
name: Continued conversation
id: continued_conversation
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF
entity_category: config
on_turn_off:
- script.execute: return_to_idle
on_turn_on:
- script.execute: return_to_idle
- platform: template
name: "Mute when absent"
id: mute_when_absent
icon: mdi:account-right-arrow
optimistic: true
entity_category: config
restore_mode: RESTORE_DEFAULT_OFF
- platform: template
name: Mute Speaker
id: mute_speaker
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF
entity_category: config
on_turn_off:
- if:
condition:
lambda: return !id(init_in_progress);
then:
- lambda: |-
if (id(speaker_volume_backup) > 0) {
id(speaker_volume) = id(speaker_volume_backup);
} else {
id(speaker_volume) = id(startup_volume).state;
}
- script.execute: set_volume
- script.execute: draw_display
on_turn_on:
- if:
condition:
lambda: return !id(init_in_progress);
then:
- lambda: |-
id(speaker_volume_backup) = static_cast<int>(id(adf_media_player).volume * 100);
if (id(speaker_volume) > 0) {
id(speaker_volume) = 0;
}
- script.execute: set_volume
- script.execute: draw_display
- platform: at581x
at581x_id: "Radar"
name: "Enable Radar"
id: enable_radar