Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split firmware into small files #235

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,675 changes: 11 additions & 1,664 deletions home-assistant-voice.yaml

Large diffs are not rendered by default.

139 changes: 139 additions & 0 deletions modules/center-button.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
binary_sensor:
# Center Button. Used for many things (See on_multi_click)
- platform: gpio
id: center_button
pin:
number: GPIO0
inverted: true
on_press:
- script.execute: control_leds
on_release:
- script.execute: control_leds
on_multi_click:
# Simple Click:
# - Abort "things" in order
# - Timer
# - Announcements
# - Voice Assistant Pipeline run
# - Music
# - Starts the voice assistant if it is not yet running and if the device is not muted.
- timing:
- ON for at most 1s
- OFF for at least 0.25s
then:
- if:
condition:
lambda: return !id(init_in_progress) && !id(color_changed);
then:
- if:
condition:
switch.is_on: timer_ringing
then:
- switch.turn_off: timer_ringing
else:
- if:
condition:
lambda: return id(nabu_media_player)->state == media_player::MediaPlayerState::MEDIA_PLAYER_STATE_ANNOUNCING;
then:
- lambda: |
id(nabu_media_player)
->make_call()
.set_command(media_player::MediaPlayerCommand::MEDIA_PLAYER_COMMAND_STOP)
.set_announcement(true)
.perform();
else:
- if:
condition:
voice_assistant.is_running:
then:
- voice_assistant.stop:
else:
- if:
condition:
media_player.is_playing:
then:
- media_player.pause:
else:
- if:
condition:
and:
- switch.is_off: master_mute_switch
- not:
voice_assistant.is_running
then:
- script.execute:
id: play_sound
priority: true
sound_file: !lambda return id(center_button_press_sound);
- delay: 300ms
- voice_assistant.start:
# Double Click
# . Exposed as an event entity. To be used in automations inside Home Assistant
- timing:
- ON for at most 1s
- OFF for at most 0.25s
- ON for at most 1s
- OFF for at least 0.25s
then:
- if:
condition:
lambda: return !id(init_in_progress) && !id(color_changed);
then:
- script.execute:
id: play_sound
priority: false
sound_file: !lambda return id(center_button_double_press_sound);
- event.trigger:
id: button_press_event
event_type: "double_press"
# Triple Click
# . Exposed as an event entity. To be used in automations inside Home Assistant
- timing:
- ON for at most 1s
- OFF for at most 0.25s
- ON for at most 1s
- OFF for at most 0.25s
- ON for at most 1s
- OFF for at least 0.25s
then:
- if:
condition:
lambda: return !id(init_in_progress) && !id(color_changed);
then:
- script.execute:
id: play_sound
priority: false
sound_file: !lambda return id(center_button_triple_press_sound);
- event.trigger:
id: button_press_event
event_type: "triple_press"
# Long Press
# . Exposed as an event entity. To be used in automations inside Home Assistant
- timing:
- ON for at least 1s
then:
- if:
condition:
lambda: return !id(init_in_progress) && !id(color_changed);
then:
- script.execute:
id: play_sound
priority: false
sound_file: !lambda return id(center_button_long_press_sound);
- light.turn_off: voice_assistant_leds
- event.trigger:
id: button_press_event
event_type: "long_press"

event:
# Event entity exposed to the user to automate on complex center button presses.
# The simple press is not exposed as it is used to control the device itself.
- platform: template
id: button_press_event
name: "Button press"
icon: mdi:button-pointer
device_class: button
event_types:
- double_press
- triple_press
- long_press
143 changes: 143 additions & 0 deletions modules/device-base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
esphome:
name: home-assistant-voice
friendly_name: Home Assistant Voice
name_add_mac_suffix: true
min_version: 2024.12.2
platformio_options:
board_build.flash_mode: dio
on_boot:
priority: 375
then:
# Run the script to refresh the LED status
- script.execute: control_leds
- delay: 1s
- switch.turn_on: internal_speaker_amp
# If the hardware switch is ON, force the software switch to be ON too. This covers the case where the Mute hardware switch is operated when the device is turned off
- if:
condition:
binary_sensor.is_on: hardware_mute_switch
then:
- switch.template.publish:
id: master_mute_switch
state: ON
# If after 10 minutes, the device is still initializing (It did not yet connect to Home Assistant), turn off the init_in_progress variable and run the script to refresh the LED status
- delay: 10min
- if:
condition:
lambda: return id(init_in_progress);
then:
- lambda: id(init_in_progress) = false;
- script.execute: control_leds

esp32:
board: esp32-s3-devkitc-1
variant: esp32s3
flash_size: 16MB
framework:
type: esp-idf
version: recommended
sdkconfig_options:
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: "y"
CONFIG_ESP32S3_DATA_CACHE_64KB: "y"
CONFIG_ESP32S3_DATA_CACHE_LINE_64B: "y"
CONFIG_ESP32S3_INSTRUCTION_CACHE_32KB: "y"
CONFIG_ESP32_S3_BOX_BOARD: "y"
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY: "y"

CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP: "y"

# Settings based on https://github.com/espressif/esp-adf/issues/297#issuecomment-783811702
CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM: "16"
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM: "512"
CONFIG_ESP32_WIFI_STATIC_TX_BUFFER: "y"
CONFIG_ESP32_WIFI_TX_BUFFER_TYPE: "0"
CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM: "8"
CONFIG_ESP32_WIFI_CACHE_TX_BUFFER_NUM: "32"
CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED: "y"
CONFIG_ESP32_WIFI_TX_BA_WIN: "16"
CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED: "y"
CONFIG_ESP32_WIFI_RX_BA_WIN: "32"
CONFIG_LWIP_MAX_ACTIVE_TCP: "16"
CONFIG_LWIP_MAX_LISTENING_TCP: "16"
CONFIG_TCP_MAXRTX: "12"
CONFIG_TCP_SYNMAXRTX: "6"
CONFIG_TCP_MSS: "1436"
CONFIG_TCP_MSL: "60000"
CONFIG_TCP_SND_BUF_DEFAULT: "65535"
CONFIG_TCP_WND_DEFAULT: "65535" # Adjusted from linked settings to avoid compilation error
CONFIG_TCP_RECVMBOX_SIZE: "512"
CONFIG_TCP_QUEUE_OOSEQ: "y"
CONFIG_TCP_OVERSIZE_MSS: "y"
CONFIG_LWIP_WND_SCALE: "y"
CONFIG_TCP_RCV_SCALE: "3"
CONFIG_LWIP_TCPIP_RECVMBOX_SIZE: "512"

CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST: "y"
CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY: "y"

CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC: "y"

globals:
# Global initialization variable. Initialized to true and set to false once everything is connected. Only used to have a smooth "plugging" experience
- id: init_in_progress
type: bool
restore_value: no
initial_value: 'true'
# Global variable storing the state of ImprovBLE. Used to draw different LED animations
- id: improv_ble_in_progress
type: bool
restore_value: no
initial_value: 'false'

wifi:
id: wifi_id
on_connect:
- lambda: id(improv_ble_in_progress) = false;
- script.execute: control_leds
on_disconnect:
- script.execute: control_leds

logger:
level: DEBUG
logs:
sensor: WARN # avoids logging debug sensor updates

api:
id: api_id
on_client_connected:
- script.execute: control_leds
on_client_disconnected:
- script.execute: control_leds

ota:
- platform: esphome
id: ota_esphome

i2c:
- id: internal_i2c
sda: GPIO5
scl: GPIO6
frequency: 400kHz

psram:
mode: octal
speed: 80MHz

switch:
- platform: gpio
pin: GPIO47
id: internal_speaker_amp
name: "Internal speaker amp"
entity_category: config
restore_mode: ALWAYS_OFF
internal: true

button:
- platform: factory_reset
id: factory_reset_button
name: "Factory Reset"
entity_category: diagnostic
internal: true

debug:
update_interval: 5s
Loading
Loading