Movement Integration -- Distance and mode of transit tracking

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. :heart: Enjoy!

2 Likes

@wbyoung, very useful, thanks, however, how do you customize what is detected as biking and what is detected as driving ? guess it’s all about the speed, but it annoys me that my 25+ km/h biking is detected as driving.

For me this hasn’t been a problem because my phone doesn’t seem to switch networks as frequently when biking and isn’t connected to a infotainment system forcing constant updates (nor do I use GPS). And sometimes I just bike without the phone.

But I’d welcome a PR to allow customizing the threshold. It could be useful to you (and others). It’ll be hard to get it perfect, though. Some level of inaccuracy has to be expected. :face_with_diagonal_mouth:

Well, as I don’t have a car at the moment I’d basically be happy if I could disable the detection and calculate biking movement only :slightly_smiling_face:

Ahh, well that’s a pretty good use case (and a life I would gladly return to).

If you have the skill/knowledge, feel free to make a PR. Otherwise, you could probably make your own sensor that just combines the values for the time being.

Eventually, if I have time, I may come back to this request (or if there’s enough interest)m

Thanks @wbyoung, wish I had the skills and time to do a PR. Will give the advanced options and a custom sensor a go and see if I can accomplish what I need until somebody may have time :slightly_smiling_face: