Logging Tesla efficiency and performance using the Web API

Graph of Tesla speed and battery current

Odometer: 1745 miles

One of the cool things about having an intelligent car with a built in LTE connection is the ability to ask it to provide information about itself. Tesla provides both iPhone and Android apps that allow owners to unlock the car, flash the lights, and monitor charging. However, as a Big Data geek and recovering data scientist, I’m more intrigued by recording information about the car so that I can monitor its performance and state over time.

So to begin, a quick shoutout to the developers who have made it possible for owners to monitor their Teslas:

So with all this work as a foundation, as a big data guy, I had to write my own data logger.

Just to be clear, what this API does is not monitor the car itself directly; instead, it communicates with Tesla’s servers that regularly monitor the car. So there’s a level of insulation between user code and the car that I am quite thankful for. I’d really hate to see someone’s buggy code decide to run my car’s stereo system volume up to 11, for example.

My current Tesla data logging program shares a Raspberry pi with a homegrown weather and solar panel monitoring system. Because I started with Rob M.’s example code, it’s written in Python and it’s pretty simple minded. What it does is poll my Tesla every 20 minutes and log its state into a .csv file. If it ever notices the shifter state is not None, it ups the logging rate to every minute until the shifter goes back to None again.

With the data in .csv form, I then can use R and ggplot2 to generate not only line graphs, but to apply a smoothing regression to the data to make it easier to see trends, as shown in the graphic at the top of this post. The blue line in that graph is the car’s speed, while the red line is the battery current, which goes negative when I’m driving the car and goes positive when it is being charged.

This is all pretty rudimentary stuff at present, but I hope to make it more sophisticated as time goes on. At the very least, I’ll have a nice hard baseline of data about driving efficiency and performance when the car was new to compare with as the car ages.

I’ll be driving Lightning to Montreal and back August 8 and 9, so I’ll be particularly interested to see the logs from that 700 mile trip. I’ll share what I learn after I’ve had a chance to analyze the data.