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

How to get my car's rated Wh/mile via API or otherwise?

This site may earn commission on affiliate links.
Hello:

I'm using the Tesla API to access data about my Model S and I'm trying to get a reading on the current battery level measured in kWh. I know that I could get a direct battery reading, but I'd like to do this measurement via software and I'd like to do it every night.

I've seen that the charge_energy_added field seems to frequent start tracking quite late after the charging has started. So I'm trying to figure out how to determine how much energy is added to the battery using the battery_range field. I've read on multiple threads that the battery_range is -actually- determined by Tesla by multiplying the actual kWh currently in the battery times the "hardcoded" Wh/mile that the car is rated at. Of course, the rated Wh/mile will be different for each model/year, etc so I can't hard code the value in my software. If I "watch" a charging session by pinging the API every 60 seconds, I can calculate the miles of range that are added during the period of time when the charge_energy_added field is working correctly. From there, I can impute that my car is rated at ~311 Wh/mile. Once I have this number, then any time I want to know my battery level in kWh, I can simply multiply the battery_level times 311.

But, is there ANY way to just get the rated Wh/mile for my car directly rather than having to impute it from a charging session? Maybe it's in the existing Tesla API, or maybe its on an EPA web site?? Anyone have any ideas?
 
Wh/mi is dependent upon a desired delta. For example, do you want the Wh/mil over the last100 miles, the last trip, lifetime? I'm not an expert on the API, but I don't think it's a single API query, instead it uses the streaming API to retrieve values over small chunks. It's then up to you to do the math to determine efficiency over the trip, over the last 5 miles, etc. Your logic above sounds very similar but uses the battery percentage only at charge start and end and therefore would be a Wh/mil per "fill-up". Remember, any Wh/mil is an estimate just like the charge level in your battery is an estimate. Your efficiency numbers are really only meaningful over long distances or times.
 
Wh/mi is dependent upon a desired delta. For example, do you want the Wh/mil over the last100 miles, the last trip, lifetime? I'm not an expert on the API, but I don't think it's a single API query, instead it uses the streaming API to retrieve values over small chunks. It's then up to you to do the math to determine efficiency over the trip, over the last 5 miles, etc. Your logic above sounds very similar but uses the battery percentage only at charge start and end and therefore would be a Wh/mil per "fill-up". Remember, any Wh/mil is an estimate just like the charge level in your battery is an estimate. Your efficiency numbers are really only meaningful over long distances or times.
Yes, to measure Wh/mile as an actual number, it would require watching the numbers change over time, but I’m asking a separate question:

Every Tesla that’s sold has a rated range. This rating is based on EPA requirements and is not the typical actual range one would get “in the real world”. But, Tesla nonetheless quotes the battery level in “rated miles” rather than in kWh. So, if I knew the “rated Wh/mile”, i could easily multiply the battery range in “rated miles” times “the “rated Wh/mile” to know the actual kWh stored in the battery.

But, I can’t find this actual number via the API except to observe the car during charging. You can see this value inside your Tesla on the Energy screen as shown below which would tell you that this data has to be somewhere!!

So, back to the question:
Does anyone know of any way to get the rated Wh/mile?
 

Attachments

  • IMG_6314.jpeg
    IMG_6314.jpeg
    368.4 KB · Views: 113
But, is there ANY way to just get the rated Wh/mile for my car directly rather than having to impute it from a charging session? Maybe it's in the existing Tesla API, or maybe its on an EPA web site?? Anyone have any ideas?

The ”rated” wH/mi is equal to the battery size * 1000 / by the EPA range. For example, if a car has a 100 kWh battery and the EPA range is 400 miles, then 100 kWh * 1000 / 400 miles = 250 wH/mi.
 
The ”rated” wH/mi is equal to the battery size * 1000 / by the EPA range. For example, if a car has a 100 kWh battery and the EPA range is 400 miles, then 100 kWh * 1000 / 400 miles = 250 wH/mi.
great and I agree. But, I can't seem to find either the battery size or the EPA range in a systematic way via the API or via any other programatic means. Any ideas on where to find these numbers?
 
great and I agree. But, I can't seem to find either the battery size or the EPA range in a systematic way via the API or via any other programatic means. Any ideas on where to find these numbers?
Not sure you find any way to do this programmatically, but here is a link to the EPA site for range.

 
@jkochans - Sorry, just spotted this thread. You may have already sorted out what you're going to do. A few comments from having collected data on my mid-2016 MS90D for 7 years, first via a 'shareware' desktop program, and the past 3 years with my own standalone python routine I run from my home laptop.

There is no direct way via the API that will allow you to directly get either the current usable capacity of the battery or the rated wh/mi constant. There are multiple ways you can back calculate an apparent wh/mi constant. My belief, without every having seen the actual code behind apps like TeslaFi is that they are inferring the value by one of those means or have simply embedded a reference value based upon the model of the car.

I've also used data provided by my car to compute a rated wh/mi constant, and depending upon which set of data I use, they do not always match. I went down the rabbit hole to try and rationalize that at one point, but then ran across some threads with some of the old timers that had thrashed this topic who helped me understand that even Tesla isn't always consistent in all areas of their code on the constant. For instance, if I use the data from the Trips screen for my distance traveled, energy used, trip wh/mi and ratio that to the number of rated miles consumed, I'd come up with a constant that is somewhere around 274 wH/mi for my car. That's also what I find I need to average over a long drive for the trip screen to show a distance traveled equivalent to the odometer miles traveled.

However, is I look at the Energy screen (graph like you show above) the values there and my "rated" line is based on a constant that is about 288 wh/mi.

Now doing it from the reported RM added and kWh added for a charging session on my car gives me a value of around 285 wh/mi. (note: This is a value averaged over about my last 35 charging sessions; individual session per the data from the API would range from 283 to 287, somewhat due to numerical rounding errors given the fixed precision of the numbers reported). That's similar to what I get from the Energy screen, but again, doesn't match with what I'd see the car report to me for my Wh consumed over a long, continuous drive on the Energy screen.

Now there is a more fundamental question ... why do you care about the pack capacity in kWh???? That's not reported anywhere such that you can use it as a practical input to you daily driving behavior. If you're looking to track apparent battery degradation, you can just do that by rated miles. As you've already said, ti and pack capacity in kWh is the same value, just reported in different units by applying a fixed constant. It's like reporting distance in km versus miles vs ft. There are all the same physical distance, just a numerical constant a part. The big this for tracking apparent capacity is you want a consistent way to determine that you can trend over time. An easy way to do this is simply to track the RM/SOC at the end of any charging session, which will give you the apparent RM at 100%, trend that over time compared to the value of the car when new. I've done that for 7 years, it's a stable, consistent value. I have a clear trend, shows me my pack at around 8.5% degradation from new. Oh, and for those that will say this isn't valid unless you slow charge to 100%, I'd dare you to pick out the 40 or so full 100% charges from my over 1300 charging sessions to tell me which at the 100% charges. You can not spot any difference; they all fall in the charge-to-charge noise.

Enjoy your car.
 
  • Informative
Reactions: jmaddr
hello, Has anyone provided you with a URL / link to documentation related to an API, that details connection parameters, auth type, endpoint definitions, etc.? I am wanting to create an app for my iPhone that will request data via api endpoints and push the json responses to Azure / AWS via an MQTT client. Want to run analytics and possibly instantiate learning models on the data. I intend to start a quarterly blog to answer questions related to performance and functionality from the perspective of a new Tesla model S owner. Also, I do not need to reinvent the wheel, if there is already an app with this type of functionality that is open source that would work also.
 
If you just google tesla api you'll find information on both the legacy API (Tesla never documented, but what a multitude of existing apps used via "unofficial documentation) and also Tesla's official documentation of the new API that was announced earlier this year.

Here's the link to the new API. Unclear yet what the cost model will be when it's announced first of the year to be able to pull data on an on-going basis.