Unlocking the Charge Port of a Tesla via Home Assistant

Tesla chargers have a button on the plug that when pressed, unlocks the cable from the port automatically. Very slick but if you do not have a Tesla charger at home (like me) this is a daily pain in the arse involving whipping out my phone, opening the Tesla app and pressing “unlock charge port” before I can drive away.

To make life easier I added my car to Home Assistant and used an IKEA Zigbee button (RODRET) to replicate the button on the Tesla charging hardware that non-Tesla chargers lack. It wasn’t difficult but the steps are not obvious and the process has changed recently due to Tesla changing up how they implement API access to the vehicle. To save others from wasting a few hours of their life, here’s the steps I took to get it all working.

Add the Tesla Fleet integration to your HA setup. It’s part of the core HA integrations which is nice.

You’ll see the car added and can view the sensors and all that cool stuff but when you go to send a command it’ll throw an error like “Unknown ID”. The Tesla Fleet integration documentation says that happens because:

“Certain vehicles, including all vehicles manufactured since late 2023, require vehicle commands to be signed with a private key. All actions on vehicle entities will fail with an error if this is required and the key has not been added to the vehicle. You will need to use Tesla’s command line tools to generate a key pair and install the public key on your vehicle using Bluetooth.”

I have a 2021 Model 3 but still had to do this, so it’s not just new vehicles that require a private key. This is where things get annoying. You need to whip out a laptop and install Tesla’s command line tools and pair your laptop to the car, generate a key, then move that key to your HA device. You’ll also need your car’s keycard to generate a key.

Tesla has some command line apps that let you interact with the car. You need to install those on your computer (Mac or Linux) first. Installation on a Debian based Linux (Ubuntu, Mint, etc) was pretty easy:

  • Install Golang (can check if it’s installed by typing go version), if it’s not installed just run sudo apt install golang

  • Clone Tesla’s vehicle-command repo off Github: git clone GitHub - teslamotors/vehicle-command

  • Enter the vehicle-command directory, then run go get ./… and go build ./… then go install ./… (if like me, the install command didn’t add the tools to your terminal’s PATH, the apps are located in /home/username/go/bin)

Once you’ve installed the apps and verify they work, get close to the car with your computer and run:

tesla-keygen -key-file tesla_fleet.key create > tesla_fleet.pem

to generate a public key then this to generate the private key

tesla-control -ble -key-file tesla_fleet.key -vin VINVINVINVIN -debug add-key-request tesla_fleet.pem owner cloud_key

Replace VINVINVIN with your vehicle’s VIN of course. Running that command should bring up the following if successful:

decryption@t460:~$ sudo ~/go/bin/tesla-control -ble -key-file tesla_fleet.key -vin VINVINVIN -debug add-key-request tesla_fleet.pem owner cloud_key
2025-01-02T16:03:45+11:00 [debug] Set session cache file to '/root/.tesla-cache.json'
2025-01-02T16:03:45+11:00 [debug] Set OAuth token name to ''
2025-01-02T16:03:45+11:00 [debug] Set OAuth token file to ''
2025-01-02T16:03:45+11:00 [debug] Set keyring type to ''
2025-01-02T16:03:45+11:00 [debug] Set keyring Debug Logging to 'false'
2025-01-02T16:03:45+11:00 [debug] Skipping private key loading because FlagPrivateKey is not set
2025-01-02T16:03:45+11:00 [debug] No private key available
2025-01-02T16:03:45+11:00 [debug] Connecting over BLE...
2025-01-02T16:03:45+11:00 [debug] Creating new BLE device
2025-01-02T16:03:46+11:00 [debug] Searching for BLE beacon Sc76597fd2e4ad25fC...
2025-01-02T16:03:46+11:00 [debug] Connecting to BLE beacon a4:9f:89:a8:27:1d...
2025-01-02T16:03:46+11:00 [info ] Connected to vehicle BLE
2025-01-02T16:03:46+11:00 [info ] Connecting to car...
2025-01-02T16:03:46+11:00 [info ] Starting dispatcher service...
2025-01-02T16:03:46+11:00 [debug] TX: 0a54125082014d320208092a470a430a41047491eaddecfc10ee3950e427115027bbf8d2f6d488bafaacd9b6f2aa1dfa60eb4f180f6a91d4c8f66d3b1bd921ea8a68c978eb4bb51ce91565a6db8ce051652820021802
Sent add-key request to VINVINVIN. Confirm by tapping NFC card on center console.

Do what the app says and quickly tap your NFC card on the center console and this will pop up on your Tesla’s screen:

Tap confirm (it doesn’t stay up for long, so be quick!) and the pain in the balls bit is over. The contents of tesla_fleet.key should look something like this:

-----BEGIN EC PRIVATE KEY-----
random letters & numbers
-----END EC PRIVATE KEY-----

Now you need to send this file to your Home Assistant server and place it in the same folder as wherever your yaml files are (like automations.yaml, scenes.yaml, configuation.yaml, etc) - on my Raspberry Pi based setup, it’s in /root/config. I did it via the File Editor add-on and edited the existing tesla_fleet.key file:

Screenshot 2025-01-04 at 07.56.23

Reboot your HA setup and now sending commands to your Tesla should work. Give it a quick test by flashing the headlights or honking the horn. Now you can do whatever you wish with the car as if it was any other device in HA. Here’s the automation I made:

Uses the IKEA Zigbee button that when pressed, wakes the car up and waits 10 seconds (it can take a little while to wake up from a deep sleep), unlocks the charge cable and flashes the lights to let me know it happened. I love Home Assistant!