From d40c7bcf1ff0d406a71a613ceba985cb8fd8a4b6 Mon Sep 17 00:00:00 2001 From: Aiden Date: Mon, 8 Dec 2025 20:38:41 +0800 Subject: [PATCH] add bluetooth proxy --- athom-garage-door.yaml | 43 ++++++++++++++++++++++++++++++++++++---- athom-mini-relay-v2.yaml | 43 ++++++++++++++++++++++++++++++++++++---- athom-rgbcw-bulb.yaml | 40 +++++++++++++++++++++++++++++++++++-- athom-rgbcw-light.yaml | 39 +++++++++++++++++++++++++++++++++++- athom-scd40-sensor.yaml | 36 ++++++++++++++++++++++++++++----- athom-sht40-sensor.yaml | 36 ++++++++++++++++++++++++++++----- 6 files changed, 216 insertions(+), 21 deletions(-) diff --git a/athom-garage-door.yaml b/athom-garage-door.yaml index 7edf7b7..ee4871a 100644 --- a/athom-garage-door.yaml +++ b/athom-garage-door.yaml @@ -8,9 +8,9 @@ substitutions: # Description as appears in ESPHome & top of webserver page device_description: "athom esp32-c3 garage door opener" # Project Name - project_name: "Athom Technology.Garage Door Opener" + project_name: "China Athom Technology.Garage Door Opener" # Project version denotes the release version of the yaml file, allowing checking of deployed vs latest version - project_version: "v3.0.1" + project_version: "v3.1.1" # Define a domain for this device to use. i.e. iot.home.lan (so device will appear as athom-smart-plug-v2.iot.home.lan in DNS/DHCP logs) dns_domain: ".local" # Set timezone of the smart plug. Useful if the plug is in a location different to the HA server. Can be entered in unix Country/Area format (i.e. "Australia/Sydney") @@ -35,7 +35,7 @@ esphome: comment: "${device_description}" area: "${room}" name_add_mac_suffix: true - min_version: 2025.7.0 + min_version: 2025.8.0 project: name: "${project_name}" version: "${project_version}" @@ -51,14 +51,36 @@ esp32: framework: type: esp-idf version: recommended + sdkconfig_options: + # @grigi found in testing that these options resulted in better responsiveness. + # BLE 4.2 is supported by ALL ESP32 boards that have bluetooth, the original and derivatives. + CONFIG_BT_BLE_42_FEATURES_SUPPORTED: y + # Also enable this on any derivative boards (S2, C3 etc) but not the original ESP32. + CONFIG_BT_BLE_50_FEATURES_SUPPORTED: y + # Extend the watchdog timeout, so the device reboots if the device appears locked up for over 10 seconds. + CONFIG_ESP_TASK_WDT_TIMEOUT_S: "10" api: + # reboot_timeout: 0s + # Only enable BLE tracking when wifi is up and api is connected + # Gives single-core ESP32-C3 devices time to manage wifi and authenticate with api + on_client_connected: + - esp32_ble_tracker.start_scan: + continuous: true + # Disable BLE tracking when there are no api connections live + on_client_disconnected: + if: + condition: + not: + api.connected: + then: + - esp32_ble_tracker.stop_scan: ota: - platform: esphome logger: - baud_rate: 115200 + baud_rate: 0 # 0 Enables logging, but disables serial-port logging to free CPU and memory level: ${log_level} hardware_uart: UART0 @@ -83,6 +105,19 @@ improv_serial: esp32_improv: authorizer: none +esp32_ble_tracker: + scan_parameters: + # Don't auto start BLE scanning, we control it in the `api` block's automation. + continuous: false + active: true # send scan-request packets to gather more info, like device name for some devices. + interval: 320ms # default 320ms - how long to spend on each advert channel + window: 300ms # default 30ms - how long to actually "listen" in each interval. Reduce this if device is unstable. + # If the device cannot keep up or becomes unstable, reduce the "window" setting. This may be + # required if your device is controlling other sensors or doing PWM for lights etc. + +bluetooth_proxy: + active: true + dashboard_import: package_import_url: github://athom-tech/esp32-configs/athom-garage-door.yaml diff --git a/athom-mini-relay-v2.yaml b/athom-mini-relay-v2.yaml index 38ef9cf..3f398f6 100644 --- a/athom-mini-relay-v2.yaml +++ b/athom-mini-relay-v2.yaml @@ -8,9 +8,9 @@ substitutions: # Description as appears in ESPHome & top of webserver page device_description: "athom esp32-c3 mini relay" # Project Name - project_name: "Athom Technology.Mini Relay V2" + project_name: "China Athom Technology.Mini Relay V2" # Projection version denotes the release version of the yaml file, allowing checking of deployed vs latest version - project_version: "v3.0.0" + project_version: "v3.1.0" # Restore the relay (GPO switch) upon reboot to state: light_restore_mode: RESTORE_DEFAULT_OFF # Set the update interval for sensors @@ -42,7 +42,7 @@ esphome: comment: "${device_description}" area: "${room}" name_add_mac_suffix: true - min_version: 2025.7.0 + min_version: 2025.8.0 project: name: "${project_name}" version: "${project_version}" @@ -58,18 +58,40 @@ esp32: framework: type: esp-idf version: recommended + sdkconfig_options: + # @grigi found in testing that these options resulted in better responsiveness. + # BLE 4.2 is supported by ALL ESP32 boards that have bluetooth, the original and derivatives. + CONFIG_BT_BLE_42_FEATURES_SUPPORTED: y + # Also enable this on any derivative boards (S2, C3 etc) but not the original ESP32. + CONFIG_BT_BLE_50_FEATURES_SUPPORTED: y + # Extend the watchdog timeout, so the device reboots if the device appears locked up for over 10 seconds. + CONFIG_ESP_TASK_WDT_TIMEOUT_S: "10" preferences: flash_write_interval: 5min api: + # reboot_timeout: 0s + # Only enable BLE tracking when wifi is up and api is connected + # Gives single-core ESP32-C3 devices time to manage wifi and authenticate with api + on_client_connected: + - esp32_ble_tracker.start_scan: + continuous: true + # Disable BLE tracking when there are no api connections live + on_client_disconnected: + if: + condition: + not: + api.connected: + then: + - esp32_ble_tracker.stop_scan: ota: - platform: esphome logger: + baud_rate: 0 # 0 Enables logging, but disables serial-port logging to free CPU and memory level: ${log_level} - baud_rate: 0 mdns: disabled: false @@ -93,6 +115,19 @@ captive_portal: esp32_improv: authorizer: none +esp32_ble_tracker: + scan_parameters: + # Don't auto start BLE scanning, we control it in the `api` block's automation. + continuous: false + active: true # send scan-request packets to gather more info, like device name for some devices. + interval: 320ms # default 320ms - how long to spend on each advert channel + window: 300ms # default 30ms - how long to actually "listen" in each interval. Reduce this if device is unstable. + # If the device cannot keep up or becomes unstable, reduce the "window" setting. This may be + # required if your device is controlling other sensors or doing PWM for lights etc. + +bluetooth_proxy: + active: true + dashboard_import: package_import_url: github://athom-tech/esp32-configs/athom-mini-relay-v2.yaml diff --git a/athom-rgbcw-bulb.yaml b/athom-rgbcw-bulb.yaml index bf913f4..daea3cf 100644 --- a/athom-rgbcw-bulb.yaml +++ b/athom-rgbcw-bulb.yaml @@ -10,7 +10,7 @@ substitutions: # Project Name project_name: "China Athom Technology.Athom RGBCW Bulb" # Projection version denotes the release version of the yaml file, allowing checking of deployed vs latest version - project_version: "v3.1.2" + project_version: "v3.2.1" # Restore the light (GPO switch) upon reboot to state: light_restore_mode: RESTORE_DEFAULT_ON # Define a domain for this device to use. i.e. iot.home.lan (so device will appear as athom-smart-plug-v2.iot.home.lan in DNS/DHCP logs) @@ -103,16 +103,40 @@ esp32: framework: type: esp-idf version: recommended + sdkconfig_options: + # @grigi found in testing that these options resulted in better responsiveness. + # BLE 4.2 is supported by ALL ESP32 boards that have bluetooth, the original and derivatives. + CONFIG_BT_BLE_42_FEATURES_SUPPORTED: y + # Also enable this on any derivative boards (S2, C3 etc) but not the original ESP32. + CONFIG_BT_BLE_50_FEATURES_SUPPORTED: y + # Extend the watchdog timeout, so the device reboots if the device appears locked up for over 10 seconds. + CONFIG_ESP_TASK_WDT_TIMEOUT_S: "10" preferences: flash_write_interval: 1min api: + # reboot_timeout: 0s + # Only enable BLE tracking when wifi is up and api is connected + # Gives single-core ESP32-C3 devices time to manage wifi and authenticate with api + on_client_connected: + - esp32_ble_tracker.start_scan: + continuous: true + # Disable BLE tracking when there are no api connections live + on_client_disconnected: + if: + condition: + not: + api.connected: + then: + - esp32_ble_tracker.stop_scan: ota: - platform: esphome logger: + baud_rate: 0 # 0 Enables logging, but disables serial-port logging to free CPU and memory + level: ${log_level} mdns: disabled: false @@ -131,12 +155,24 @@ wifi: # Define dns domain / suffix to add to hostname domain: "${dns_domain}" - captive_portal: esp32_improv: authorizer: none +esp32_ble_tracker: + scan_parameters: + # Don't auto start BLE scanning, we control it in the `api` block's automation. + continuous: false + active: true # send scan-request packets to gather more info, like device name for some devices. + interval: 320ms # default 320ms - how long to spend on each advert channel + window: 300ms # default 30ms - how long to actually "listen" in each interval. Reduce this if device is unstable. + # If the device cannot keep up or becomes unstable, reduce the "window" setting. This may be + # required if your device is controlling other sensors or doing PWM for lights etc. + +bluetooth_proxy: + active: true + dashboard_import: package_import_url: github://athom-tech/esp32-configs/athom-rgbcw-bulb.yaml diff --git a/athom-rgbcw-light.yaml b/athom-rgbcw-light.yaml index ee80436..ec50d5a 100644 --- a/athom-rgbcw-light.yaml +++ b/athom-rgbcw-light.yaml @@ -10,7 +10,7 @@ substitutions: # Project Name project_name: "China Athom Technology.Athom 12W RGBCW Bulb" # Projection version denotes the release version of the yaml file, allowing checking of deployed vs latest version - project_version: "v3.1.2" + project_version: "v3.1.3" # Restore the light (GPO switch) upon reboot to state: light_restore_mode: RESTORE_DEFAULT_ON # Define a domain for this device to use. i.e. iot.home.lan (so device will appear as athom-smart-plug-v2.iot.home.lan in DNS/DHCP logs) @@ -103,16 +103,40 @@ esp32: framework: type: esp-idf version: recommended + sdkconfig_options: + # @grigi found in testing that these options resulted in better responsiveness. + # BLE 4.2 is supported by ALL ESP32 boards that have bluetooth, the original and derivatives. + CONFIG_BT_BLE_42_FEATURES_SUPPORTED: y + # Also enable this on any derivative boards (S2, C3 etc) but not the original ESP32. + CONFIG_BT_BLE_50_FEATURES_SUPPORTED: y + # Extend the watchdog timeout, so the device reboots if the device appears locked up for over 10 seconds. + CONFIG_ESP_TASK_WDT_TIMEOUT_S: "10" preferences: flash_write_interval: 1min api: + # reboot_timeout: 0s + # Only enable BLE tracking when wifi is up and api is connected + # Gives single-core ESP32-C3 devices time to manage wifi and authenticate with api + on_client_connected: + - esp32_ble_tracker.start_scan: + continuous: true + # Disable BLE tracking when there are no api connections live + on_client_disconnected: + if: + condition: + not: + api.connected: + then: + - esp32_ble_tracker.stop_scan: ota: - platform: esphome logger: + baud_rate: 0 # 0 Enables logging, but disables serial-port logging to free CPU and memory + level: ${log_level} mdns: disabled: false @@ -137,6 +161,19 @@ captive_portal: esp32_improv: authorizer: none +esp32_ble_tracker: + scan_parameters: + # Don't auto start BLE scanning, we control it in the `api` block's automation. + continuous: false + active: true # send scan-request packets to gather more info, like device name for some devices. + interval: 320ms # default 320ms - how long to spend on each advert channel + window: 300ms # default 30ms - how long to actually "listen" in each interval. Reduce this if device is unstable. + # If the device cannot keep up or becomes unstable, reduce the "window" setting. This may be + # required if your device is controlling other sensors or doing PWM for lights etc. + +bluetooth_proxy: + active: true + dashboard_import: package_import_url: github://athom-tech/esp32-configs/athom-rgbcw-light.yaml diff --git a/athom-scd40-sensor.yaml b/athom-scd40-sensor.yaml index 89c5110..20a8e52 100644 --- a/athom-scd40-sensor.yaml +++ b/athom-scd40-sensor.yaml @@ -5,7 +5,7 @@ substitutions: room: "" device_description: "athom scd40 CO₂ sensor" project_name: "China Athom Technology.CO₂ Sensor" - project_version: "1.0.6" + project_version: "1.0.7" update_interval: 5s # Define a domain for this device to use. i.e. iot.home.lan (so device will appear as athom-smart-plug-v2.iot.home.lan in DNS/DHCP logs) dns_domain: ".local" @@ -57,18 +57,40 @@ esphome: esp32: board: esp32-c3-devkitm-1 flash_size: 4MB + variant: ESP32C3 framework: type: esp-idf version: recommended + sdkconfig_options: + # @grigi found in testing that these options resulted in better responsiveness. + # BLE 4.2 is supported by ALL ESP32 boards that have bluetooth, the original and derivatives. + CONFIG_BT_BLE_42_FEATURES_SUPPORTED: y + # Also enable this on any derivative boards (S2, C3 etc) but not the original ESP32. + CONFIG_BT_BLE_50_FEATURES_SUPPORTED: y + # Extend the watchdog timeout, so the device reboots if the device appears locked up for over 10 seconds. + CONFIG_ESP_TASK_WDT_TIMEOUT_S: "10" api: # reboot_timeout: 0s + # Only enable BLE tracking when wifi is up and api is connected + # Gives single-core ESP32-C3 devices time to manage wifi and authenticate with api + on_client_connected: + - esp32_ble_tracker.start_scan: + continuous: true + # Disable BLE tracking when there are no api connections live + on_client_disconnected: + if: + condition: + not: + api.connected: + then: + - esp32_ble_tracker.stop_scan: ota: - platform: esphome logger: - baud_rate: 115200 + baud_rate: 0 # 0 Enables logging, but disables serial-port logging to free CPU and memory level: ${log_level} mdns: @@ -94,9 +116,13 @@ esp32_improv: esp32_ble_tracker: scan_parameters: - interval: 320ms - window: 320ms - active: true + # Don't auto start BLE scanning, we control it in the `api` block's automation. + continuous: false + active: true # send scan-request packets to gather more info, like device name for some devices. + interval: 320ms # default 320ms - how long to spend on each advert channel + window: 300ms # default 30ms - how long to actually "listen" in each interval. Reduce this if device is unstable. + # If the device cannot keep up or becomes unstable, reduce the "window" setting. This may be + # required if your device is controlling other sensors or doing PWM for lights etc. bluetooth_proxy: active: true diff --git a/athom-sht40-sensor.yaml b/athom-sht40-sensor.yaml index c2c5433..98fdc70 100644 --- a/athom-sht40-sensor.yaml +++ b/athom-sht40-sensor.yaml @@ -5,7 +5,7 @@ substitutions: room: "" device_description: "athom sht40 temperature and humidity sensor" project_name: "China Athom Technology.Temperature Humidity Sensor" - project_version: "1.0.6" + project_version: "1.0.7" update_interval: 5s # Define a domain for this device to use. i.e. iot.home.lan (so device will appear as athom-smart-plug-v2.iot.home.lan in DNS/DHCP logs) dns_domain: ".local" @@ -59,21 +59,43 @@ esphome: esp32: board: esp32-c3-devkitm-1 flash_size: 4MB + variant: ESP32C3 framework: type: esp-idf version: recommended + sdkconfig_options: + # @grigi found in testing that these options resulted in better responsiveness. + # BLE 4.2 is supported by ALL ESP32 boards that have bluetooth, the original and derivatives. + CONFIG_BT_BLE_42_FEATURES_SUPPORTED: y + # Also enable this on any derivative boards (S2, C3 etc) but not the original ESP32. + CONFIG_BT_BLE_50_FEATURES_SUPPORTED: y + # Extend the watchdog timeout, so the device reboots if the device appears locked up for over 10 seconds. + CONFIG_ESP_TASK_WDT_TIMEOUT_S: "10" preferences: flash_write_interval: 1min api: # reboot_timeout: 0s + # Only enable BLE tracking when wifi is up and api is connected + # Gives single-core ESP32-C3 devices time to manage wifi and authenticate with api + on_client_connected: + - esp32_ble_tracker.start_scan: + continuous: true + # Disable BLE tracking when there are no api connections live + on_client_disconnected: + if: + condition: + not: + api.connected: + then: + - esp32_ble_tracker.stop_scan: ota: - platform: esphome logger: - baud_rate: 115200 + baud_rate: 0 # 0 Enables logging, but disables serial-port logging to free CPU and memory level: ${log_level} mdns: @@ -106,9 +128,13 @@ esp32_improv: esp32_ble_tracker: scan_parameters: - interval: 320ms - window: 320ms - active: true + # Don't auto start BLE scanning, we control it in the `api` block's automation. + continuous: false + active: true # send scan-request packets to gather more info, like device name for some devices. + interval: 320ms # default 320ms - how long to spend on each advert channel + window: 300ms # default 30ms - how long to actually "listen" in each interval. Reduce this if device is unstable. + # If the device cannot keep up or becomes unstable, reduce the "window" setting. This may be + # required if your device is controlling other sensors or doing PWM for lights etc. bluetooth_proxy: active: true