Hello all. Back in September I decided that I wanted to try to build some automations around the state of change of my EV. Unfortunately, there was no integration (at the time) that could pull the battery level of my specific car.
To automate without being able to pull the battery level required distance tracking. None was available, so I built something:
The Long Story
For those interested, here’s the TL;DR version…
I started working on something that could determine how far I had traveled in my car during the day. I built it entirely in using template sensors, statistics and Jinja templates. I kind of expected it wouldn’t work all that well based off of prior conversations I’ve seen on here. But it actually ended up working better than expected. About 90% of the time, I was able to get +/- 5% of the actual battery level as it went from 80% → 30%. My code kept growing and eventually got complex enough that I needed to figure out a way to get some tests built for all of it. I knew it was outgrowing the template setup, but didn’t quite know how to build a custom integration.
Well a couple weeks ago, @tube0013 put out the Smartcar integration. I’d been waiting for this. (I tried it in the past, but their API was a little more complicated to get set up in the past & I didn’t think it’d be easy to get working with HASS.) It worked for me, but I ended up learning more about integration development in order to fix some issues.
With my newly acquired knowledge, I updated all of the template based setup I had to an actual integration that’s available via HACS.
Hopefully this is useful to someone. Enjoy!