From dd033f69bb4b213c051e846d8a513ed341054fa8 Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Thu, 19 Feb 2026 11:32:23 +0100 Subject: [PATCH] Refactor vehicle beacon configs and clean up gate Extract shared M5ATOM vehicle code (esp32, on_loop, LED effects) into common/vehicle_base.yaml, reducing each vehicle file from ~136 to 20 lines. Remove dead commented-out code from on_loop lambda. Gate: fix on_multi_click and select indentation, change esp32_ble_tracker id from ${name} to ${device} (lowercase), remove unused commented-out gate_flash GPIO sensor. Co-Authored-By: Claude Sonnet 4.6 --- common/vehicle_base.yaml | 105 ++++++++++++++++++++++++ mcu-gate.yaml | 98 ++++++++++------------- mcu-vehicle-honda-pcx125.yaml | 118 +-------------------------- mcu-vehicle-suzuki-dl650.yaml | 118 +-------------------------- mcu-vehicle-toyota-auris-ts.yaml | 119 +--------------------------- mcu-vehicle-toyota-yaris-cross.yaml | 119 +--------------------------- 6 files changed, 155 insertions(+), 522 deletions(-) create mode 100644 common/vehicle_base.yaml diff --git a/common/vehicle_base.yaml b/common/vehicle_base.yaml new file mode 100644 index 0000000..2390e61 --- /dev/null +++ b/common/vehicle_base.yaml @@ -0,0 +1,105 @@ +esp32: + variant: esp32 + framework: + type: esp-idf + +external_components: + - source: components + +# PINOUTS: M5ATOM +# IR G12 +# NEO G27 +# BUTTON G39 +# I2C0 SDA G26 +# I2C0 SCL G32 +# I2C1 SDA G25 +# I2C1 SCL G21 +# UART0 RX G3 +# UART0 TX G1 +# UART1 RX G23 +# UART1 TX G33 +# 1-WIRE G22 +# NC G19 + +esphome: + on_loop: + 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: + - platform: esp32_rmt_led_strip + name: LED + id: led + rgb_order: 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 248c61f..399cee2 100644 --- a/mcu-gate.yaml +++ b/mcu-gate.yaml @@ -93,14 +93,11 @@ switch: optimistic: true restore_mode: RESTORE_DEFAULT_ON -# Bluetooth related stuff esp32_ble_tracker: - id: ${name}_ble_tracker + id: ${device}_ble_tracker scan_parameters: duration: 1min -# bluetooth_proxy: - binary_sensor: - platform: ble_presence id: ibeacon_auris @@ -210,15 +207,6 @@ binary_sensor: - binary_sensor.is_off: ibeacon_pcx125 then: - button.press: gate_close - # - platform: gpio - # id: gate_flash - # pin: - # number: 26 - # inverted: true - # mode: - # input: true - # filters: - # - delayed_on: 10ms - platform: gpio id: gate_ogi pin: @@ -230,53 +218,53 @@ binary_sensor: - delayed_on: 10ms entity_category: diagnostic on_multi_click: - - timing: - - OFF for at least 1500ms - then: - - select.set: - id: gate_state - option: Closed - - logger.log: "OGI OFF => GATE CLOSED" - invalid_cooldown: 100ms - - timing: - - ON for at least 400ms - - OFF for at least 400ms - - ON for at least 400ms - - OFF for at least 400ms - then: - - select.set: - id: gate_state - option: Opening - - logger.log: "OGI SLOW BLINK => GATE OPENING" - invalid_cooldown: 100ms - - timing: - - ON for at most 300ms - - OFF for at most 300ms - - ON for at most 300ms - - OFF for at most 300ms - then: - - select.set: - id: gate_state - option: Closing - - logger.log: "OGI FAST BLINK => GATE CLOSING" - invalid_cooldown: 100ms - - timing: - - ON for at least 1500ms - then: - - select.set: - id: gate_state - option: Open - - logger.log: "OGI ON => GATE OPEN" - invalid_cooldown: 100ms + - timing: + - OFF for at least 1500ms + then: + - select.set: + id: gate_state + option: Closed + - logger.log: "OGI OFF => GATE CLOSED" + invalid_cooldown: 100ms + - timing: + - ON for at least 400ms + - OFF for at least 400ms + - ON for at least 400ms + - OFF for at least 400ms + then: + - select.set: + id: gate_state + option: Opening + - logger.log: "OGI SLOW BLINK => GATE OPENING" + invalid_cooldown: 100ms + - timing: + - ON for at most 300ms + - OFF for at most 300ms + - ON for at most 300ms + - OFF for at most 300ms + then: + - select.set: + id: gate_state + option: Closing + - logger.log: "OGI FAST BLINK => GATE CLOSING" + invalid_cooldown: 100ms + - timing: + - ON for at least 1500ms + then: + - select.set: + id: gate_state + option: Open + - logger.log: "OGI ON => GATE OPEN" + invalid_cooldown: 100ms select: - platform: template name: State id: gate_state options: - - Open - - Closed - - Opening - - Closing + - Open + - Closed + - Opening + - Closing initial_option: Closed optimistic: true diff --git a/mcu-vehicle-honda-pcx125.yaml b/mcu-vehicle-honda-pcx125.yaml index f468d4b..e52c683 100644 --- a/mcu-vehicle-honda-pcx125.yaml +++ b/mcu-vehicle-honda-pcx125.yaml @@ -9,127 +9,13 @@ esphome: friendly_name: ${name} area: ${area} comment: ${comment} - on_loop: - 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_off(); - //call.perform(); - auto call = id(led).turn_on(); - call.set_effect("BEACON"); - call.perform(); - } - last_state = state; - } - -esp32: - variant: esp32 - framework: - type: esp-idf - -# api: -# reboot_timeout: 0s - -# wifi: -# reboot_timeout: 0s - -external_components: - - source: components packages: - common: !include common/logger.yaml -# common: !include common/common.yaml - -# debug: - -# PINOUTS: M5ATOM -# IR G12 -# NEO G27 -# BUTTON G39 -# I2C0 SDA G26 -# I2C0 SCL G32 -# I2C1 SDA G25 -# I2C1 SCL G21 -# UART0 RX G3 -# UART0 TX G1 -# UART1 RX G23 -# UART1 TX G33 -# 1-WIRE G22 -# NC G19 + base: !include common/vehicle_base.yaml + logger: !include common/logger.yaml esp32_ble_beacon: type: iBeacon uuid: !secret ble_beacon_honda_uuid major: !secret ble_beacon_honda_major minor: !secret ble_beacon_honda_minor - -light: - - platform: esp32_rmt_led_strip - name: LED - id: led - rgb_order: 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-vehicle-suzuki-dl650.yaml b/mcu-vehicle-suzuki-dl650.yaml index 0c082da..0d0c4fe 100644 --- a/mcu-vehicle-suzuki-dl650.yaml +++ b/mcu-vehicle-suzuki-dl650.yaml @@ -9,127 +9,13 @@ esphome: friendly_name: ${name} area: ${area} comment: ${comment} - on_loop: - 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_off(); - //call.perform(); - auto call = id(led).turn_on(); - call.set_effect("BEACON"); - call.perform(); - } - last_state = state; - } - -esp32: - variant: esp32 - framework: - type: esp-idf - -# api: -# reboot_timeout: 0s - -# wifi: -# reboot_timeout: 0s - -external_components: - - source: components packages: - common: !include common/logger.yaml -# common: !include common/common.yaml - -# debug: - -# PINOUTS: M5ATOM -# IR G12 -# NEO G27 -# BUTTON G39 -# I2C0 SDA G26 -# I2C0 SCL G32 -# I2C1 SDA G25 -# I2C1 SCL G21 -# UART0 RX G3 -# UART0 TX G1 -# UART1 RX G23 -# UART1 TX G33 -# 1-WIRE G22 -# NC G19 + base: !include common/vehicle_base.yaml + logger: !include common/logger.yaml esp32_ble_beacon: type: iBeacon uuid: !secret ble_beacon_suzuki_uuid major: !secret ble_beacon_suzuki_major minor: !secret ble_beacon_suzuki_minor - -light: - - platform: esp32_rmt_led_strip - name: LED - id: led - rgb_order: 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-vehicle-toyota-auris-ts.yaml b/mcu-vehicle-toyota-auris-ts.yaml index 4a50b29..c575f23 100644 --- a/mcu-vehicle-toyota-auris-ts.yaml +++ b/mcu-vehicle-toyota-auris-ts.yaml @@ -16,69 +16,12 @@ esphome: - binary_sensor.is_off: button then: - wifi.disable: - on_loop: - 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_off(); - //call.perform(); - auto call = id(led).turn_on(); - call.set_effect("BEACON"); - call.perform(); - } - last_state = state; - } - -esp32: - variant: esp32 - framework: - type: esp-idf - # version: 5.3.2 - # platform_version: 53.03.11 - -external_components: - - source: components packages: + base: !include common/vehicle_base.yaml wifi: !include common/wifi.yaml logger: !include common/logger.yaml - # api: !include common/api.yaml ota: !include common/ota.yaml -# common: !include common/common.yaml - -# api: -# reboot_timeout: 0s - -# wifi: -# enable_on_boot: false - -# debug: - -# PINOUTS: M5ATOM -# IR G12 -# NEO G27 -# BUTTON G39 -# I2C0 SDA G26 -# I2C0 SCL G32 -# I2C1 SDA G25 -# I2C1 SCL G21 -# UART0 RX G3 -# UART0 TX G1 -# UART1 RX G23 -# UART1 TX G33 -# 1-WIRE G22 -# NC G19 binary_sensor: - platform: gpio @@ -92,63 +35,3 @@ esp32_ble_beacon: uuid: !secret ble_beacon_toyota_auris_uuid major: !secret ble_beacon_toyota_auris_major minor: !secret ble_beacon_toyota_auris_minor - -light: - - platform: esp32_rmt_led_strip - name: LED - id: led - rgb_order: 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-vehicle-toyota-yaris-cross.yaml b/mcu-vehicle-toyota-yaris-cross.yaml index e3039a2..3be866c 100644 --- a/mcu-vehicle-toyota-yaris-cross.yaml +++ b/mcu-vehicle-toyota-yaris-cross.yaml @@ -9,128 +9,13 @@ esphome: friendly_name: ${name} area: ${area} comment: ${comment} - on_loop: - 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_off(); - //call.perform(); - auto call = id(led).turn_on(); - call.set_effect("BEACON"); - call.perform(); - } - last_state = state; - } - -esp32: - variant: esp32 - framework: - type: esp-idf - -# api: -# reboot_timeout: 0s - -# wifi: -# reboot_timeout: 0s - -external_components: - - source: components packages: - common: !include common/logger.yaml - # wifi: !include common/wifi.yaml - # common: !include common/common.yaml - -# debug: - -# PINOUTS: M5ATOM -# IR G12 -# NEO G27 -# BUTTON G39 -# I2C0 SDA G26 -# I2C0 SCL G32 -# I2C1 SDA G25 -# I2C1 SCL G21 -# UART0 RX G3 -# UART0 TX G1 -# UART1 RX G23 -# UART1 TX G33 -# 1-WIRE G22 -# NC G19 + base: !include common/vehicle_base.yaml + logger: !include common/logger.yaml esp32_ble_beacon: type: iBeacon uuid: !secret ble_beacon_toyota_yaris_uuid major: !secret ble_beacon_toyota_yaris_major minor: !secret ble_beacon_toyota_yaris_minor - -light: - - platform: esp32_rmt_led_strip - name: LED - id: led - rgb_order: 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;