-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathesp32-s3-mini-intercom.yaml
More file actions
347 lines (311 loc) · 9.69 KB
/
esp32-s3-mini-intercom.yaml
File metadata and controls
347 lines (311 loc) · 9.69 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
# ==============================================================================
# ESP32-S3 INTERCOM MINI - New TCP-based API
# ==============================================================================
#
# Uses the new intercom_api component with TCP streaming on port 6054.
# Clean YAML syntax with native platform entities (no lambdas!)
#
# HARDWARE:
# - Board: ESP32-S3 Mini (4MB Flash, Quad PSRAM)
# - Microphone: SPH0645 I2S MEMS (I2S_NUM_0) - has DC offset
# - Speaker: MAX98357A I2S amplifier (I2S_NUM_1)
# - LED: WS2812 RGB (GPIO21)
#
# GPIO PINOUT:
# Microphone (SPH0645):
# - WS/LRCLK: GPIO3
# - SCK/BCLK: GPIO2
# - SD/DIN: GPIO4
#
# Speaker (MAX98357A):
# - LRC/LRCLK: GPIO6
# - BCLK: GPIO7
# - DIN: GPIO8
#
# LED (WS2812):
# - DATA: GPIO21
#
# ==============================================================================
substitutions:
name: esp32-s3-mini-intercom
friendly_name: ESP32-S3 Mini Intercom
esphome:
name: ${name}
friendly_name: ${friendly_name}
platformio_options:
board_build.flash_mode: dio
esp32:
board: esp32-s3-devkitc-1
variant: esp32s3
framework:
type: esp-idf
sdkconfig_options:
CONFIG_LWIP_MAX_SOCKETS: "16"
CONFIG_ESP32S3_DATA_CACHE_64KB: "y"
CONFIG_ESP32S3_DATA_CACHE_LINE_64B: "y"
CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC: "y"
psram:
mode: quad # Mini has quad PSRAM
speed: 80MHz
# ==============================================================================
# CONNECTIVITY
# ==============================================================================
api:
on_client_connected:
- lambda: |-
static bool published = false;
if (!published) {
published = true;
id(intercom).publish_entity_states();
}
ota:
- platform: esphome
logger:
hardware_uart: UART0
level: INFO
logs:
intercom_api: INFO
component: INFO
network:
enable_high_performance: true
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# ==============================================================================
# EXTERNAL COMPONENTS
# ==============================================================================
external_components:
- source:
type: git
url: https://github.com/n-IA-hane/esphome-intercom
ref: main
components: [intercom_api, esp_aec]
# ==============================================================================
# I2S AUDIO BUSES
# ==============================================================================
i2s_audio:
# I2S Bus 0: SPH0645 Microphone
- id: i2s_mic_bus
i2s_lrclk_pin: GPIO3
i2s_bclk_pin: GPIO2
# I2S Bus 1: MAX98357A Speaker
- id: i2s_spk_bus
i2s_lrclk_pin: GPIO6
i2s_bclk_pin: GPIO7
# ==============================================================================
# MICROPHONE (SPH0645)
# ==============================================================================
microphone:
- platform: i2s_audio
id: mic_component
i2s_audio_id: i2s_mic_bus
i2s_din_pin: GPIO4
adc_type: external
pdm: false
bits_per_sample: 32bit
sample_rate: 16000
channel: left
# ==============================================================================
# SPEAKER (MAX98357A)
# ==============================================================================
speaker:
- platform: i2s_audio
id: spk_component
i2s_audio_id: i2s_spk_bus
i2s_dout_pin: GPIO8
dac_type: external
i2s_mode: primary
sample_rate: 16000
bits_per_sample: 16bit
timeout: never # Keep I2S running (avoids clicks on resume)
buffer_duration: 100ms # Low latency buffer for real-time intercom
# ==============================================================================
# AEC (Acoustic Echo Cancellation)
# ==============================================================================
esp_aec:
id: aec_processor
sample_rate: 16000
filter_length: 8 # 8 = 128ms tail (max value, covers most latency scenarios)
mode: voip_high_perf # High performance AEC for better echo cancellation
# ==============================================================================
# INTERCOM API (TCP-based, port 6054)
# ==============================================================================
# Auto-creates these sensors:
# - text_sensor.intercom_mini_intercom_state (Idle/Ringing/Streaming)
# - text_sensor.intercom_mini_destination (selected contact) [full mode only]
# - text_sensor.intercom_mini_caller (who is calling) [full mode only]
# - text_sensor.intercom_mini_contacts (count) [full mode only]
intercom_api:
id: intercom
mode: full # full = ESP↔ESP calls with contacts, simple = browser only
microphone: mic_component
speaker: spk_component
dc_offset_removal: true # SPH0645 has DC bias that must be removed
aec_id: aec_processor # Links to esp_aec for echo cancellation
ringing_timeout: 30s # Auto-decline unanswered calls
# === FSM event callbacks ===
on_outgoing_call:
- light.turn_on:
id: status_led
effect: "Ringing"
red: 100%
green: 50%
blue: 0%
# Fire HA event when calling "Home Assistant" (for notifications/automations)
- if:
condition:
intercom_api.destination_is:
id: intercom
destination: "Home Assistant"
then:
- homeassistant.event:
event: esphome.intercom_call
data:
caller: "${friendly_name}"
destination: "Home Assistant"
type: "doorbell"
on_ringing:
- light.turn_on:
id: status_led
effect: "Ringing"
red: 100%
green: 0%
blue: 0%
on_answered:
- logger.log: "Call answered"
on_streaming:
- light.turn_on:
id: status_led
effect: none
red: 0%
green: 100%
blue: 0%
on_idle:
- light.turn_off: status_led
on_hangup:
- logger.log:
format: "Hangup: %s"
args: ['reason.c_str()']
on_call_failed:
- logger.log:
format: "Call failed: %s"
args: ['reason.c_str()']
# ==============================================================================
# BUTTONS
# ==============================================================================
button:
# Smart Call button: idle→call, ringing→answer, streaming→hangup
# The on_outgoing_call callback handles the HA event for doorbell notifications
- platform: template
id: call_button
name: "Call"
icon: "mdi:phone"
on_press:
- intercom_api.call_toggle:
id: intercom
# Next contact (full mode)
- platform: template
id: next_contact_button
name: "Next Contact"
icon: "mdi:arrow-right"
on_press:
- intercom_api.next_contact:
id: intercom
# Previous contact (full mode)
- platform: template
id: prev_contact_button
name: "Previous Contact"
icon: "mdi:arrow-left"
on_press:
- intercom_api.prev_contact:
id: intercom
# Decline incoming call
- platform: template
id: decline_button
name: "Decline"
icon: "mdi:phone-hangup"
on_press:
- intercom_api.decline_call:
id: intercom
- platform: restart
name: "Restart"
icon: "mdi:restart"
# ==============================================================================
# SWITCHES (native platform with restore_mode)
# ==============================================================================
switch:
- platform: intercom_api
intercom_api_id: intercom
auto_answer:
id: auto_answer_switch
name: "Auto Answer"
restore_mode: RESTORE_DEFAULT_ON
aec:
id: aec_switch
name: "Echo Cancellation"
restore_mode: RESTORE_DEFAULT_ON
# ==============================================================================
# NUMBERS (native platform with restore_value)
# ==============================================================================
number:
- platform: intercom_api
intercom_api_id: intercom
speaker_volume:
id: speaker_volume
name: "Speaker Volume"
mic_gain:
id: mic_gain
name: "Mic Gain"
# ==============================================================================
# STATUS LED (WS2812 RGB on GPIO21)
# ==============================================================================
light:
- platform: esp32_rmt_led_strip
id: status_led
name: "Status LED"
icon: "mdi:led-on"
pin: GPIO21
chipset: WS2812
num_leds: 1
rgb_order: RGB
effects:
- pulse:
name: "Streaming"
min_brightness: 20%
max_brightness: 100%
- strobe:
name: "Ringing"
colors:
- state: true
brightness: 100%
red: 100%
green: 0%
blue: 0%
duration: 250ms
- state: false
duration: 250ms
# ==============================================================================
# TEXT SENSORS
# ==============================================================================
text_sensor:
# Subscribe to HA's centralized contacts sensor
- platform: homeassistant
id: ha_active_devices
entity_id: sensor.intercom_active_devices
on_value:
- intercom_api.set_contacts:
id: intercom
contacts_csv: !lambda 'return x;'
# ==============================================================================
# DIAGNOSTICS
# ==============================================================================
sensor:
- platform: wifi_signal
name: "WiFi Signal"
update_interval: 60s
- platform: uptime
name: "Uptime"
update_interval: 60s
- platform: internal_temperature
name: "CPU Temperature"
update_interval: 60s