Tesla's API is seriously undervalued!

One of the most fun aspects of being an amateur software developer and having access to a Tesla is the unparalleled possibility it offers in terms of data and automation, like no other vehicle. I've always believed that cars were ridiculously simple for the 21st century, having comparable or often fewer features than a smartphone and was honestly disappointed the first years of having a licence, innovation in the industry slowed to a crawl and everybody settled.

Until the disruption came from Tesla, when EVs were shown to be more than just tokens for environmentalists - they became desired.

These computers on wheels are some of the most complexly engineered products on the planet, whilst having a beautifully straightforward and easy to use programming interface. Obviously Tesla are harvesting information about safety, autopilot usage, and charging etc., but the entire vehicle API is also accessible to owners and contains a plethora of interesting information; like GPS location, temperature, charging status, media information and a whole lot more. Just as if using the app, you can send commands directly from a computer terminal or python script.

It might not be obviously useful, a little gimmick to be able to monitor your car's location from any internet-connected device, but there's so much potential to store this and create dashboards of trends over time; average charging rate, total usage, location or temperature and tyre monitoring…the list goes on.

The real gem though lies in the automation available, just a few possibilities are;

  • Send an alert if the GPS coordinates change and activate speed limit mode

  • More granular control over AC depending on the temperature

  • Setting daily schedules for pre-conditioning, charging or sentry mode

  • Email / RSS alerts based on any value conditions, triggering a sequence of actions in response

The options are endless and it's both incredibly exciting and quite daunting to think about where to start. Thanks to some generous, intelligent individuals, the owner API that's used by the app has been reverse engineered and fairly well documented, it gives a great tutorial on getting set up and some common functions to perform.

This is great for hobbyists like myself to play around and I've been busy for a couple of months now. It started as a simple Command Line Interface to test retrieving account and vehicle information, just dumping out a huge JSON payload and poking around at the contents to get some inspiration. I still cannot comprehend how many different things might be accomplished or interesting trends discovered.

I added simple triggers to enable and disable sentry and valet mode, and of course to test the remote boombox (fart) feature. It worked like a charm, but wasn't particularly practical even being on a laptop I could take anywhere.

The real goal then is to build a web portal hooked up to a database, hosted on a Raspberry Pi or similar, with a little bit of port forwarding and some security - to provide a personal dashboard for your vehicle to view data and reports, send and schedule commands or even more complex automation from anywhere in the world. Fun, right?! Is that just me?

Regardless, there's already a clear market for fleet operators managing hundreds of vehicles that require a unified solution, or just keen owners looking for more than Tesla currently offer, hence the appearance of services like TeslaFi - https://about.teslafi.com.

Being a keen programmer I wanted the challenge of doing it myself, all you need is an authentication token that’s obtained with your usual login credentials. Then it's a simple matter of building a structure of commands, a method of execution and a frontend framework for user interaction from a browser.

Here’s the current iteration, there's a page full of data:

A dashboard to pin anything specific as well as some useful info widgets:

Easy access to common commands:

A basic scheduling page for now:

This is the biggest challenge by far and the current work in progress, the underlying system is in place and now comes the UI to actually create and manage the scheduled tasks.

Chat GPT has been a helpful copilot in this endeavour, I keep a web panel on the side for any quick questions or code snippets, the results though are unpredictable. Every answer sounds perfectly legitimate and most work well enough with a few tweaks, but occasionally it will produce something entirely incorrect with utmost certainty, which can waste time chasing down a dead end.

As long as you bear that in mind and do a little fact-checking, it's much more efficient than Google, which in recent years has been declining in ability to serve helpful results and will likely soon be surpased. The advertising model has corrupted so far that finding unbiased information is very difficult, the first page of results are sponsored and they hijack traffic from other sites by providing their services inline (flight checker sure seems convenient), but all these offerings have a darker consequence. If Google had their way you'd stay on their site and do all your browsing or web activity through their service, who could refuse all that wonderful (pure profit) data? I digress...

Chat GPT has some way to go, but it's becoming an invaluable tool in the kit of programmers and countless other professions, fast.

At times this project has been incredibly frustrating with nothing going right, usually after a night's sleep, fresh eyes glean a solution or alternate approach that didn’t occur before. It’s an ongoing effort of constant iteration, trust in the process and the rewards are incredibly satisfying. Along the way I've learned some new skills, levelled-up my Python and revelled in each success no matter how trivial, especially after hours of debugging, there's few greater feelings than finally cracking that code!

So this is just a summary to share what I've been working on and what's to come, a more detailed technical breakdown will follow in future posts for those who are interested. I'll also put the source code up on GitHub at some point once I've assembled all the pieces together into a solid framework, so that hopefully others may build upon it or have a free, open-source foundation for unlimited personal projects.

Previous
Previous

Tesla Insurance set to disrupt the market

Next
Next

Tesla Investor Day 2023