-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathatomecho01.yaml
More file actions
616 lines (577 loc) · 15.7 KB
/
atomecho01.yaml
File metadata and controls
616 lines (577 loc) · 15.7 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
substitutions:
name: atomecho01
friendly_name: Atom Echo
static_ip: 192.168.2.186
micro_wake_word_model: okay_nabu # alexa, hey_jarvis, hey_mycroft are also supported
esphome:
name: "${name}"
friendly_name: "${friendly_name}"
name_add_mac_suffix: false
project:
name: m5stack.atom-echo-voice-assistant
version: "1.0"
min_version: 2024.6.0
# includes:
# - audio/timer_finished.h
# - audio/wake_word_triggered.h
esp32:
board: m5stack-atom
framework:
type: esp-idf
version: 4.4.8
platform_version: 5.4.0
logger:
api:
encryption:
key: !secret api_key
ota:
- platform: esphome
id: ota_esphome
password: !secret ota_pwd_sec
# - platform: http_request
# id: ota_http_request
#
#update:
# - platform: http_request
# id: update_http_request
# name: Firmware
# source: https://firmware.esphome.io/wake-word-voice-assistant/m5stack-atom-echo/manifest.json
# dashboard_import:
# package_import_url: github://esphome/firmware/voice-assistant/m5stack-atom-echo.yaml@main
wifi:
networks:
- ssid: !secret wifi_dmz_ssid
password: !secret wifi_dmz_password
use_address: 192.168.2.186
#manual_ip:
# static_ip: ${static_ip}
# gateway: 192.xxxxxxxxx
# subnet: 255.255.255.0
globals:
- id: media_player_va_pipeline
type: int
restore_value: no
initial_value: '0'
binary_sensor:
# button does the following:
# short click - stop a timer
# if no timer then restart either microwakeword or voice assistant continuous
- platform: gpio
pin:
number: GPIO39
inverted: true
name: Button
disabled_by_default: true
entity_category: diagnostic
id: echo_button
on_multi_click:
- timing:
- ON for at least 1001ms
then:
- if:
condition:
or:
- switch.is_on: timer_ringing
- voice_assistant.is_running
then:
- script.execute: handle_generic_click
else:
- switch.toggle: use_wake_word
- timing:
- ON for at most 1000ms
then:
- script.execute: handle_generic_click
button:
- platform: template
name: Test speaker
id: test_speaker
entity_category: config
on_press:
- script.execute: sound_beep
- script.wait: sound_beep
- delay: 100ms
- script.execute: restore_wake_word
- platform: template
name: Stop timer
id: stop_timer
on_press:
then:
- switch.turn_off: timer_ringing
- platform: template
name: Start assistant
id: btn_start_assistant
entity_category: config
on_press:
then:
- if:
condition:
switch.is_off: timer_ringing
then:
- script.execute: start_assistant
- platform: factory_reset
id: factory_reset_btn
name: Factory reset
- platform: restart
name: "${friendly_name} Restart"
i2s_audio:
- id: audio_i2s
i2s_lrclk_pin: GPIO33
i2s_bclk_pin: GPIO19
speaker:
- id: audio_out
platform: i2s_audio
dac_type: external
i2s_dout_pin: GPIO22
i2s_audio_id: audio_i2s
timeout: 100ms
channel: right
bits_per_sample: 16bit
sample_rate: 48000
buffer_duration: 100ms
# buffer_duration: 60ms
# - platform: mixer
# id: mixer_speaker_id
# output_speaker: audio_out
# source_speakers:
# - id: announcement_spk_mixer_input
# - id: media_spk_mixer_input
media_player:
- platform: speaker
id: va_media_player
name: player
codec_support_enabled: false
buffer_size: 19200
# buffer_size: 25000
announcement_pipeline:
format: WAV
# speaker: announcement_spk_mixer_input
speaker: audio_out
num_channels: 1
sample_rate: 48000
# media_pipeline:
# format: WAV
# speaker: media_spk_mixer_input
# num_channels: 1
# sample_rate: 16000
# on_state:
# - logger.log: "State updated!"
on_play: &play
- script.execute: stop_wake_word
- script.wait: stop_wake_word
- delay: 100ms
- if:
condition:
lambda: 'return (id(media_player_va_pipeline) == 0);'
then:
- light.turn_on:
id: led
red: 100%
green: 0%
blue: 0%
brightness: 100%
effect: "Playing"
on_announcement: *play
# - script.execute: stop_wake_word
# - script.wait: stop_wake_word
# - delay: 100ms
on_idle:
- if:
condition:
lambda: 'return (id(media_player_va_pipeline) == 0);'
then:
- script.execute: restore_wake_word
files:
- id: wake_word_wav
file: audio/wake_word_triggered.wav # Placed in the yaml directory. Should be encoded with a 16000 Hz sample rate, mono or stereo audio, and 16 bits per sample.
- id: timer_finished_wav
file: audio/timer_finished.wav # Placed in the yaml directory. Should be encoded with a 16000 Hz sample rate, mono or stereo audio, and 16 bits per sample.
microphone:
- platform: i2s_audio
id: echo_microphone
i2s_din_pin: GPIO23
adc_type: external
pdm: true
sample_rate: 16000
number:
- name: Speaker Volume
id: volume
platform: template
entity_category: config
min_value: 0
max_value: 1.0
step: 0.05
update_interval: never
optimistic: true
restore_value: true
initial_value: 1
on_value:
- lambda: id(audio_out).set_volume(x);
switch:
- platform: template
id: timer_ringing
optimistic: true
internal: true
restore_mode: ALWAYS_OFF
on_turn_on:
- script.execute: timer_start_ringing
on_turn_off:
then:
- script.stop: timer_start_ringing
- script.execute: restore_wake_word
- platform: template
name: Use wake word
id: use_wake_word
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF
entity_category: config
on_turn_on:
- wait_until:
media_player.is_idle:
- delay: 100ms
- micro_wake_word.start
- script.execute: refresh_led_default
on_turn_off:
- micro_wake_word.stop
- script.execute: refresh_led_default
#external_components:
# - source: github://pr#5230
# components:
# - esp_adf
# refresh: 0s
# esp_adf:
script:
- id: handle_generic_click
then:
- if:
condition:
voice_assistant.is_running
then:
- voice_assistant.stop
- script.execute: restore_wake_word
else:
- if:
condition:
switch.is_on: timer_ringing
then:
- switch.turn_off: timer_ringing
else:
- script.execute: start_assistant
- id: restore_wake_word
then:
- script.execute: refresh_led_default
- logger.log: "Restore wake word"
- if:
condition:
switch.is_on: use_wake_word
then:
- logger.log: "Waiting idle"
- wait_until:
media_player.is_idle:
- globals.set:
id: media_player_va_pipeline
value: "0"
- wait_until:
speaker.is_stopped:
- delay: 100ms
- logger.log: "Start micro wake word"
- micro_wake_word.start:
- id: stop_wake_word
then:
- if:
condition:
micro_wake_word.is_running
then:
- micro_wake_word.stop
- wait_until:
not:
micro_wake_word.is_running
- id: start_assistant
then:
- globals.set:
id: media_player_va_pipeline
value: "1"
- script.execute: stop_wake_word
- script.wait: stop_wake_word
- media_player.stop:
- voice_assistant.start
- light.turn_on:
id: led
red: 0
green: 0
blue: 1
brightness: 1
- id: refresh_led_default
mode: restart
then:
- if:
condition:
switch.is_on: timer_ringing
then:
- light.turn_on:
id: led
red: 0%
green: 100%
blue: 0%
brightness: 100%
effect: "Fast Pulse"
else:
- if:
condition:
lambda: return id(va)->get_timers().size() > 0;
then:
- if:
condition:
switch.is_on: use_wake_word
then:
- light.turn_on:
id: led
red: 100%
green: 90%
blue: 0%
brightness: 100%
effect: "Yellow Cyan Strobe"
else:
- light.turn_on:
id: led
red: 100%
green: 90%
blue: 0%
brightness: 100%
effect: "Very Slow Pulse"
else:
- if:
condition:
switch.is_on: use_wake_word
then:
- light.turn_on:
id: led
red: 0%
green: 0%
blue: 100%
brightness: 100%
effect: none
else:
- light.turn_off: led
- id: sound_beep
then:
- globals.set:
id: media_player_va_pipeline
value: "1"
- media_player.speaker.play_on_device_media_file:
media_file: wake_word_wav
announcement: true
# Wait until the alarm sound starts playing
- wait_until:
media_player.is_announcing:
# Wait until the alarm sound stops playing
- wait_until:
not:
media_player.is_announcing:
- id: timer_start_ringing
then:
- light.turn_on:
id: led
brightness: 1
red: 1
green: 1
blue: 1
effect: Pulse
- script.execute: timer_perform_ringing
- delay: 1min
- switch.turn_off: timer_ringing
- id: timer_perform_ringing
then:
- script.execute: refresh_led_default
- voice_assistant.stop:
- micro_wake_word.stop:
- wait_until:
not:
microphone.is_capturing:
- delay: 100ms
- while:
condition:
switch.is_on: timer_ringing
then:
- globals.set:
id: media_player_va_pipeline
value: "1"
- media_player.speaker.play_on_device_media_file:
media_file: timer_finished_wav
announcement: true
# Wait until the alarm sound starts playing
- wait_until:
media_player.is_announcing:
# Wait until the alarm sound stops playing
- wait_until:
not:
media_player.is_announcing:
- delay: 500ms
- wait_until:
not:
media_player.is_announcing:
voice_assistant:
id: va
microphone: echo_microphone
# speaker: echo_speaker
media_player: va_media_player
noise_suppression_level: 2
auto_gain: 31dBFS
volume_multiplier: 10.0
# vad_threshold: 3
on_wake_word_detected:
- microphone.stop_capture:
- wait_until:
not:
microphone.is_capturing:
# - lambda: id(echo_speaker).play(id(ok_sound), sizeof(id(ok_sound)));
on_listening:
- light.turn_on:
id: led
blue: 100%
red: 0%
green: 0%
effect: "Slow Pulse"
on_stt_vad_end:
- light.turn_on:
id: led
blue: 100%
red: 0%
green: 0%
effect: "Fast Pulse"
on_tts_start:
- globals.set:
id: media_player_va_pipeline
value: "1"
- light.turn_on:
id: led
blue: 100%
red: 0%
green: 0%
brightness: 100%
effect: none
on_idle:
then:
- delay: 1s
- script.execute: restore_wake_word
on_end:
then:
- delay: 1s
- script.execute: restore_wake_word
on_error:
- light.turn_on:
id: led
red: 100%
green: 0%
blue: 0%
brightness: 100%
effect: none
- script.execute: restore_wake_word
- delay: 1s
- script.execute: refresh_led_default
on_client_connected:
- delay: 2s # Give the api server time to settle
- script.execute: restore_wake_word
# - micro_wake_word.start:
on_client_disconnected:
- voice_assistant.stop:
- micro_wake_word.stop:
on_timer_finished:
- switch.turn_on: timer_ringing
light:
- platform: esp32_rmt_led_strip
id: led
name: None
disabled_by_default: true
entity_category: config
pin: GPIO27
default_transition_length: 250ms
chipset: SK6812
num_leds: 1
rgb_order: grb
rmt_channel: 0
effects:
- random:
name: "Playing"
transition_length: 3s
update_interval: 5s
- strobe:
name: "Yellow Cyan Strobe"
colors:
- state: true
brightness: 100%
red: 100%
green: 90%
blue: 0%
duration: 2000ms
transition_length: 2000ms
- state: true
brightness: 100%
red: 0%
green: 0%
blue: 100%
duration: 2000ms
transition_length: 2000ms
- pulse:
name: "Pulse"
transition_length: 500ms
update_interval: 500ms
- pulse:
name: "Slow Pulse"
transition_length: 250ms
update_interval: 250ms
min_brightness: 50%
max_brightness: 100%
- pulse:
name: "Very Slow Pulse"
transition_length: 2000ms
update_interval: 3000ms
min_brightness: 50%
max_brightness: 100%
- pulse:
name: "Fast Pulse"
transition_length: 100ms
update_interval: 100ms
min_brightness: 50%
max_brightness: 100%
micro_wake_word:
# model: okay_nabu
id: mww
models:
- model: https://github.com/kahrendt/microWakeWord/releases/download/okay_nabu_20241205.4/okay_nabu.json
# id: okay_nabu
# - model: https://github.com/kahrendt/microWakeWord/releases/download/stop/stop.json
# id: stop
# internal: true
# vad:
# model: https://github.com/kahrendt/microWakeWord/releases/download/v2.1_models/vad.json
microphone: echo_microphone
on_wake_word_detected:
- lambda: 'ESP_LOGI("custom", "Wake word detected: %s", wake_word.c_str());'
- if:
condition:
switch.is_on: timer_ringing
then:
- switch.turn_off: timer_ringing
else:
- if:
condition:
lambda: return (wake_word != "Stop");
then:
- wait_until:
not:
microphone.is_capturing:
- delay: 100ms
- script.execute: sound_beep
- script.wait: sound_beep
# - delay: 100ms
# - micro_wake_word.stop
- voice_assistant.start:
wake_word: !lambda return wake_word;
- light.turn_on:
id: led
red: 0
green: 0
blue: 1
brightness: 1
else:
- script.execute: restore_wake_word