On Charges dash the charged and kw data is not consistent with Charges Details.
Everything else (mph, SOC, etc) looks ok. I have a variable energy tariff hence the multiple charging sessions.


Thanks!
If I understand the code correctly, each charge session once it's started must reach "Complete" status to be inserted as a full session. As I mentioned above I have variable energy tariff and I have a script that start/stop the charge during the day. A minimum charge session is 30 min as the tariff is every 30 min. So in my case I might never reach "Complete" status depending of my charge limit settings.
I suggest that "Stopped" status should be considered as a recorded full session.
Thank you!
I did not consider variable energy tariffs so I'm not surprised that it doesn't behave like you'd expect. But I have not yet fully understood what you mean. Could you explain in more detail what you expect to happen and what you are seeing now? E.g. what exactly is not consistent? Thanks!
I have my car's charge limit set to 80%. If I manually stop the charge before the car could charge to 80% this condition will not trigger:
if last_state == "Complete" do
Logger.info("Charging / Restart", car_id: data.car.id)
{:ok, _cproc} = call(data.deps.log, :resume_charging_process, [pid])
end
So the next time I plug in and start a new charging session, all the added kwh and kw speed will be averaged with the previous charging sessions. This is what I understand from the stats:

From the logs:
00:31:52.693 car_id=1 [info] Charging / SOC: 66%
01:01:30.299 car_id=1 [info] Charging / Stopped / 0.88 kWh – 29 min
It should say approximately 3.5 kWh as "#{added}".
I'm still trying to grasp Elixir so I might be wrong in understanding the charging handle_event function.
Thanks!
Okay, so the charge session is 30 min and you are charging with 7 kW. Hence "charged" should say approximately 3.5 kWh. However, "charged" says 0.88 kWh.
I'm not yet fully convinced that this has something to do with triggering the above mentioned condition because all other values (mph, SOC, etc) look okay. This suggests that the charge session was completely logged.
The "charged" value is reported by the car / the API i.e. if that value is incorrect, the "kW' and "mi /h" values are also derived incorrectly.
Let's debug this. Could you add the value charge_energy_addedto the Charge Details dashboard?
The query should look like this:
SELECT
$__time(date),
battery_level as "SOC [%]",
charger_power as "Power [kW]",
convert_km(ideal_battery_range_km, '$length_unit') as "Range [$length_unit]",
charger_voltage as "Charging Voltage [V]",
charger_phases as "Phases",
charger_actual_current as "Current [A]",
charger_pilot_current as "Current (pilot) [A]",
convert_celsius(outside_temp, '$temp_unit') as "Outdoor Temperature [°$temp_unit]",
c.charge_energy_added
FROM
charges c
join
charging_processes p ON p.id = c.charging_process_id
WHERE
$__timeFilter(date) and
p.car_id = $car_id
ORDER BY
date ASC
How does the charge_energy_added graph look like between 00:31 and 03:35?
It stayed at 0 for almost the entire charging session from 0.30-1.00.

That's strange. But then there is nothing we can do here, I'm afraid? Or am I missing something? However, the 10.09 kWh of the second charge session are definitely wrong.
What do you prefer in this case? Should all charge session be combined into one? Or should the second charge session show 10.09 - 0.88 = 9.21 kWh?
I think that every charging session (plug/unplug, start/stop from the app, charge complete, etc) should have its own added kWh. It should be useful to debug charging issues that might happen with the car or for the future features of the logger (combine battery heater status and charger charging power to provide charging efficiency in different temperature).
I have expanded the graph for the maximum days I have recorded for charging and it happened a day before for charge_energy_added to stay 0 for few minutes at the beginning of the charging session.
If charge_energy_added comes from the tesla api module then for the moment I'll monitor the values for each charge and see if I can find a pattern why it's 0 sometimes.
Thanks!
Still testing the charging...
Last night the session ended with Complete status, but still charge_energy_added was 0 for few minutes at the beginning of the charge session. The charge_battery_heater was off, so no relation there.
Can you add charge_miles_added_ideal or charge_miles_added_rated to the database? I'm not that confident I'm able to do it in Elixir. I want to see if the car reports added miles but not added kWh. Maybe it's a bug with API from the car or API module.
Thanks!
I'd appreciate it if you'd test it with a custom script first. Adding those measurements just for debugging purposes is a bit too much :)
After multiple charging sessions I can confirm that the car reports correct values.
However, charge_energy_added is reset to 0 when you plug in. If you have multiple charging sessions before you unplug all the kWh added will add up to charge_energy_added. As a side note, the value of charge_energy_added is updated when charge_miles_added_rated is changing.
TeslaMate uses max(c.charge_energy_added) to store the Charges and obviously the max value is actually the total value of charge_energy_added since plug in as you can see below.

The only interesting data with that session is that because the temperature outside dropped, charge_miles_added_rated was lowered as well hence charge_energy_added lost 0.52 kWh. This would indicate that charge_energy_added is an estimated value by the BMS and not actually counted by the cars charger.
So I see two possible way to solve this:

Hope this helps.
Thanks!
Best regards,
Mihai
Thanks, this helps a lot! I'll implement your recommended fix to calculate the charge_energy_added.
Brilliant! It works beautifully.
10:49:54.241 car_id=1 [info] Start / :online
10:51:12.069 car_id=1 [info] Charging / SOC: 80%
11:01:27.577 car_id=1 [info] Charging / Stopped / 1.0500000000000007 kWh – 10 min
11:01:27.577 car_id=1 [info] Start / :online

Thanks!
Cool!
Can update the previous charge sessions if you want to:
Manually look up the ids of the respective "charing_processes" in the database
connect to your running TeslaMate instance:
docker exec -it teslamate bin/teslamate remote
ids = [1, 2] # insert the ids here
for id <- ids do
{:ok, cproc} = TeslaMate.Log.complete_charging_process(id)
%{end_date: end_date} =
Charge
|> select([c], %{end_date: max(c.date)})
|> where(charging_process_id: ^id)
|> Repo.one()
{:ok, _} =
cproc
|> ChargingProcess.changeset(%{end_date: end_date})
|> Repo.update()
end