lephisto / tesla-apiscraper

API Scraper for pulling Vehicle Statistics from the Tesla Owner API into an InfluxDB + Grafana Dashboards
GNU Lesser General Public License v3.0
365 stars 102 forks source link

What would best way to calculate cost of charge? #55

Open CptanPanic opened 5 years ago

CptanPanic commented 5 years ago

I would like to get data similar to teslafi charging data https://about.teslafi.com/charge-tracking/ like how much was charged in a session and how much that cost. Any ideas how to do that with the data we have?

eliluong commented 5 years ago

Use most recent value of charge_energy_added to determine how much kWh added for last charging session. Use charger_voltage to determine if using level 1, level 2, or level 3 charger. I think level 3 charging will have fast_charger_present as true, and fast_charger_type as Tesla. Then if you frequent one supercharger regularly, then you just use that to calculate the cost, otherwise you'll have to either generate your own database of supercharger costs and calculate it there, or make up an average cost per kWh. At home you can come up with either cost per kWh, or if cost per kWh changes with time, then you have to extract the start/stop charging times and then calculate from there.

bert4git commented 5 years ago

@CptanPanic Did you solve the problem? I'm looking for a similar dashboard, but i'm very new to this sql syntax and yea....

CptanPanic commented 5 years ago

@CptanPanic Did you solve the problem? I'm looking for a similar dashboard, but i'm very new to this sql syntax and yea....

I haven't gotten it to really work yet, but am trying to just use the variable charge_energy_added, which increases as you charge. So you take the max of each charging session.

bert4git commented 5 years ago

Whats the way you detect the charging sessions? I have seen - the max value will not only work. If you finished charging - the plug is in the car, the energy will decrease about 0.1 to 0.2 and this will be recharged. The values will be: 0.2 0.3 ...7.9 7.8 7.9 7.8 7.7 7.9 each new recharge is in the database with an Charging Event. I was looking for a solution and found a second implementation - called TeslaLogger (Github) with a similar db-schema and an implentation of this metrics. Currently i'm trying to understand the statements and try to implement it here...

CptanPanic commented 5 years ago

So the way I have it so far is look for charger_state of "Disconnected" and then find the previous value of charge_energy_added.