yoziru / esphome-tesla-ble

Interact with Tesla vehicles over BLE using ESPHome and Home Assistant
GNU Affero General Public License v3.0
83 stars 16 forks source link

Successful install after errors - Tutorial inside #27

Open TwilightDuck opened 3 months ago

TwilightDuck commented 3 months ago

Hi,

I got it flashed but now I'm getting the following error in the logs. Compiled and uploaded with ESPHOME terminal


[22:20:14][I][app:062]: setup() finished successfully!
[22:20:14][W][component:170]: Component wifi cleared Warning flag
[22:20:14][W][component:157]: Component api set Warning flag: unspecified
[22:20:14][I][app:100]: ESPHome version 2024.7.2 compiled on Jul 25 2024, 21:24:07
[22:20:14][I][app:102]: Project yoziru.esphome-tesla-ble version 2024.7.24
[22:20:14][W][component:170]: Component api cleared Warning flag
[22:20:14][W][component:237]: Component api took a long time for an operation (55 ms).
[22:20:14][W][component:238]: Components should block for at most 30 ms.
[22:20:14][W][component:237]: Component api took a long time for an operation (57 ms).
[22:20:14][W][component:238]: Components should block for at most 30 ms.
[22:20:27][I][tesla_ble_vehicle:285]: Starting pairing
[22:20:27][I][tesla_ble_vehicle:286]: Not authenticated yet, building whitelist message
[22:20:27]Building whitelist message
[22:20:27]Public key size: 65
[22:20:27]Public key: 04cb6ae2967e197bbd63ea0ff4eed03950367705897add253e6e185264148dace6ce29ff383a1a7363ebde5b2851b8b7026ba991876c4c077422c7f006f9ec1974
[22:20:27]Encoding whitelist message
[22:20:27]Bytes written: 80
[22:20:27]Encoding message
[22:20:27]Encoded whitelist message :82014d2a470a430a4104cb6ae2967e197bbd63ea0ff4eed03950367705897add253e6e185264148dace6ce29ff383a1a7363ebde5b2851b8b7026ba991876c4c077422c7f006f9ec1974200232020809
[22:20:27]Building VCSEC to VCSEC message
[22:20:27]Encoding VCSEC to VCSEC message
[22:20:27]Bytes written: 86
[22:20:27]Encoding message
[22:20:27]Encoded VCSEC to VCSEC message length: 86
[22:20:27]Encoded VCSEC to VCSEC message :0a54125082014d2a470a430a4104cb6ae2967e197bbd63ea0ff4eed03950367705897add253e6e185264148dace6ce29ff383a1a7363ebde5b2851b8b7026ba991876c4c077422c7f006f9ec19742002320208091802
[22:20:27]Prepending length
[22:20:27][I][esp-idf:000]: W (22496) BT_LOG: esp_ble_gattc_write_char, The connection not created.
[22:20:27]
[22:20:27][W][tesla_ble_vehicle:353]: Error sending write value to BLE gattc server, error=259
[22:20:27][E][tesla_ble_vehicle:303]: Failed to send whitelist message
[22:20:27][W][component:237]: Component api took a long time for an operation (82 ms).
[22:20:27][W][component:238]: Components should block for at most 30 ms.
[22:20:41][W][component:237]: Component api took a long time for an operation (54 ms).
[22:20:41][W][component:238]: Components should block for at most 30 ms.
[22:20:42][W][component:237]: Component api took a long time for an operation (56 ms).
[22:20:42][W][component:238]: Components should block for at most 30 ms.
[22:20:47][I][tesla_ble_vehicle:285]: Starting pairing
[22:20:47][I][tesla_ble_vehicle:286]: Not authenticated yet, building whitelist message
[22:20:47]Building whitelist message
[22:20:47]Public key size: 65
[22:20:47]Public key: 04cb6ae2967e197bbd63ea0ff4eed03950367705897add253e6e185264148dace6ce29ff383a1a7363ebde5b2851b8b7026ba991876c4c077422c7f006f9ec1974
[22:20:47]Encoding whitelist message
[22:20:47]Bytes written: 80
[22:20:47]Encoding message
[22:20:47]Encoded whitelist message :82014d2a470a430a4104cb6ae2967e197bbd63ea0ff4eed03950367705897add253e6e185264148dace6ce29ff383a1a7363ebde5b2851b8b7026ba991876c4c077422c7f006f9ec1974200232020809
[22:20:47]Building VCSEC to VCSEC message
[22:20:47]Encoding VCSEC to VCSEC message
[22:20:47]Bytes written: 86
[22:20:47]Encoding message
[22:20:47]Encoded VCSEC to VCSEC message length: 86
[22:20:47]Encoded VCSEC to VCSEC message :0a54125082014d2a470a430a4104cb6ae2967e197bbd63ea0ff4eed03950367705897add253e6e185264148dace6ce29ff383a1a7363ebde5b2851b8b7026ba991876c4c077422c7f006f9ec19742002320208091802
[22:20:47]Prepending length
[22:20:47][I][esp-idf:000]: W (42487) BT_LOG: esp_ble_gattc_write_char, The connection not created.
[22:20:47]
[22:20:47][W][tesla_ble_vehicle:353]: Error sending write value to BLE gattc server, error=259
[22:20:47][E][tesla_ble_vehicle:303]: Failed to send whitelist message
[22:20:47][W][component:237]: Component api took a long time for an operation (87 ms).
[22:20:47][W][component:238]: Components should block for at most 30 ms.
[22:20:55][W][ble_rssi_sensor:061]: [BLE Signal] Cannot poll, not connected
[22:21:06][I][safe_mode:041]: Boot seems successful; resetting boot loop counter```
TwilightDuck commented 3 months ago

Okay, update. I thought I had a shortcut by just taking the BLE MAC from my phone.. Seems like that caused it. I used the tesla_ble_listener and it turned out to be a different MAC. I used that and boom! It recognized the ESP32 as a key.

But I wan't there yet, it wasn't working.. After literally doing esphome run tesla-ble-esp32-generic.yml a few times. It just started working!

NOTE: minimum amps is same as in the app, 5. (Using the trickle charger) NOTE: When pressing "pair" you don't get a popup on the Tesla screen, until you tap your key card!

So to re-iterate:

  1. Install ESPHome CLI locally
  2. Clone/download the project locally
  3. Create secrets.yaml and put in your details. (Including a new api_encryption_key)
  4. Go into the directory and run esphome run tesla-ble-esp32-generic.yml (Make sure your ESP32 is connected via USB to your PC)
  5. Once it's done, it should boot up and start showing you logs.
  6. In Home Assistant, go to Settings > Devices & Services > ESPHome > Tesla BLE device and click "Pair BLE key"
  7. Tap your NFC card to your car's center console
  8. Hit confirm on the screen

Success! @yoziru Thank you.

PedroKTFC commented 3 months ago

I've also had a few issues to get the pairing to work but seemed to finally do it this morning. I haven't repeatedly rebuilt it like you and, moreover, I've adopted it into my HA esphome add-on so I can easily update it - I've already done that too. I just tried pairing again this morning and I could now start charging and change the charge limit. The real test will be when I take the car away and then return home - will it still work?! Fingers crossed!

TwilightDuck commented 3 months ago

Update

Getting errors again. It's really intermitent. @yoziru any idea?


[15:06:05][W][component:170]: Component wifi cleared Warning flag
[15:06:05][W][component:157]: Component api set Warning flag: unspecified
[15:06:05][I][app:100]: ESPHome version 2024.7.2 compiled on Jul 26 2024, 14:25:37
[15:06:05][I][app:102]: Project yoziru.esphome-tesla-ble version 2024.7.24
[15:06:05][I][esp-idf:000][BTU_TASK]: E (8420) BT_BTM: BTM_BleScan scan not active
[15:06:05]
[15:06:05]
[15:06:05][I][esp-idf:000][BTU_TASK]: W (8421) BT_APPL:  bta_dm_ble_scan stop scan failed, status=0x6
[15:06:05]
[15:06:05]
[15:06:05][I][esp32_ble_client:066]: [0] [F8:55:48:BB:D1:D1] 0x00 Attempting BLE connection
[15:06:05][I][tesla_ble_vehicle:721]: Connected successfully!
[15:06:06][W][component:170]: Component api cleared Warning flag
[15:06:06][W][component:237]: Component api took a long time for an operation (58 ms).
[15:06:06][W][component:238]: Components should block for at most 30 ms.
[15:06:07][I][esp32_ble_client:227]: [0] [F8:55:48:BB:D1:D1] ConnectedAdding key slot infomessage: 0x3ffcf7f0
[15:06:07]message.which_sub_message: 1
[15:06:07]
[15:06:07][I][tesla_ble_vehicle:853]: SessionInfoRequest sent to VEHICLE_SECURITY
[15:06:07][I][tesla_ble_vehicle:861]: Sent initial info status request
[15:06:07][I][ble_rssi_sensor:049]: ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT RSSI: -71
[15:06:07][W][tesla_ble_vehicle:955]: [x] Dropping message with missing source
[15:06:07][I][tesla_ble_vehicle:1049]: Received message from unknown domain DOMAIN_VEHICLE_SECURITY
[15:06:12][I][tesla_ble_vehicle:572]: Setting charge amps to 14Error: epoch is empty
[15:06:12]Failed to build car action message
[15:06:12]
[15:06:12][E][tesla_ble_vehicle:578]: Failed to build charge amps message
[15:06:13][I][tesla_ble_vehicle:1040]: [a4e957db5e20fb38a84ea61493255624] Updated session info for DOMAIN_INFOTAINMENT
[15:06:13][W][component:237]: Component esp32_ble took a long time for an operation (225 ms).
[15:06:13][W][component:238]: Components should block for at most 30 ms.
[15:06:18][I][tesla_ble_vehicle:386]: Waking vehicle
[15:06:18][I][tesla_ble_vehicle:389]: Vehicle is already awake
[15:06:23][I][tesla_ble_vehicle:610]: Setting charge limit to 80
[15:06:23][I][tesla_ble_vehicle:1049]: Received message from unknown domain DOMAIN_INFOTAINMENT
[15:06:23][I][tesla_ble_vehicle:569]: CarServerResponse:
[15:06:23][I][tesla_ble_vehicle:572]:   ActionStatus:
[15:06:23][I][tesla_ble_vehicle:573]:     result: OK
[15:06:30][I][tesla_ble_vehicle:534]: Setting charging switch to ON
[15:06:31][I][tesla_ble_vehicle:1049]: Received message from unknown domain DOMAIN_INFOTAINMENT
[15:06:31][I][tesla_ble_vehicle:569]: CarServerResponse:
[15:06:31][I][tesla_ble_vehicle:572]:   ActionStatus:
[15:06:31][I][tesla_ble_vehicle:573]:     result: ERROR
[15:06:31][I][tesla_ble_vehicle:579]:     reason: is_charging
[15:06:35][I][tesla_ble_vehicle:572]: Setting charge amps to 8
[15:06:36][I][esp-idf:000][BTU_TASK]: W (39067) BT_APPL: gattc_conn_cb: if=3 st=0 id=3 rsn=0x8
[15:06:36]
[15:06:36][I][esp-idf:000][BTU_TASK]: W (39069) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x8
[15:06:36]
[15:06:36][W][tesla_ble_vehicle:754]: Disconnected!
[15:06:36][W][component:157]: Component ble_client.sensor set Warning flag: unspecified
[15:06:36][W][ble_rssi_sensor:061]: [BLE Signal] Cannot poll, not connected
[15:06:39][I][esp32_ble_client:066]: [0] [F8:55:48:BB:D1:D1] 0x00 Attempting BLE connection
[15:06:39][I][esp-idf:000][BTU_TASK]: W (42267) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
[15:06:39]
[15:06:40][I][tesla_ble_vehicle:721]: Connected successfully!
[15:06:43][I][esp32_ble_client:227]: [0] [F8:55:48:BB:D1:D1] Connected
[15:06:43][W][tesla_ble_vehicle:453]: Not authenticated yet, try again in a few seconds
[15:06:43][I][tesla_ble_vehicle:460]: SessionInfoRequest sent to VEHICLE_SECURITY
[15:06:43][I][tesla_ble_vehicle:853]: Adding key slot infomessage: 0x3ffcf7f0
[15:06:43]message.which_sub_message: 1
[15:06:43]SessionInfoRequest sent to VEHICLE_SECURITY
[15:06:43][W][tesla_ble_vehicle:453]: Not authenticated yet, try again in a few seconds
[15:06:43][I][tesla_ble_vehicle:460]: SessionInfoRequest sent to VEHICLE_SECURITY
[15:06:43][I][tesla_ble_vehicle:861]: Sent initial info status request
[15:06:43][I][ble_rssi_sensor:049]: ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT RSSI: -74
[15:06:43][W][component:170]: Component ble_client.sensor cleared Warning flag
[15:06:43][W][tesla_ble_vehicle:955]: [x] Dropping message with missing source
[15:06:44][E][tesla_ble_vehicle:121]:   MessageStatus:
[15:06:44][E][tesla_ble_vehicle:122]:     operation_status: WAIT
[15:06:44][E][tesla_ble_vehicle:123]:     signed_message_fault: ERROR_NONE
[15:06:44][I][tesla_ble_vehicle:1022]: Received wait message from domain DOMAIN_VEHICLE_SECURITY
[15:06:44][I][tesla_ble_vehicle:1040]: [8afe211b197ee4758ec6878558dd24e6] Updated session info for DOMAIN_VEHICLE_SECURITY
[15:06:44][W][component:237]: Component esp32_ble took a long time for an operation (224 ms).
[15:06:44][W][component:238]: Components should block for at most 30 ms.
[15:06:52][W][tesla_ble_vehicle:453]: Not authenticated yet, try again in a few seconds
[15:06:52][I][tesla_ble_vehicle:460]: SessionInfoRequest sent to VEHICLE_SECURITY
[15:06:52][W][tesla_ble_vehicle:497]: Car is asleep, waking up
[15:06:52][I][tesla_ble_vehicle:386]: Waking vehicle
[15:06:52][W][tesla_ble_vehicle:453]:message: 0x3ffcf540
[15:06:52]message.which_sub_message: 2
[15:06:52] Not authenticated yet, try again in a few seconds
[15:06:52][I][tesla_ble_vehicle:460]: SessionInfoRequest sent to VAdding key slot infomessage: 0x3ffcf4f0
[15:06:52]message.which_sub_message: 1
[15:06:52]EHICLE_SECURITY
[15:06:52][W][tesla_ble_vehicle:453]: Not authenticated yet, try again in a few seconds
[15:06:52][I][tesla_ble_vehicle:460]: SessionInfoRequest sent to VEHICLE_SECURITY
[15:06:52][I][tesla_ble_vehicle:610]: Setting charge limit to 71
[15:06:52][W][component:237]: Component api took a long time for an operation (57 ms).
[15:06:52][W][component:238]: Components should block for at most 30 ms.
[15:06:52][E][tesla_ble_vehicle:881]: write char failed, error status = 8f
[15:06:52][E][tesla_ble_vehicle:881]: write char failed, error status = 8f
[15:06:52][E][tesla_ble_vehicle:881]: write char failed, error status = 8f
[15:06:52][E][tesla_ble_vehicle:881]: write char failed, error status = 8f
[15:06:52][E][tesla_ble_vehicle:881]: write char failed, error status = 8f
[15:06:52][E][tesla_ble_vehicle:881]: write char failed, error status = 8f
[15:06:52][E][tesla_ble_vehicle:881]: write char failed, error status = 8f
[15:06:52][E][tesla_ble_vehicle:881]: write char failed, error status = 8f
[15:06:52][E][tesla_ble_vehicle:881]: write char failed, error status = 8f
[15:06:52][W][component:237]: Component esp32_ble took a long time for an operation (61 ms).
[15:06:52][W][component:238]: Components should block for at most 30 ms.
[15:06:53][I][tesla_ble_vehicle:1040]: [067a337097d75212f57ed29495660623] Updated session info for DOMAIN_VEHICLE_SECURITY
[15:06:53][W][component:237]: Component esp32_ble took a long time for an operation (225 ms).
[15:06:53][W][component:238]: Components should block for at most 30 ms.
[15:06:58][I][safe_mode:041]: Boot seems successful; resetting boot loop counter
[15:07:04][I][esp-idf:000][BTU_TASK]: W (66777) BT_APPL: gattc_conn_cb: if=3 st=0 id=3 rsn=0x8
[15:07:04]
[15:07:04][I][esp-idf:000][BTU_TASK]: W (66778) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x8
[15:07:04]
[15:07:04][W][tesla_ble_vehicle:754]: Disconnected!
[15:07:04][W][component:157]: Component ble_client.sensor set Warning flag: unspecified
[15:07:04][I][esp-idf:000][BTU_TASK]: E (66811) BT_BTM: BTM_BleScan scan not active```
yoziru commented 3 months ago

https://github.com/yoziru/esphome-tesla-ble/pull/38 Should fix this Try updating to the latest release: https://github.com/yoziru/esphome-tesla-ble/releases/tag/2024.7.26

TwilightDuck commented 3 months ago

38 Should fix this Try updating to the latest release: https://github.com/yoziru/esphome-tesla-ble/releases/tag/2024.7.26

Just installed the new release and tested it. Worked great on first try, then exited the vehicle. Went of of range, got back in and then got the following errors and it didn't recover. Let me know if there's a specific scenario you'd like me to test.

[20:25:19][W][tesla_ble_vehicle:458]: Not authenticated yet, try again in a few seconds
[20:25:19][I][tesla_ble_vehicle:465]: SessionInfoRequest sent to VEHICLE_SECURITY
[20:25:19][I][tesla_ble_vehicle:1004]: [a98d3bf35baaf3571b048784a87e737e] Updated session info for DOMAIN_VEHICLE_SECURITY
[20:25:19][W][component:237]: Component esp32_ble took a long time for an operation (259 ms).
[20:25:19][W][component:238]: Components should block for at most 30 ms.
[20:25:25][W][tesla_ble_vehicle:458]: Not authenticated yet, try again in a few seconds
[20:25:25][I][tesla_ble_vehicle:465]: SessionInfoRequest sent to VEHICLE_SECURITY
[20:25:25][W][tesla_ble_vehicle:502]: Car is asleep, waking up
[20:25:25][I][tesla_ble_vehicle:391]: Waking vehicle
[20:25:25][W][tesla_ble_vehicle:458]: Not authenticated yet, try again in a few seconds
[20:25:25][I][tesla_ble_vehicle:465]: SessionInfoRequest sent to VEHICLE_SECURITY
[20:25:25][W][tesla_ble_vehicle:458]: Not authenticated yet, try again in a few seconds
[20:25:25][I][tesla_ble_vehicle:465]: SessionInfoRequest sent to VEHICLE_SECURITY
[20:25:25][I][tesla_ble_vehicle:574]: Setting charge amps to 11
[20:25:25][E][tesla_ble_vehicle:877]: write char failed, error status = 8f
[20:25:25][E][tesla_ble_vehicle:877]: write char failed, error status = 8f
[20:25:25][E][tesla_ble_vehicle:877]: write char failed, error status = 8f
[20:25:25][E][tesla_ble_vehicle:877]: write char failed, error status = 8f
[20:25:25][E][tesla_ble_vehicle:877]: write char failed, error status = 8f
[20:25:25][E][tesla_ble_vehicle:877]: write char failed, error status = 8f
[20:25:25][E][tesla_ble_vehicle:877]: write char failed, error status = 8f
[20:25:25][E][tesla_ble_vehicle:877]: write char failed, error status = 8f
[20:25:25][E][tesla_ble_vehicle:877]: write char failed, error status = 8f
[20:25:25][E][tesla_ble_vehicle:877]: write char failed, error status = 8f
[20:25:26][I][tesla_ble_vehicle:1004]: [7a18bb42b65574b50b310761c8a04a1b] Updated session info for DOMAIN_VEHICLE_SECURITY
[20:25:26][W][component:237]: Component esp32_ble took a long time for an operation (260 ms).
[20:25:26][W][component:238]: Components should block for at most 30 ms.
[20:25:52][I][ble_rssi_sensor:049]: ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT RSSI: -69
[20:26:00][I][esp-idf:000][BTU_TASK]: W (108698) BT_APPL: gattc_conn_cb: if=3 st=0 id=3 rsn=0x8
[20:26:00]
[20:26:00][I][esp-idf:000][BTU_TASK]: W (108700) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x8
amit-nz commented 3 months ago

I was having a similar issue as @TwilightDuck here after getting this built using a generic cheap, nasty esp32devkit board off aliexpress. I also didn't install espHome "standalone" - I put the yaml straight into ESPhome inside of Home Assistant and got it built that way.

I've noticed the following messages repeating in the log, even after pairing the key (and seeing "Unknown Key" in the Locks menu.

Not authenticated yet, try again in a few seconds

Plus whenever I would try to do something (wake, set charge amps, start/stop charging) I would get this:

[I][tesla_ble_vehicle:539]: Setting charging switch to ON
[I][esp-idf:000]: E (1184079) TeslaBLE: Epoch can not be empty with signature type AES_GCM_PERSONALIZED
[I][esp-idf:000]: E (1184082) TeslaBLE: Failed to build car action message
[E][tesla_ble_vehicle:545]: Failed to build setChargingSwitch message
[I][tesla_ble_vehicle:1004]: [8ff0c69ecb28ed2d7fcc1ef813dae733] Updated session info for DOMAIN_VEHICLE_SECURITY
[W][component:237]: Component esp32_ble took a long time for an operation (228 ms).
[W][component:238]: Components should block for at most 30 ms.

I just removed and re-added the "key", now it works perfectly. I will post again if this keeps happening.