added sonic

This commit is contained in:
radu
2026-08-13 08:56:24 +07:00
parent 4b6dda3096
commit 45115f1724
2 changed files with 237 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
esp32_ble:
io_capability: none
max_notifications: 20
esp32_ble_tracker:
scan_parameters:
active: true
# bluetooth_proxy:
# active: true
external_components:
- source:
type: git
url: https://github.com/mtheli/philips_sonicare_ble
ref: master
path: esphome/components
components: [philips_sonicare]
refresh: 0s
philips_sonicare:
- id: philips_sonicare_ble
connected:
name: "Sonicare Connected"
on_connect:
then:
- logger.log: "Connected to Sonicare"
on_disconnect:
then:
- logger.log: "Disconnected from Sonicare"
+208
View File
@@ -0,0 +1,208 @@
globals:
# Global variable tracking the phase of the voice assistant (defined above). Initialized to not_ready
- id: voice_assistant_phase
type: int
restore_value: no
initial_value: "2"
- id: stt_vad_started
type: bool
restore_value: no
initial_value: "false"
i2s_audio:
- id: i2s_in
i2s_lrclk_pin: ${WS} #WS
i2s_bclk_pin: ${SCK} #SCK
microphone:
- platform: i2s_audio
id: mic_id
adc_type: external
i2s_audio_id: i2s_in
i2s_din_pin: ${SD} #SD
channel: right
sample_rate: 16000
bits_per_sample: 32bit
#correct_dc_offset: true
########################################################################
voice_assistant:
id: va
microphone:
microphone: echo_microphone
channels: 0
gain_factor: 4
noise_suppression_level: 2
auto_gain: 31dBFS
on_start:
- light.turn_on:
id: led
red: 0%
green: 100%
blue: 0%
brightness: 15%
effect: none
on_listening:
- light.turn_on:
id: led
blue: 100%
red: 0%
green: 0%
effect: none
- lambda: id(voice_assistant_phase) = 2;
- lambda: id(stt_vad_started) = false;
on_stt_vad_start:
# Turn off the script if speech is detected
- lambda: id(stt_vad_started) = true;
on_stt_vad_end:
#- logger.log: "===============================VAD is the END =================================="
- light.turn_on:
id: led
blue: 100%
red: 0%
green: 100%
effect: none
on_stt_end:
- logger.log:
format: "STT text: %s"
args: ["x.c_str()"]
on_tts_start:
then:
- light.turn_on:
id: led
blue: 100%
red: 100%
green: 100%
brightness: 30%
effect: none
# - light.turn_on:
# id: led
# blue: 100%
# red: 0%
# green: 0%
# brightness: 100%
# effect: none
on_tts_end:
- homeassistant.action:
action: media_player.play_media
data:
entity_id: ${SPKR}
media_content_id: !lambda "return x;"
media_content_type: music
announce: "false"
on_end:
- lambda: id(voice_assistant_phase) = 1;
- lambda: id(stt_vad_started) = false;
- script.execute: start_wake_word
#- voice_assistant.start:
on_error:
- if:
condition:
lambda: |-
return message.find("duplicate_wake_up_detected") != std::string::npos;
then:
- voice_assistant.stop:
- delay: 350ms
- script.execute: start_wake_word
else:
- lambda: id(voice_assistant_phase) = 4;
- light.turn_on:
id: led
red: 100%
green: 0%
blue: 0%
brightness: 100%
effect: "Slow Pulse"
- delay: 2s
- script.execute: rboot
#- script.execute: reset_led
on_client_connected:
- delay: 1s # Give the api server time to settle
- script.execute: start_wake_word
on_client_disconnected:
- lambda: id(voice_assistant_phase) = 4;
- script.execute: stop_wake_word
- script.execute: rboot
interval:
- interval: 30s
then:
- if:
condition:
and:
- api.connected:
- not:
- voice_assistant.is_running:
then:
- script.execute: start_wake_word
script:
- id: rboot
mode: restart
then:
- delay: 180s
- if:
condition:
lambda: |-
return id(voice_assistant_phase) == 4;
then:
- switch.turn_on:
id: rbt
- id: listening_timeout
mode: restart
then:
- delay: ${listenTimeout}
# - logger.log:
# format: "In Script >>>> C >>>> voice_assistant_phase=%d "
# args: [ 'id(voice_assistant_phase)' ]
- if:
condition:
lambda: |-
return id(voice_assistant_phase) == 2 && !id(stt_vad_started);
then:
- logger.log: "+++++++++++++++++++++++++ reset =========================================="
- light.turn_off:
id: led
- voice_assistant.stop:
- delay: 1s
- script.execute: start_wake_word
- id: start_wake_word
then:
- if:
condition:
#and:
- not:
- voice_assistant.is_running:
then:
- lambda: id(va).set_use_wake_word(true);
- voice_assistant.start_continuous:
- id: stop_wake_word
then:
- lambda: id(va).set_use_wake_word(false);
- voice_assistant.stop:
switch:
- platform: restart
name: Restart
id: rbt
- platform: template
name: Stop Listen
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF
#entity_category: config
on_turn_on:
- microphone.mute: echo_microphone
#- script.execute: stop_wake_word
on_turn_off:
- microphone.unmute: echo_microphone
#- script.execute: listening_timeout