============================================================
代码 F - 无 LED 版本(最终修正)
============================================================
substitutions:
friendly_name: Tesla BLE
device_name: tesla-ble
device_description: Tesla BLE
ble_mac_address: !secret ble_mac_address
tesla_vin: !secret tesla_vin
auto_lock_delay: 30s
board: esp32-s3-devkitc-1
variant: ESP32S3
flash_size: 8MB
esphome:
name: ${device_name}
friendly_name: ${friendly_name}
name_add_mac_suffix: false
platformio_options:
build_flags:
- -DESPHOME_DISABLE_STRAPPING_WARNINGS=1
- -DBOARD_HAS_PSRAM
board_build.flash_mode: dio
board_build.mcu: esp32s3
esp32:
board: ${board}
variant: ${variant}
flash_size: ${flash_size}
framework:
type: esp-idf
sdkconfig_options:
CONFIG_BT_BLE_42_FEATURES_SUPPORTED: y
CONFIG_BT_CTRL_SCAN_DUPLICATE_FILTER: y
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_160: y
CONFIG_ESP32S3_DATA_CACHE_32KB: y
CONFIG_ESP32S3_INSTRUCTION_CACHE_32KB: y
CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM: "8"
CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM: "16"
CONFIG_ESP_TASK_WDT_TIMEOUT_S: "15"
CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE: "16"
CONFIG_BT_DEBUG_LOG: y
CONFIG_BT_DEBUG_BLE: y
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: true
ap:
ssid: "tesla-ble Fallback Hotspot"
password: !secret wifi_hotspot_password
on_connect:
then:
- esp32_ble_tracker.start_scan:
continuous: true
on_disconnect:
then:
- logger.log: "⚠️ WiFi断开,自动重连"
- esp32_ble_tracker.stop_scan
captive_portal:
web_server:
port: 80
auth:
username: admin
password: !secret web_server_password
local: true
version: 2
include_internal: true
esp32_ble_tracker:
scan_parameters:
interval: 150ms
window: 150ms
active: false
continuous: true
external_components:
- source: github://PedroKTFC/esphome-tesla-ble@main
components: [tesla_ble_vehicle, tesla_ble_listener]
refresh: 0s
ble_client:
- mac_address: ${ble_mac_address}
id: ble_tesla_id
auto_connect: true
on_connect:
then:
- logger.log: "✅ BLE 已连接车辆"
on_disconnect:
then:
- logger.log: "⚠️ BLE 断开,auto_connect 将自动重连"
tesla_ble_vehicle:
ble_client_id: ble_tesla_id
id: tesla_ble_vehicle_id
vin: ${tesla_vin}
update_interval: 15s
logger:
level: DEBUG
baud_rate: 115200
logs:
component: ERROR
ble_client: DEBUG
esp32_ble_tracker: DEBUG
ota:
platform: esphome
password: !secret ota_password
on_begin:
then:
- logger.log: "⚠️ OTA升级中"
api:
encryption:
key: !secret api_encryption_key
reboot_timeout: 0s
script:
- id: manual_reconnect
mode: single
then:
- esp32_ble_tracker.start_scan:
continuous: true
- ble_client.connect: ble_tesla_id
- logger.log: "手动触发 BLE 重连"
globals:
- id: unlock_executed
type: bool
initial_value: "false"
- id: lock_executed
type: bool
initial_value: "false"
- id: pairing_in_progress
type: bool
initial_value: "false"
sensor:
- platform: ble_client
type: rssi
ble_client_id: ble_tesla_id
name: "BLE Signal"
icon: mdi:bluetooth
update_interval: 60s
entity_category: diagnostic
- platform: wifi_signal
name: "WiFi Signal"
update_interval: 60s
icon: mdi:wifi
- platform: uptime
name: "Uptime"
update_interval: 60s
icon: mdi:clock-outline
- platform: template
name: "Battery Level"
id: battery_level_sensor
unit_of_measurement: "%"
icon: mdi:battery
lambda: |-
return id(tesla_ble_vehicle_id)->get_battery_level();
update_interval: 30s
- platform: template
name: "Charge Power"
id: charge_power_sensor
unit_of_measurement: "kW"
icon: mdi:lightning-bolt
lambda: |-
return id(tesla_ble_vehicle_id)->get_charge_power_kw();
update_interval: 10s
- platform: template
name: "Inside Temperature"
id: inside_temp_sensor
unit_of_measurement: "°C"
icon: mdi:thermometer
lambda: |-
return id(tesla_ble_vehicle_id)->get_inside_temp_c();
update_interval: 30s
binary_sensor:
-
platform: template
name: "WiFi连接状态"
id: wifi_connected
internal: true
lambda: "return WiFi.isConnected();"
-
platform: gpio
pin:
number: GPIO0
mode:
input: true
pullup: true
inverted: true
name: "BOOT按键"
id: boot_button
internal: true
on_multi_click:
- timing:
- "ON for at most 1s"
- "OFF for at least 0.2s"
then:
- logger.log: "单击 -> 开启前备箱"
- lambda: "return id(tesla_ble_vehicle_id).open_frunk();"
- timing:
- "ON for at most 1s"
- "OFF for at most 0.2s"
- "ON for at most 1s"
- "OFF for at least 0.2s"
then:
- logger.log: "双击 -> 开启后备箱"
- lambda: "return id(tesla_ble_vehicle_id).open_trunk();"
- timing:
- "ON for at most 1s"
- "OFF for at most 0.2s"
- "ON for at most 1s"
- "OFF for at most 0.2s"
- "ON for at most 1s"
- "OFF for at least 0.2s"
then:
- logger.log: "三击 -> 关闭后备箱"
- lambda: "return id(tesla_ble_vehicle_id).close_trunk();"
- timing:
- "ON for at most 1s"
- "OFF for at most 0.2s"
- "ON for at most 1s"
- "OFF for at most 0.2s"
- "ON for at most 1s"
- "OFF for at most 0.2s"
- "ON for at most 1s"
- "OFF for at least 0.2s"
then:
- logger.log: "四击 -> 寻车(闪灯)"
- lambda: "return id(tesla_ble_vehicle_id).flash_lights();"
- timing:
- "ON for at least 5s"
then:
- if:
condition:
lambda: "return !id(pairing_in_progress);"
then:
- logger.log: "长按 BOOT 键,开始配对"
- globals.set:
id: pairing_in_progress
value: "true"
- lambda: "return id(tesla_ble_vehicle_id).pair();"
- delay: 10s
- globals.set:
id: pairing_in_progress
value: "false"
- logger.log: "配对完成"
-
platform: template
name: "车辆已连接"
id: vehicle_connected
lambda: "return id(ble_tesla_id).connected();"
on_press:
then:
- if:
condition:
lambda: "return !id(unlock_executed);"
then:
- logger.log: "自动解锁车辆"
- lambda: "return id(tesla_ble_vehicle_id).unlock();"
- globals.set:
id: unlock_executed
value: "true"
on_release:
then:
- if:
condition:
lambda: "return !id(lock_executed) && id(unlock_executed);"
then:
- delay: ${auto_lock_delay}
- logger.log: "自动锁车"
- lambda: "return id(tesla_ble_vehicle_id).lock();"
- globals.set:
id: lock_executed
value: "true"
- globals.set:
id: unlock_executed
value: "false"
- globals.set:
id: lock_executed
value: "false"
-
platform: status
name: "Status"
text_sensor:
- platform: version
name: "Version"
icon: mdi:cube-outline
- platform: wifi_info
ip_address:
name: "IP Address"
time:
- platform: homeassistant
id: homeassistant_time
button:
-
platform: restart
name: Restart
icon: mdi:restart
entity_category: diagnostic
-
platform: template
name: "Pair BLE Key"
id: pair_ble_key
icon: mdi:key-wireless
on_press:
- logger.log: "开始配对"
- lambda: "return id(tesla_ble_vehicle_id).pair();"
- delay: 10s
- logger.log: "配对完成"
-
platform: template
name: "Wake Vehicle"
id: wake_vehicle
icon: mdi:car
on_press:
- lambda: "return id(tesla_ble_vehicle_id).wakeup();"
-
platform: template
name: "Unlock Doors"
id: unlock_doors
icon: mdi:lock-open
on_press:
- logger.log: "手动解锁"
- lambda: "return id(tesla_ble_vehicle_id).unlock();"
-
platform: template
name: "Lock Doors"
id: lock_doors
icon: mdi:lock
on_press:
- logger.log: "手动锁车"
- lambda: "return id(tesla_ble_vehicle_id).lock();"
-
platform: template
name: "Force Reconnect BLE"
id: force_reconnect_ble
icon: mdi:bluetooth-connect
on_press:
- script.execute: manual_reconnect
-
platform: template
name: "Flash Lights (寻车)"
id: flash_lights_button
icon: mdi:car-light-high
on_press:
- lambda: "return id(tesla_ble_vehicle_id).flash_lights();"
- logger.log: "已触发闪灯寻车"
switch:
- platform: ble_client
ble_client_id: ble_tesla_id
name: "BLE Connection"
entity_category: diagnostic
编译提示(venv) zipo@zipo-Default-string:~/tesla-ble-project$ esphome compile tesla-ble.yaml
INFO ESPHome 2025.12.1
INFO Reading configuration tesla-ble.yaml...
INFO Updating https://github.com/PedroKTFC/esphome-tesla-ble.git@main
WARNING GPIO0 is a strapping PIN and should only be used for I/O with care.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq/#why-am-i-getting-a-warning-about-strapping-pins
INFO Detected timezone 'Asia/Shanghai'
INFO Generating C++ source...
INFO Setting CONFIG_LWIP_MAX_SOCKETS to 14 (registered: api=4, captive_portal=4, mdns=2, ota=1, web_server=3)
INFO Compiling app... Build path: /home/zipo/tesla-ble-project/.esphome/build/tesla-ble
Obsolete PIO Core v6.1.18 is used (previous was 6.1.19)
Please remove multiple PIO Cores from a system:
https://docs.platformio.org/en/latest/core/installation/troubleshooting.html
HARDWARE: ESP32S3 240MHz, 320KB RAM, 8MB Flash
- contrib-piohome @ 3.4.4
- framework-espidf @ 3.50501.0 (5.5.1)
- tool-cmake @ 4.0.3
- tool-esp-rom-elfs @ 2024.10.11
- tool-esptoolpy @ 5.1.0
- tool-mklittlefs @ 3.2.0
- tool-ninja @ 1.13.1
- tool-scons @ 4.40801.0 (4.8.1)
- toolchain-xtensa-esp-elf @ 14.2.0+20241119
Reading CMake configuration...
Dependency Graph
|-- noise-c @ 0.1.10
|-- ArduinoJson @ 7.4.2
Compiling .pioenvs/tesla-ble/src/esphome/components/tesla_ble_vehicle/log.cpp.o
src/esphome/components/tesla_ble_vehicle/log.cpp:7:10: fatal error: car_server.pb.h: No such file or directory
7 | #include <car_server.pb.h>
| ^~~~~~~~~~~~~~~~~
compilation terminated.
Compiling .pioenvs/tesla-ble/src/esphome/components/tesla_ble_vehicle/tesla_ble_vehicle.cpp.o
*** [.pioenvs/tesla-ble/src/esphome/components/tesla_ble_vehicle/log.cpp.o] Error 1
src/esphome/components/tesla_ble_vehicle/tesla_ble_vehicle.cpp:5:10: fatal error: pb_decode.h: No such file or directory
5 | #include <pb_decode.h>
| ^~~~~~~~~~~~~
compilation terminated.
*** [.pioenvs/tesla-ble/src/esphome/components/tesla_ble_vehicle/tesla_ble_vehicle.cpp.o] Error 1
========================= [FAILED] Took 49.12 seconds ==================== Here's the English translation of your sentence:
"I get this error message when compiling. Can anyone help me, or help me compile it into a bin file?"
============================================================
代码 F - 无 LED 版本(最终修正)
============================================================
substitutions:
friendly_name: Tesla BLE
device_name: tesla-ble
device_description: Tesla BLE
ble_mac_address: !secret ble_mac_address
tesla_vin: !secret tesla_vin
auto_lock_delay: 30s
board: esp32-s3-devkitc-1
variant: ESP32S3
flash_size: 8MB
esphome:
name: ${device_name}
friendly_name: ${friendly_name}
name_add_mac_suffix: false
platformio_options:
build_flags:
- -DESPHOME_DISABLE_STRAPPING_WARNINGS=1
- -DBOARD_HAS_PSRAM
board_build.flash_mode: dio
board_build.mcu: esp32s3
esp32:
board: ${board}
variant: ${variant}
flash_size: ${flash_size}
framework:
type: esp-idf
sdkconfig_options:
CONFIG_BT_BLE_42_FEATURES_SUPPORTED: y
CONFIG_BT_CTRL_SCAN_DUPLICATE_FILTER: y
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_160: y
CONFIG_ESP32S3_DATA_CACHE_32KB: y
CONFIG_ESP32S3_INSTRUCTION_CACHE_32KB: y
CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM: "8"
CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM: "16"
CONFIG_ESP_TASK_WDT_TIMEOUT_S: "15"
CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE: "16"
CONFIG_BT_DEBUG_LOG: y
CONFIG_BT_DEBUG_BLE: y
wifi:⚠️ WiFi断开,自动重连"
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: true
ap:
ssid: "tesla-ble Fallback Hotspot"
password: !secret wifi_hotspot_password
on_connect:
then:
- esp32_ble_tracker.start_scan:
continuous: true
on_disconnect:
then:
- logger.log: "
- esp32_ble_tracker.stop_scan
captive_portal:
web_server:
port: 80
auth:
username: admin
password: !secret web_server_password
local: true
version: 2
include_internal: true
esp32_ble_tracker:
scan_parameters:
interval: 150ms
window: 150ms
active: false
continuous: true
external_components:
components: [tesla_ble_vehicle, tesla_ble_listener]
refresh: 0s
ble_client:
id: ble_tesla_id
auto_connect: true
on_connect:
then:
- logger.log: "✅ BLE 已连接车辆"
on_disconnect:
then:
- logger.log: "
tesla_ble_vehicle:
ble_client_id: ble_tesla_id
id: tesla_ble_vehicle_id
vin: ${tesla_vin}
update_interval: 15s
logger:
level: DEBUG
baud_rate: 115200
logs:
component: ERROR
ble_client: DEBUG
esp32_ble_tracker: DEBUG
ota:⚠️ OTA升级中"
platform: esphome
password: !secret ota_password
on_begin:
then:
- logger.log: "
api:
encryption:
key: !secret api_encryption_key
reboot_timeout: 0s
script:
mode: single
then:
continuous: true
globals:
type: bool
initial_value: "false"
type: bool
initial_value: "false"
type: bool
initial_value: "false"
sensor:
type: rssi
ble_client_id: ble_tesla_id
name: "BLE Signal"
icon: mdi:bluetooth
update_interval: 60s
entity_category: diagnostic
name: "WiFi Signal"
update_interval: 60s
icon: mdi:wifi
name: "Uptime"
update_interval: 60s
icon: mdi:clock-outline
name: "Battery Level"
id: battery_level_sensor
unit_of_measurement: "%"
icon: mdi:battery
lambda: |-
return id(tesla_ble_vehicle_id)->get_battery_level();
update_interval: 30s
name: "Charge Power"
id: charge_power_sensor
unit_of_measurement: "kW"
icon: mdi:lightning-bolt
lambda: |-
return id(tesla_ble_vehicle_id)->get_charge_power_kw();
update_interval: 10s
name: "Inside Temperature"
id: inside_temp_sensor
unit_of_measurement: "°C"
icon: mdi:thermometer
lambda: |-
return id(tesla_ble_vehicle_id)->get_inside_temp_c();
update_interval: 30s
binary_sensor:
platform: template
name: "WiFi连接状态"
id: wifi_connected
internal: true
lambda: "return WiFi.isConnected();"
platform: gpio
pin:
number: GPIO0
mode:
input: true
pullup: true
inverted: true
name: "BOOT按键"
id: boot_button
internal: true
on_multi_click:
then:
then:
then:
then:
then:
condition:
lambda: "return !id(pairing_in_progress);"
then:
- logger.log: "长按 BOOT 键,开始配对"
- globals.set:
id: pairing_in_progress
value: "true"
- lambda: "return id(tesla_ble_vehicle_id).pair();"
- delay: 10s
- globals.set:
id: pairing_in_progress
value: "false"
- logger.log: "配对完成"
platform: template
name: "车辆已连接"
id: vehicle_connected
lambda: "return id(ble_tesla_id).connected();"
on_press:
then:
- if:
condition:
lambda: "return !id(unlock_executed);"
then:
- logger.log: "自动解锁车辆"
- lambda: "return id(tesla_ble_vehicle_id).unlock();"
- globals.set:
id: unlock_executed
value: "true"
on_release:
then:
- if:
condition:
lambda: "return !id(lock_executed) && id(unlock_executed);"
then:
- delay: ${auto_lock_delay}
- logger.log: "自动锁车"
- lambda: "return id(tesla_ble_vehicle_id).lock();"
- globals.set:
id: lock_executed
value: "true"
- globals.set:
id: unlock_executed
value: "false"
- globals.set:
id: lock_executed
value: "false"
platform: status
name: "Status"
text_sensor:
name: "Version"
icon: mdi:cube-outline
ip_address:
name: "IP Address"
time:
id: homeassistant_time
button:
platform: restart
name: Restart
icon: mdi:restart
entity_category: diagnostic
platform: template
name: "Pair BLE Key"
id: pair_ble_key
icon: mdi:key-wireless
on_press:
platform: template
name: "Wake Vehicle"
id: wake_vehicle
icon: mdi:car
on_press:
platform: template
name: "Unlock Doors"
id: unlock_doors
icon: mdi:lock-open
on_press:
platform: template
name: "Lock Doors"
id: lock_doors
icon: mdi:lock
on_press:
platform: template
name: "Force Reconnect BLE"
id: force_reconnect_ble
icon: mdi:bluetooth-connect
on_press:
platform: template
name: "Flash Lights (寻车)"
id: flash_lights_button
icon: mdi:car-light-high
on_press:
switch:
ble_client_id: ble_tesla_id
name: "BLE Connection"
entity_category: diagnostic
编译提示(venv) zipo@zipo-Default-string:~/tesla-ble-project$ esphome compile tesla-ble.yaml
INFO ESPHome 2025.12.1
INFO Reading configuration tesla-ble.yaml...
INFO Updating https://github.com/PedroKTFC/esphome-tesla-ble.git@main
WARNING GPIO0 is a strapping PIN and should only be used for I/O with care.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq/#why-am-i-getting-a-warning-about-strapping-pins
INFO Detected timezone 'Asia/Shanghai'
INFO Generating C++ source...
INFO Setting CONFIG_LWIP_MAX_SOCKETS to 14 (registered: api=4, captive_portal=4, mdns=2, ota=1, web_server=3)
INFO Compiling app... Build path: /home/zipo/tesla-ble-project/.esphome/build/tesla-ble
Obsolete PIO Core v6.1.18 is used (previous was 6.1.19)
Please remove multiple PIO Cores from a system:
https://docs.platformio.org/en/latest/core/installation/troubleshooting.html
Processing tesla-ble (board: esp32-s3-devkitc-1; framework: espidf; platform: https://github.com/pioarduino/platform-espressif32/releases/download/55.03.31-2/platform-espressif32.zip)
HARDWARE: ESP32S3 240MHz, 320KB RAM, 8MB Flash
Reading CMake configuration...
Dependency Graph
|-- noise-c @ 0.1.10
|-- ArduinoJson @ 7.4.2
Compiling .pioenvs/tesla-ble/src/esphome/components/tesla_ble_vehicle/log.cpp.o
src/esphome/components/tesla_ble_vehicle/log.cpp:7:10: fatal error: car_server.pb.h: No such file or directory
compilation terminated.
Compiling .pioenvs/tesla-ble/src/esphome/components/tesla_ble_vehicle/tesla_ble_vehicle.cpp.o
*** [.pioenvs/tesla-ble/src/esphome/components/tesla_ble_vehicle/log.cpp.o] Error 1
src/esphome/components/tesla_ble_vehicle/tesla_ble_vehicle.cpp:5:10: fatal error: pb_decode.h: No such file or directory
compilation terminated.
*** [.pioenvs/tesla-ble/src/esphome/components/tesla_ble_vehicle/tesla_ble_vehicle.cpp.o] Error 1
========================= [FAILED] Took 49.12 seconds ==================== Here's the English translation of your sentence:
"I get this error message when compiling. Can anyone help me, or help me compile it into a bin file?"