Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register

Calculating kWh from Tesla API for a drive

This site may earn commission on affiliate links.
Hello all, new member here. I’ve searched a bunch so forgive me if it has already been answered.

Basically, I’m trying to calculate kWh used from the Tesla API while driving. I think I see how to calculate kWh while charging (there’s energy added, there’s current, phases, and voltage) but the only “state” information while driving is battery level and estimated range in all it’s variations. To base it off of battery level % you have to assume a top end energy available (ie ~72kWh for 75) which seems highly inaccurate and/or uncertain. To use estimated range you have to assume a nominal energy rate (ie 333 Wh/mi) this doesn’t seem particularly accurate either.

I don’t want to assume energy used based upon energy added because that would presume you are always adding to the same point and sometimes I stop early or might change the stop point, and this seems like really low quality data.

I’m not looking to create an app or anything I’m just writing my own software for my own purposes. Yes, I know there’s TeslaFi et al but how do they calculate it?

Thanks for any assistance.