yoziru / esphome-tesla-ble

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

Guide for usage via the ESPHome Dashboard #5

Open eaxi opened 3 months ago

eaxi commented 3 months ago

Can you do a guide how to build the firmware via the Dashboard ?

madsdyd commented 3 months ago

I would love that as well.

matkaan commented 3 months ago

Edit: see my other comment below.


This is how I did this on Dashboard:

  1. Create "New Device " at ESPHome Dashboard, use following yaml.
    • (This just references to download the packages directly from github.)
  2. Add all secrect with the same names than specified in https://github.com/yoziru/esphome-tesla-ble/blob/main/secrets.yaml.example (as usual using ESPHome dashboard).
  3. Install
    • Note: Before install you might need to do "Clean build files" as this seems to use older version of some libraries.

Disclaimer: I have not yet installed the firmware to esp32 (need to find a board). But build was ok so "should" work.

yaml content:

# hack of this file https://github.com/yoziru/esphome-tesla-ble/blob/main/tesla-ble-esp32-generic.yml
packages: 
  base: github://yoziru/esphome-tesla-ble/packages/base.yml
  device_base: github://yoziru/esphome-tesla-ble/boards/esp32-generic.yml

Option2: Other a bit more hackish option that I did first:

  1. combine boards/esp32-generic.yml, packages/base.yml to one file
  2. Change the rows "common: !include common.yml" and "project: !include project.yml" to use remote packages from github, similarly as done in previous option.
pixelwave commented 3 months ago

I tried to copy and install this script via my ESPHome (2024.7.2 / Docker) but got the following error:

Screenshot 2024-07-26 at 12 38 55
esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: arduino

substitutions:
  friendly_name: ESPHome Tesla BLE
  device_name: tesla-ble
  device_description:  Tesla BLE

esphome:
  name: ${device_name}
  name_add_mac_suffix: true
  friendly_name: ${friendly_name}
  comment: ${device_description}
  project:
    name: yoziru.esphome-tesla-ble
    version: "2024.7.24"
  libraries:
    - https://github.com/yoziru/tesla-ble.git#v2.1.0

packages:
  common: !include tesla-ble/common.yml
  client: !include tesla-ble/client.yml
  listener: !include tesla-ble/listener.yml # Uncomment this to scan find your VIN BLE MAC address

logger:
  level: INFO

# Enable Home Assistant API
api:
  encryption:
    key: "..."

# sync time with home assistant
time:
  - platform: homeassistant
    id: homeassistant_time

ota:
  - platform: esphome
    password: "..."

esp32_ble_tracker:
  scan_parameters:
    # Activate scan only after wifi connect, see https://github.com/esphome/issues/issues/2941#issuecomment-1842369092
    continuous: false

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp32-08-Tesla-Ble"
    password: "EuiIlgkmbgWj"
  # Activate scan only after wifi connect, see https://github.com/esphome/issues/issues/2941#issuecomment-1842369092
  on_connect:
    - esp32_ble_tracker.start_scan:
       continuous: true
  on_disconnect:
    - esp32_ble_tracker.stop_scan:

captive_portal:    
matkaan commented 3 months ago

Got it working on ESPHome Dashboard with option2 from my above comments! Here are details:

  1. Create new device by combining base.yml and esp32-generic.yml (bord specific) -files.

  2. Change package references to github: From...

    packages:
    common: !include common.yml
    client: !include client.yml
    # listener: !include listener.yml 

    ...to

    packages:
    common: github://yoziru/esphome-tesla-ble/packages/common.yml@main
    client: github://yoziru/esphome-tesla-ble/packages/client.yml@main
    # listener: github://yoziru/esphome-tesla-ble/packages/listener.yml@main 

    Example of my .yml with these changes: https://pastebin.com/8XeEueZR

  3. Set secrets to ESPHome Dashboard

    • BLE address I got using Android app "BLE Scanner" or similar app. Went really near car with my phone and picked the address of the ble beacon that the app told to be nearest to my phone. (uncommenting "listener" did not work for me, there was some yml validation error about "vin" property not existing in Listener)
  4. Install the firmware using ESPHome Dashboard normally. Should probably clean the build files first every time.

  5. Add esp32 tesla ble -device to HE integration with the API key from secrets (step descripted in readme)

    • HE found new device automatically for me after esp32 installation.
  6. Do the BLE pairing with the car as descripted on readme (step descripted in readme)

Limitations:

Thanks a lot for this great integration! <3

matkaan commented 3 months ago

I tried to copy and install this script via my ESPHome (2024.7.2 / Docker) but got the following error:

Screenshot 2024-07-26 at 12 38 55

I got the same errors, but still works fine. Did you change the include-rows to reference to github?

pixelwave commented 3 months ago

I got the same errors, but still works fine. Did you change the include-rows to reference to github?

Issue was the Arduino framework. Changed it to:

  board: esp32-c3-devkitm-1
  framework:
    type: esp-idf
    version: 5.2.2
    platform_version: 6.7.0

Now the code compiled! :) Lets see if it works ...

pixelwave commented 3 months ago

ESP32 device logs just show this:

Screenshot 2024-07-26 at 13 23 43

ESPHome YAML File:

esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: esp-idf
    version: 5.2.2
    platform_version: 6.7.0

substitutions:
  friendly_name: ESPHome Tesla BLE
  device_name: tesla-ble
  device_description:  Tesla BLE

esphome:
  name: ${device_name}
  name_add_mac_suffix: true
  friendly_name: ${friendly_name}
  comment: ${device_description}
  project:
    name: yoziru.esphome-tesla-ble
    version: "2024.7.24"
  libraries:
    - https://github.com/yoziru/tesla-ble.git#v2.1.0

packages:
  common: github://yoziru/esphome-tesla-ble/packages/common.yml@main
  client: github://yoziru/esphome-tesla-ble/packages/client.yml@main
  # listener: github://yoziru/esphome-tesla-ble/packages/listener.yml@main   # Uncomment this to scan find your VIN BLE MAC address

logger:
  level: INFO

api:
  encryption:
    key: !secret api_encryption_key

# sync time with home assistant
time:
  - platform: homeassistant
    id: homeassistant_time

ota:
  platform: esphome
  password: !secret ota_password

esp32_ble_tracker:
  scan_parameters:
    # Activate scan only after wifi connect, see https://github.com/esphome/issues/issues/2941#issuecomment-1842369092
    continuous: false

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    password: !secret wifi_hotspot_password
  # Activate scan only after wifi connect, see https://github.com/esphome/issues/issues/2941#issuecomment-1842369092
  on_connect:
    - esp32_ble_tracker.start_scan:
       continuous: true
  on_disconnect:
    - esp32_ble_tracker.stop_scan:

captive_portal:

I tried to install "BLE Scanner 4.0" on my iPhone but it does not show MAC addresses. As I understand iOS hides MAC addresses in general ...

madsdyd commented 3 months ago

Thanks, looks great!

Does anybody know if it is possible to leave such a device "in the car" -- e.g. I could power it from one of the USB ports, and use it as a Wifi gateway? Or would it always leave the car unlocked?

matkaan commented 3 months ago

I had some errors when building an updated version, probably due file caching (I have ESPHome as add-on in supervised HA). Solved by changing package reference files to to refresh every 60seconds, like this:

packages:
  common: 
    url: https://github.com/yoziru/esphome-tesla-ble/
    ref: main
    files: packages/common.yml
    refresh: 60s

  client: 
    url: https://github.com/yoziru/esphome-tesla-ble/
    ref: main
    files: packages/client.yml
    refresh: 60s
pixelwave commented 3 months ago

I had some errors when building an updated version, probably due file caching (I have ESPHome as add-on in supervised HA). Solved by changing package reference files to to refresh every 60seconds, like this:

packages:
  common: 
    url: https://github.com/yoziru/esphome-tesla-ble/
    ref: main
    files: packages/common.yml
    refresh: 60s

  client: 
    url: https://github.com/yoziru/esphome-tesla-ble/
    ref: main
    files: packages/client.yml
    refresh: 60s

Can you post your complete yaml file?

matkaan commented 3 months ago

At the end, I have not found reliable way of updating remote package code for the build using esphome add-on dashboard. It seems to use old version of the code, what ever I try (clean build files, reference to specific version tag, setting refresh time, etc). There seems to be some esphome issues how files are cached, maybe related to this (old) pull request to esphome https://github.com/esphome/esphome/pull/5443

pixelwave commented 3 months ago

At the end, I have not found reliable way of updating remote package code for the build using esphome add-on dashboard. It seems to use old version of the code, what ever I try (clean build files, reference to specific version tag, setting refresh time, etc). There seems to be some esphome issues how files are cached, maybe related to this (old) pull request to esphome esphome/esphome#5443

So basically you recommend to compile the firmware with CMAKE and not ESPHome Dashboard? Is there a short tutorial for that since I am not that experience with that ...

matkaan commented 3 months ago

So basically you recommend to compile the firmware with CMAKE and not ESPHome Dashboard? Is there a short tutorial for that since I am not that experience with that ...

I am also not so experienced with that, I would like to use dashboard to keep things simple. But maybe I will also switch to command line (as descripted on readme). It is probably more reliable way. You can use esphome in a docker or install it locally https://esphome.io/guides/getting_started_command_line

But... Now, without changing anything, I was today again able to build using dashboard just fine! I am pretty sure that ESPHome (at least as a add-on) deletes github code "cache" (only) every 24h. So updating firmware once a day might work. Lets see.

My current full .yml: https://pastebin.com/Q8MGxavM

pixelwave commented 3 months ago

So basically you recommend to compile the firmware with CMAKE and not ESPHome Dashboard? Is there a short tutorial for that since I am not that experience with that ...

I am also not so experienced with that, I would like to use dashboard to keep things simple. But maybe I will also switch to command line (as descripted on readme). It is probably more reliable way. You can use esphome in a docker or install it locally https://esphome.io/guides/getting_started_command_line

But... Now, without changing anything, I was today again able to build using dashboard just fine! I am pretty sure that ESPHome (at least as a add-on) deletes github code "cache" (only) every 24h. So updating firmware once a day might work. Lets see.

My current full .yml: https://pastebin.com/Q8MGxavM

I am running ESPHome as docker. But I get those compile errors with external resources as stated above. And the ESP32 does hang when booting ... -.- Tried two hardware modules laying around ESP32-C3-Mini as well as generic ESP32.

Chreutz commented 2 months ago

Hey everyone. As you, I've been trying to make this work in ESPHome dashboard (in my case as a HA addon).

The following yaml worked for me:

external_components:
  - source: github://yoziru/esphome-tesla-ble/tree/main/components
    components: all

packages:
  base: github://yoziru/esphome-tesla-ble/packages/base.yml
  device_base: github://yoziru/esphome-tesla-ble/boards/esp32-generic.yml
  client: github://yoziru/esphome-tesla-ble/packages/client.yml

dashboard_import:
  package_import_url: github://yoziru/esphome-tesla-ble/tesla-ble-esp32-generic.dashboard.yml

esphome:
  name_add_mac_suffix: false

I included the override to not adding the mac suffix, as it was then showing up in the dashboard as a seperate device, and adopting it tried to install a new firmware to it, and that failed ¯\_(ツ)_/¯. This is my first foray into ESPHome, so I'm new to some of these things.

I never got the listener part to work, but opted to install BLE Radar from F-Droid and deduced that a device with a 20 character seemingly random name starting with "S9" and MAC address starting with B0 was the car.

A recommendation with that app if you're in doubt is to leave the scanning on while driving and check the map. If a device followed you around for the entire drive, it's probably the car.

Hope this helps someone out there :-).

pvmil commented 2 months ago

I did get it to work and be adopted, see https://github.com/yoziru/esphome-tesla-ble/issues/70#issuecomment-2318890375 Would it be an idea to add this to the documentation?