From 0da0cd154412b873bb66cc58c1c5d2b314e224bb Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Fri, 4 Dec 2026 00:53:07 +0100 Subject: [PATCH] Vehicle beacons: LED dark except a boot blink and while the gate's home beacon is seen, Wi-Fi + OTA on a 3 s button hold, 9 dBm, esp32_ble without the empty advertisement; gate: own home beacon, scan window 160/320 ms --- common/vehicle_base.yaml | 173 +++++++++++++++------------- mcu-gate.yaml | 17 +++ mcu-vehicle-honda-pcx125.yaml | 1 + mcu-vehicle-suzuki-dl650.yaml | 1 + mcu-vehicle-toyota-auris-ts.yaml | 17 +-- mcu-vehicle-toyota-yaris-cross.yaml | 1 + secrets.yaml.default | 5 +- 7 files changed, 114 insertions(+), 101 deletions(-) diff --git a/common/vehicle_base.yaml b/common/vehicle_base.yaml index 326849f..f0dfe6b 100644 --- a/common/vehicle_base.yaml +++ b/common/vehicle_base.yaml @@ -1,14 +1,7 @@ -esp32: - variant: esp32 - toolchain: esp-idf - framework: - advanced: - flash_chip: gd # ESP32-PICO-D4, like every other ATOM Lite - type: esp-idf - -external_components: - - source: components - +# Vehicle iBeacon on an M5Stack ATOM Lite: BLE only, Wi-Fi + OTA by holding the button. +# LED: short blue blink at boot, then dark; blue while the home beacon (mcu-gate) is seen; +# green while Wi-Fi is on. +# # PINOUTS: M5ATOM # IR G12 # NEO G27 @@ -24,85 +17,99 @@ external_components: # 1-WIRE G22 # NC G19 +esp32: + variant: esp32 + toolchain: esp-idf + framework: + advanced: + flash_chip: gd # ESP32-PICO-D4, like every other ATOM Lite + type: esp-idf + +# iBeacon on air from boot without the empty standard advertisement every 10 s +external_components: + - source: github://randybb/esphome-components + components: [esp32_ble] + +packages: + wifi: !include wifi.yaml + esphome: - on_loop: + on_boot: then: - lambda: |- - static uint32_t last_state = 0; - auto state = App.get_app_state(); - if (state != last_state) { - if (state & STATUS_LED_ERROR) { - auto call = id(led).turn_on(); - call.set_effect("ERROR"); - call.perform(); - } else if (state & STATUS_LED_WARNING) { - auto call = id(led).turn_on(); - call.set_effect("BOOT"); - call.perform(); - } else { - auto call = id(led).turn_on(); - call.set_effect("BEACON"); - call.perform(); - } - last_state = state; - } + - light.turn_on: + id: led + red: 0% + green: 0% + blue: 50% + transition_length: 0s + - delay: 300ms + - light.turn_off: + id: led + transition_length: 0s + +wifi: + enable_on_boot: false + +# flashed over USB straight to encrypted OTA, no password migration needed +ota: + - platform: esphome + encryption: + key: !secret api_key + +esp32_ble_tracker: + scan_parameters: + active: false + +binary_sensor: + - platform: gpio + id: button + pin: + number: 39 + inverted: true + on_press: + - delay: 3s + - if: + condition: + binary_sensor.is_on: button + then: + - wifi.enable: + - light.turn_on: + id: led + red: 0% + green: 50% + blue: 0% + transition_length: 0s + - platform: ble_presence + id: home + ibeacon_uuid: !secret ble_beacon_gate_uuid + timeout: 1min + on_press: + - if: + condition: + not: + wifi.enabled: + then: + - light.turn_on: + id: led + red: 0% + green: 0% + blue: 50% + transition_length: 0s + on_release: + - if: + condition: + not: + wifi.enabled: + then: + - light.turn_off: + id: led + transition_length: 0s light: - platform: esp32_rmt_led_strip - name: LED id: led - rgb_order: GRB + channel_colors: GRB pin: 27 num_leds: 1 chipset: ws2812 restore_mode: ALWAYS_OFF - effects: - - strobe: - name: "BEACON" - colors: - - state: true - red: 0% - green: 0% - blue: 50% - duration: 200ms - - state: false - duration: 200ms - - state: true - red: 0% - green: 0% - blue: 50% - duration: 200ms - - state: false - duration: 10s - - lambda: - name: "ERROR" - update_interval: 0.5s - lambda: |- - static bool state = false; - auto call = id(led).turn_on(); - call.set_transition_length(500); - call.set_rgb(1, 0, 0); - if (!state) { - call.set_brightness(1); - } else { - // If using 0, it freaks Home Assistant UI. - call.set_brightness(0.01); - } - call.perform(); - state = !state; - - lambda: - name: "BOOT" - update_interval: 0.5s - lambda: |- - static bool state = false; - auto call = id(led).turn_on(); - call.set_transition_length(500); - call.set_rgb(0, 1, 0); - if (!state) { - call.set_brightness(1); - } else { - // If using 0, it freaks Home Assistant UI. - call.set_brightness(0.01); - } - call.perform(); - state = !state; diff --git a/mcu-gate.yaml b/mcu-gate.yaml index d480c0b..aadaa33 100644 --- a/mcu-gate.yaml +++ b/mcu-gate.yaml @@ -34,6 +34,11 @@ esp32: flash_chip: gd type: esp-idf +# iBeacon on air from boot without the empty standard advertisement every 10 s +external_components: + - source: github://randybb/esphome-components + components: [esp32_ble] + packages: common: !include common/common.yaml ipv6_only: !include common/ipv6_only.yaml @@ -107,8 +112,20 @@ globals: esp32_ble_tracker: id: ${device}_ble_tracker + # window 160/320 ms (default 30): hears the vehicle beacons sooner, half the airtime stays for Wi-Fi scan_parameters: duration: 1min + interval: 320ms + window: 160ms + active: false + +# home beacon: the vehicles light their LED while they see it +esp32_ble_beacon: + type: iBeacon + uuid: !secret ble_beacon_gate_uuid + min_interval: 1s + max_interval: 1s + tx_power: 9dBm binary_sensor: - platform: ble_presence diff --git a/mcu-vehicle-honda-pcx125.yaml b/mcu-vehicle-honda-pcx125.yaml index 96e9362..1de6d20 100644 --- a/mcu-vehicle-honda-pcx125.yaml +++ b/mcu-vehicle-honda-pcx125.yaml @@ -22,3 +22,4 @@ esp32_ble_beacon: uuid: !secret ble_beacon_honda_uuid major: !secret ble_beacon_honda_major minor: !secret ble_beacon_honda_minor + tx_power: 9dBm diff --git a/mcu-vehicle-suzuki-dl650.yaml b/mcu-vehicle-suzuki-dl650.yaml index 84ba1a0..c51a7c3 100644 --- a/mcu-vehicle-suzuki-dl650.yaml +++ b/mcu-vehicle-suzuki-dl650.yaml @@ -22,3 +22,4 @@ esp32_ble_beacon: uuid: !secret ble_beacon_suzuki_uuid major: !secret ble_beacon_suzuki_major minor: !secret ble_beacon_suzuki_minor + tx_power: 9dBm diff --git a/mcu-vehicle-toyota-auris-ts.yaml b/mcu-vehicle-toyota-auris-ts.yaml index 5b5c580..ecd97f5 100644 --- a/mcu-vehicle-toyota-auris-ts.yaml +++ b/mcu-vehicle-toyota-auris-ts.yaml @@ -12,29 +12,14 @@ esphome: friendly_name: ${name} area: ${area} comment: ${comment} - on_boot: - then: - - if: - condition: - - binary_sensor.is_off: button - then: - - wifi.disable: packages: base: !include common/vehicle_base.yaml - wifi: !include common/wifi.yaml logger: !include common/logger.yaml - ota: !include common/ota.yaml - -binary_sensor: - - platform: gpio - id: button - filters: - - invert: - pin: 39 esp32_ble_beacon: type: iBeacon uuid: !secret ble_beacon_toyota_auris_uuid major: !secret ble_beacon_toyota_auris_major minor: !secret ble_beacon_toyota_auris_minor + tx_power: 9dBm diff --git a/mcu-vehicle-toyota-yaris-cross.yaml b/mcu-vehicle-toyota-yaris-cross.yaml index 3dc7487..75c7def 100644 --- a/mcu-vehicle-toyota-yaris-cross.yaml +++ b/mcu-vehicle-toyota-yaris-cross.yaml @@ -22,3 +22,4 @@ esp32_ble_beacon: uuid: !secret ble_beacon_toyota_yaris_uuid major: !secret ble_beacon_toyota_yaris_major minor: !secret ble_beacon_toyota_yaris_minor + tx_power: 9dBm diff --git a/secrets.yaml.default b/secrets.yaml.default index 95a1a2f..a8abe51 100644 --- a/secrets.yaml.default +++ b/secrets.yaml.default @@ -31,8 +31,9 @@ ble_beacon_toyota_auris_uuid: "00000000-0000-0000-0000-000000000000" ble_beacon_toyota_auris_major: 10167 ble_beacon_toyota_auris_minor: 61958 ble_beacon_toyota_yaris_uuid: "00000000-0000-0000-0000-000000000000" -ble_beacon_toyota_yaris_honda_major: 10167 -ble_beacon_toyota_yaris_honda_minor: 61958 +ble_beacon_toyota_yaris_major: 10167 +ble_beacon_toyota_yaris_minor: 61958 +ble_beacon_gate_uuid: "00000000-0000-0000-0000-000000000000" # Thread active dataset (hex TLV) from Home Assistant thread_tlv: "0E080000000000010000"