-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesphome-chatbot.yaml
More file actions
454 lines (416 loc) · 11.2 KB
/
esphome-chatbot.yaml
File metadata and controls
454 lines (416 loc) · 11.2 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
esphome:
name: chat-robot
friendly_name: Chat Robot
platformio_options:
board_build.flash_mode: dio
board_build.f_flash: 80000000L
board_build.flash_size: 16MB
on_boot:
then:
- light.turn_on:
id: led_ww
blue: 100%
brightness: 60%
effect: fast pulse
- lambda: |-
id(eye_state) = "idle";
esp32:
board: esp32-s3-devkitc-1
variant: esp32s3
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_SPIRAM_MODE_OCT: "y"
CONFIG_SPIRAM_SPEED_80M: "y"
CONFIG_SPIRAM: "y"
CONFIG_ESP32_S3_BOX_BOARD: "y"
psram:
mode: octal
speed: 80MHz
button:
- platform: restart
name: "Restart"
id: but_rest
binary_sensor:
- platform: gpio
pin: GPIO40
name: "Volume Up Button"
on_press:
then:
- media_player.volume_up: external_media_player
- platform: gpio
pin: GPIO39
name: "Volume Down Button"
on_press:
then:
- media_player.volume_down: external_media_player
switch:
- platform: template
id: mute
name: mute
optimistic: true
on_turn_on:
- micro_wake_word.stop:
- voice_assistant.stop:
- light.turn_on:
id: led_ww
red: 100%
green: 0%
blue: 0%
brightness: 60%
effect: fast pulse
- delay: 2s
- light.turn_off:
id: led_ww
- light.turn_on:
id: led_ww
red: 100%
green: 0%
blue: 0%
brightness: 30%
on_turn_off:
- micro_wake_word.start:
- light.turn_on:
id: led_ww
red: 0%
green: 100%
blue: 0%
brightness: 60%
effect: fast pulse
- delay: 2s
- light.turn_off:
id: led_ww
light:
- platform: esp32_rmt_led_strip
id: led_ww
rgb_order: GRB
pin: GPIO48
num_leds: 1
chipset: ws2812
name: "on board light"
effects:
- pulse:
name: "Slow Pulse"
transition_length: 250ms
update_interval: 250ms
min_brightness: 50%
max_brightness: 100%
- pulse:
name: "Fast Pulse"
transition_length: 100ms
update_interval: 100ms
min_brightness: 50%
max_brightness: 100%
# I2C for OLED display
i2c:
sda: GPIO41
scl: GPIO42
scan: true
frequency: 400kHz
id: bus_a
# I2S Audio configuration
i2s_audio:
- id: i2s_in
i2s_lrclk_pin: GPIO4
i2s_bclk_pin: GPIO5
- id: i2s_out
i2s_lrclk_pin: GPIO16
i2s_bclk_pin: GPIO15
# Microphone
microphone:
- platform: i2s_audio
id: mic
adc_type: external
i2s_audio_id: i2s_in
i2s_din_pin: GPIO6
pdm: false
bits_per_sample: 32bit
sample_rate: 16000
channel: left
# Speaker
speaker:
- platform: i2s_audio
id: speaker_out
i2s_audio_id: i2s_out
dac_type: external
i2s_dout_pin: GPIO7
channel: mono
sample_rate: 16000
- platform: mixer
id: mixing_speaker
output_speaker: speaker_out
num_channels: 1
source_speakers:
- id: announcement_mixing_input
timeout: never
- id: media_mixing_input
timeout: never
media_player:
- platform: speaker
id: external_media_player
name: "Voice Assistant Speaker"
volume_increment: 0.05
volume_min: 0.4
volume_max: 1
announcement_pipeline:
speaker: announcement_mixing_input
format: FLAC
num_channels: 1
sample_rate: 16000
media_pipeline:
speaker: media_mixing_input
format: FLAC
num_channels: 1
sample_rate: 16000
on_announcement:
- mixer_speaker.apply_ducking:
id: media_mixing_input
decibel_reduction: 20
duration: 0.0s
# Micro Wake Word - with PSRAM you can use larger models
micro_wake_word:
id: mww
vad:
probability_cutoff: 0.05
microphone:
microphone: mic
channels: 0
gain_factor: 4
stop_after_detection: false
models:
- model: hey_jarvis
probability_cutoff: 0.5
sliding_window_size: 5
- model: okay_nabu
probability_cutoff: 0.5
sliding_window_size: 5
- model: hey_mycroft
probability_cutoff: 0.5
sliding_window_size: 5
on_wake_word_detected:
- voice_assistant.start:
wake_word: !lambda return wake_word;
silence_detection: true
- lambda: |-
id(eye_state) = "listening";
id(blink_timer) = 0;
# Voice Assistant
voice_assistant:
microphone: mic
media_player: external_media_player
use_wake_word: false
micro_wake_word: mww
noise_suppression_level: 2
auto_gain: 31dBFS
volume_multiplier: 2.0
on_listening:
- light.turn_on:
id: led_ww
red: 80%
green: 0%
blue: 80%
brightness: 60%
effect: fast pulse
- lambda: |-
id(eye_state) = "listening";
on_stt_vad_start:
- light.turn_on:
id: led_ww
red: 0%
green: 80%
blue: 80%
brightness: 60%
effect: Slow pulse
on_stt_vad_end: #thinking phase
- light.turn_on:
id: led_ww
red: 80%
green: 0%
blue: 80%
brightness: 60%
effect: Slow Pulse
on_stt_end:
- lambda: |-
id(eye_state) = "thinking";
on_tts_start:
- light.turn_on:
id: led_ww
red: 0%
green: 0%
blue: 80%
brightness: 60%
effect: Slow Pulse
- lambda: |-
id(eye_state) = "speaking";
on_end:
then:
- wait_until:
not:
voice_assistant.is_running:
# Stop ducking audio.
- mixer_speaker.apply_ducking:
id: media_mixing_input
decibel_reduction: 0
duration: 1.0s
- light.turn_off: led_ww
- micro_wake_word.start:
- delay: 10s
- lambda: |-
id(eye_state) = "idle";
id(blink_timer) = 0;
on_error:
- lambda: |-
id(eye_state) = "error";
id(blink_timer) = 0;
# OLED Display
font:
- file: "fonts/arial.ttf"
id: font_small
size: 10
display:
- platform: ssd1306_i2c
model: "SSD1306 128x64"
address: 0x3C
update_interval: 50ms # 20 FPS for smooth animation
lambda: |-
// Animation counter
static int frame = 0;
frame++;
int left_eye_x = 35;
int right_eye_x = 93;
int eye_y = 32;
int eye_radius = 14;
int pupil_radius = 8;
// Blink animation
bool is_blinking = false;
if (id(eye_state) == "idle" || id(eye_state) == "listening") {
id(blink_timer)++;
if (id(blink_timer) > 100 && id(blink_timer) < 106) {
is_blinking = true;
} else if (id(blink_timer) > 110) {
id(blink_timer) = 0;
}
}
if (id(eye_state) == "idle") {
// Draw normal eyes with occasional blink
if (is_blinking) {
// Draw closed eyes (horizontal lines)
it.line(left_eye_x - eye_radius, eye_y, left_eye_x + eye_radius, eye_y);
it.line(right_eye_x - eye_radius, eye_y, right_eye_x + eye_radius, eye_y);
} else {
// Draw open eyes
it.circle(left_eye_x, eye_y, eye_radius);
it.circle(right_eye_x, eye_y, eye_radius);
it.filled_circle(left_eye_x, eye_y, pupil_radius);
it.filled_circle(right_eye_x, eye_y, pupil_radius);
}
}
else if (id(eye_state) == "listening") {
// Wide eyes
it.circle(left_eye_x, eye_y, eye_radius + 2);
it.circle(right_eye_x, eye_y, eye_radius + 2);
it.filled_circle(left_eye_x, eye_y, pupil_radius + 2);
it.filled_circle(right_eye_x, eye_y, pupil_radius + 2);
// Pulsing effect
if ((frame / 10) % 2 == 0) {
it.circle(left_eye_x, eye_y, eye_radius + 4);
it.circle(right_eye_x, eye_y, eye_radius + 4);
}
}
else if (id(eye_state) == "thinking") {
// Eyes looking up-right with animation
int offset_x = ((frame / 5) % 8) - 4;
int offset_y = -6 + ((frame / 5) % 4) - 2;
it.circle(left_eye_x, eye_y, eye_radius);
it.circle(right_eye_x, eye_y, eye_radius);
it.filled_circle(left_eye_x + offset_x, eye_y + offset_y, pupil_radius);
it.filled_circle(right_eye_x + offset_x, eye_y + offset_y, pupil_radius);
// Thinking dots
int dot_y = 55;
for (int i = 0; i < 3; i++) {
if ((frame / 15 + i * 5) % 15 < 5) {
it.filled_circle(54 + i * 10, dot_y, 2);
}
}
}
else if (id(eye_state) == "speaking") {
// Animated blinking/talking eyes
int blink_cycle = (frame / 8) % 20;
if (blink_cycle < 3) {
// Blink
it.line(left_eye_x - eye_radius, eye_y, left_eye_x + eye_radius, eye_y);
it.line(right_eye_x - eye_radius, eye_y, right_eye_x + eye_radius, eye_y);
} else {
// Open with varying pupil size (simulating expression)
int pupil_mod = (frame / 5) % 4;
it.circle(left_eye_x, eye_y, eye_radius);
it.circle(right_eye_x, eye_y, eye_radius);
it.filled_circle(left_eye_x, eye_y, pupil_radius - pupil_mod);
it.filled_circle(right_eye_x, eye_y, pupil_radius - pupil_mod);
}
}
else if (id(eye_state) == "error") {
// X eyes
it.line(left_eye_x - 8, eye_y - 8, left_eye_x + 8, eye_y + 8);
it.line(left_eye_x + 8, eye_y - 8, left_eye_x - 8, eye_y + 8);
it.line(right_eye_x - 8, eye_y - 8, right_eye_x + 8, eye_y + 8);
it.line(right_eye_x + 8, eye_y - 8, right_eye_x - 8, eye_y + 8);
}
int bar = int(id(external_media_player).volume * 60);
if (bar != id(last_bar)) {
id(last_bar) = bar;
id(bar_timer) = 30;
}
if (id(bar_timer) > 0) {
id(bar_timer)--;
int bar = int(id(external_media_player).volume * 60);
it.rectangle(124, 1, 126, 60, COLOR_ON); // outline
it.filled_rectangle(124, 60 - bar, 126, 60, COLOR_ON); // fill bar
} else {
it.rectangle(124, 1, 126, 60, COLOR_OFF); // outline
it.filled_rectangle(124, 60 - bar, 126, 60, COLOR_OFF); // fill bar
}
# Globals for animation state
globals:
- id: eye_state
type: std::string
initial_value: '"idle"'
- id: blink_timer
type: int
initial_value: '0'
- id: last_bar
type: int
initial_value: "0"
- id: bar_timer
type: int
initial_value: "0"
api:
encryption:
key: !secret api
on_client_connected:
then:
- delay: 50ms
- micro_wake_word.start:
on_client_disconnected:
then:
- voice_assistant.stop:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fast connect for better performance
fast_connect: true
power_save_mode: none
ap:
ssid: "Esp32-S3-Wake-Word"
password: ""
captive_portal:
web_server:
port: 80
logger:
level: DEBUG
ota:
- platform: esphome
password: !secret ota