Monday, August 28, 2023

Electrified Road Trip Part 2: Tracking with Teslamate

In preparation for my big road trip, I added Teslamate to my Home Assistant setup.  I have to say, I am sad that I didn't do this on day 1.  This little platform is amazing, and it not only gets a huge amount of data out of Tesla's cloud and on to my own hardware, but it also generates some wonderful Grafana dashboards too!  It is kind of a game changer compared to the way I have collected stats from my current car, and just using the unofficial Tesla Integration for home assistant.

So, the integration's main screen doesn't look like anything special.  The map shows the real time location of the car, along with some basic stats about the car.  You can also use Geo-fences to give common locations any name you like, and you can even set a charging price for the location.  This is particularly useful for charging at home because there is no receipt for purchasing power like you get from a charging station.  I will get into manually updating charge prices once I figure that out, but I rarely charge anywhere other than home, so it is a low priority task for me to sort out.

The real advantage comes with 2 backend features this plugin provides.  First, the plugin integrates with a database to log all your data about your car.  This data goes far beyond just what you see on the plugin page, and this is why Grafana is the real hero for this plugin.  The second feature is MQTT, which is just a protocol used by IoT devices to communicate updates.  Once you have these two features, you can create dashboards in Grafana to visualize the data and create reports, and MQTT sends the data to home assistant so I can trigger events based on the reported stats.

To the right I show MQTT explorer, which shows an example of the message data Teslamate sends to Home Assistant.  This data gets updated in real time, and one thing this does for me is update any time the car is unplugged from the charger immediately, rather than having to wait for the integration to poll Tesla for the data, which can take anywhere from no time to 5 minutes.  One problem this caused me a few times is that I would unplug my car, and have Home Assistant log the data to a google sheet; however, if the data didn't get logged immediately my car would not be at home when the data was logged, and my cost estimates would be off.  I guess Teslamate removes the need for this Google Integration too, which I appreciate reducing the number of cloud dependencies I have.

Possibly the best part of the this addon is Grafana Dashboards!  For those who don't know, Grafana is a web application that can collect data from databases and organize it into Dashboards, which are a collection of charts, graphs, and data.  It is somewhat popular for its ability to collect data from many places and combine it all together into a single screen/report that is full of pretty pictures.

Teslamate has a bunch of dashboard that is loads into Grafana if you set it up correctly.  Its a great way to visualize things like your most recent trip data and commute data.  For example, this image shows a track for everywhere I've driven this month. When I scroll down through the list of drives I've made, I can tell that I drive the same few routes over and over again, and it gives some nice summary information like how efficiently I drive (256 Wh/mi) and the fact I have paid about $13 to drive my car 265 miles (which is WAY cheaper than gas).  Just getting access to this data is a critical asset to accurately estimate my personal cost of driving the car, and having a few months of data under my belt will give me a clear picture of how far I can drive my car on a single charge.

For those interested in the process of getting this all set up, I added 3 home assistant add-ons using the instructions on the mat-FFFFFF github repository here.  If you are savvy with docker and have a spare raspberry pi laying around, I have to admit most of the troubleshooting resources online focus on putting everything into its own container.  However, its not too difficult to follow the directions and get it all setup, but maybe that could be a good thing to write about next.  Let me circle back around to that once I get around to refactoring a couple things for best practices.

Anyway, that's it for now.  Until next time.