Skip to content

Commit

Permalink
fix startup bug and update logging
Browse files Browse the repository at this point in the history
- Fix extension stopping at first MQTT listening
- Update logging and documentation
- Improve pairing procedure doc and logging
- Improve HA entities classification
- Cleanup
  • Loading branch information
raphmur committed Jun 16, 2024
1 parent 2b4e5f9 commit 11d1500
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 157 deletions.
14 changes: 0 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@ This package contains:

## BLE Pairing with your car

- Navigate to the Tesla_BLE_MQTT Device info.
- In HA : Settings -> Devices & Services -> Devices (tab) -> Tesla_BLE_MQTT
- Press : Generate Keys (required once)
- Press : Deploy Key (car may need to be awake - TBC)
- If the command succeed to initiate the pairing with the car, the following will show in the add-on logs:
`Sent add-key request to _YOUR_CAR_VIN. Confirm by tapping NFC card on center console.`
- Tap your NFC card on the center console
- On the car's screen `Phone Key pairing request`, confirm your accept the pairing

- If the command failed, the following error will show up:
`Error: failed to find BLE beacon for _YOUR_CAR_VIN_. (S________________C): can’t scan: context deadline exceeded`
- You car might just be too far from your Bluetooth adapter.

- Credits : Shankar Kumarasamy's [Blog](https://shankarkumarasamy.blog/2024/01/28/tesla-developer-api-guide-ble-key-pair-auth-and-vehicle-commands-part-3/)

## Add-ons

Expand Down
10 changes: 10 additions & 0 deletions tesla_ble_mqtt/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<!-- https://developers.home-assistant.io/docs/add-ons/presentation#keeping-a-changelog -->

## 0.0.5

### Changed

- Fix extension stopping at first MQTT listening
- Update logging and documentation
- Improve pairing procedure doc and logging
- Improve HA entities classification
- Cleanup

## 0.0.4

### Changed
Expand Down
57 changes: 39 additions & 18 deletions tesla_ble_mqtt/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
# Home Assistant Add-on: Tesla Local Commands

Send commands via MQTT to a Tesla car using Bluetooth Low Energy (BLE)


This Addon is a package of iainbullock's https://github.com/iainbullock/tesla_ble_mqtt_docker
It runs the official Tesla Vehicle SDK commands via BLE to activate various entities in your Tesla.
This is to bypass the current Fleet API rate limitation.

It does not rely on the API.
This is to bypass the current Fleet API rate limitation as it does not rely on the API.

This package contains:
- All the code generated by iainbullock repackaged as a HA addon
- A `standalone` folder which contains a single script to run the BLE service on a separate machine

# Tesla BLE MQTT Docker

Send commands via MQTT to a Tesla car using Bluetooth Low Energy (BLE)

If Home Assistant (HA) is already using the MQTT integration, then the various entities will be auto-discovered by HA
# Prerequisites

You must already have a working MQTT broker. If you want the entities to be auto-discovered by Home Assistant (HA), then the HA MQTT Integration must already be set up and working. See: https://www.home-assistant.io/integrations/mqtt/
The advantage of the MQTT setup is that it can run on a device separate to your HA server, e.g. Raspberry Pi located close to where you park your car

## Installation and setup

1 You must already have a working MQTT broker. If you want the entities to be auto-discovered by Home Assistant (HA), then the HA MQTT Integration must already be set up and working. See: https://www.home-assistant.io/integrations/mqtt/
# Installation and setup

Note that in both cases below, if you have already created a key pair that you want to reuse, place the private key in `/share/tesla_ble_mqtt`
If you have already created a key pair that you want to reuse, place the private key in `/share/tesla_ble_mqtt`

## 1.1 HA Add-on: install below and configure

[![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https://github.com/raphmur/tesla-local-control-addon)

2.1 For the HA Add-on: install below and configure.

You will need to provide:
- TESLA_VIN (car VIN)
Expand All @@ -35,20 +36,40 @@ You will need to provide:
- MQTT_PWD
- SEND_CMD_RETRY_DELAY: delay between retries in case BLE fails. Use 5 by default

[![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https://github.com/raphmur/tesla-local-control-addon)

2.2 For the standalone version, it has been tested on RPi 3B so far. Here are the assumptions and way forward:
## 1.2 For the standalone version

It has been tested on RPi 3B so far. Here are the assumptions and way forward:
- You already have Docker working on the host device, and you are familiar with basic Docker concepts and actions
- Clone the self packaged shell script: `https://github.com/raphmur/tesla-local-control-addon/blob/main/standalone/start_tesla_ble_mqtt.sh`
- Clone the self packaged shell script: `wget https://github.com/raphmur/tesla-local-control-addon/blob/main/standalone/start_tesla_ble_mqtt.sh`
- Edit the script to input your own settings: TESLA_VIN, MQTT_IP (ip of your MQTT server), MQTT_PORT, MQTT_USER, MQTT_PWD, SEND_CMD_RETRY_DELAY (delay between retries in case BLE fails), _optional_ _BLE_MAC_ (to be used for proximity discovery)
- run the script: `./start_tesla_ble_mqtt.sh`, it will download the rest of the elements, build and deploy the container

3 THEN:
## 2 Pairing with your car

- Navigate to the Tesla_BLE_MQTT Device info.
- In HA : Settings -> Devices & Services -> Devices (tab) -> Tesla_BLE_MQTT
- Press : Generate Keys (required once)
- Press : Deploy Key (car may need to be awake - TBC)
- If the command succeed to initiate the pairing with the car, the following will show in the add-on logs:
`Sent add-key request to _YOUR_CAR_VIN. Confirm by tapping NFC card on center console.`
- Tap your NFC card on the center console
- On the car's screen `Phone Key pairing request`, confirm your accept the pairing

- If the command failed, the following error will show up:
`Error: failed to find BLE beacon for _YOUR_CAR_VIN_. (S________________C): can’t scan: context deadline exceeded`
- You car might just be too far from your Bluetooth adapter.

- Credits : Shankar Kumarasamy's [Blog](https://shankarkumarasamy.blog/2024/01/28/tesla-developer-api-guide-ble-key-pair-auth-and-vehicle-commands-part-3/)

## 3 THEN

- A new device called Tesla_BLE_MQTT should have automatically appeared. Click it to view the the associated entities. You should find a list of Button entities and a Number entity
- If this is the first time you have run the container, press the 'Generate Keys' button. This will generate the public and private keys as per Shanker's blog
- Wake up your car using the Tesla App. Then press the 'Deploy Key' button. This will deploy the public key to the car. You will then need to access your car and use a Key Card to accept the public key into the car (see the blog for screenshots)
- Then you are ready. Press the other button entities to send various commands, or change the Charging Current. You can use the relevant service calls in HA automations if you wish
- If this is the first time you have run the container, press the 'Generate Keys' button in HA (Settings -> Devices & Services -> Devices (tab) -> Tesla_BLE_MQTT). This will generate the public and private keys as per Shanker's blog
- **Wake up your car using the Tesla App**. Then press the 'Deploy Key' button. This will deploy the public key to the car. You will then need to access your car and use a Key Card to accept the public key into the car (see the blog for screenshots)
- If the command succeed to initiate the pairing with the car, the following will show in the add-on logs: `Sent add-key request to [YOUR_CAR_VIN]. Confirm by tapping NFC card on center console.` Go in your car and tap your NFC card on the center console and on the car's screen `Phone Key pairing request`, confirm your accept the pairing
- If the command failed, the following error will show up: `Error: failed to find BLE beacon for [YOUR_CAR_VIN]. (xxx): can’t scan: context deadline exceeded`. You car might just be too far from your Bluetooth adapter. The command will be tried in case bluetooth is weak or unavailable...
- Then you are ready. Press the other button entities to send various commands... You can use the relevant service calls in HA automations if you wish

## Credits

Expand Down
2 changes: 1 addition & 1 deletion tesla_ble_mqtt/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Tesla Local Commands"
version: "0.0.3zb"
version: "0.0.5"
slug: "tesla_local_commands"
description: "Local BLE calls to control your Tesla."
# url: "tbc"
Expand Down
Loading

0 comments on commit 11d1500

Please sign in to comment.