MattJeanes / TeslaMateAgile

Integration to automatically fill in prices for charge data captured by TeslaMate for smart energy providers
MIT License
76 stars 9 forks source link

3 Phase 230V calculations are wrong #17

Closed Dezzorex closed 3 years ago

Dezzorex commented 3 years ago

I just got installed a 3 Phase IT charger for my Tesla Model 3. It is charging at 230V 11.4kW, but if I set phases to 3 in the config, it calculates wrong. I Suspect calculations are for 3 phase 400V TN which is common in europe, but in norway we have 230V IT (only Norway and Albania I believe have this, newer areas in Norway do have 400V though). This causes it to calculate wrong amount of kW and therefor also wrong usage. If I take the calulated amount for 3 phase, and divide it by 1,73 (difference between 400/230), it results in more accurate number compared to TeslaMate. Basically all calculations here will be wrong on IT network with 3 phase.

Would it be possible to add calculations/and config for 230V?

Example from calculations based on 1-2-3 phase:

1 Phase:

  Calculating cost for charges 02/03/2021 00:03:03 UTC - 02/03/2021 04:21:30 UTC
  Calculated cost 13.68 and energy 27.51 kWh for charging process 57
  Mismatch between TeslaMate calculated energy used of 47.65 and ours of 27.51

2-Phase:

  Calculating cost for charges 02/03/2021 00:03:03 UTC - 02/03/2021 04:21:30 UTC
  Calculated cost 27.36 and energy 55.02 kWh for charging process 57
  Mismatch between TeslaMate calculated energy used of 47.65 and ours of 55.02

3-Phase:

  Calculating cost for charges 02/03/2021 00:03:03 UTC - 02/03/2021 04:21:30 UTC
  Calculated cost 41.04 and energy 82.53 kWh for charging process 57
  Mismatch between TeslaMate calculated energy used of 47.65 and ours of 82.53
MattJeanes commented 3 years ago

I suspected the 3-phase support would be a bit off, unfortunately I was unable to test it! Could you if possible provide an export of a 3-phase charge from the charges and charging_process table? I see how TeslaMate is calculating it and performing voltage correction but I was never able to implement it without access to some test data.

If you're not sure how to export data, try using pgAdmin and essentially doing this: image image

There is no sensitive data like location in these tables, that is stored elsewhere so this is fine to export but please review the exported data yourself just to make sure

Dezzorex commented 3 years ago

Added results in uploaded zip (in CSV format)

Charge.zip

MattJeanes commented 3 years ago

That's perfect thank you, I'll take a look into this now - do you mind if I commit a version of this to the project as part of a unit test?

MattJeanes commented 3 years ago

I've implemented the phase calculation as per TeslaMate itself now, can you try the new RC version v1.5.0-rc.1? you can remove the TeslaMate__Phases environment variable too now as it is no longer required.

It calculates the same energy usage as TeslaMate itself now for your example you sent me, so can you give it a go and see if it's working well for you? Set the costs in the database to NULL to get TeslaMateAgile to calculate them again.

If all goes well I'll publish it properly :)

Dezzorex commented 3 years ago

Fantastic, but how do I install the pre-release version via docker?

MattJeanes commented 3 years ago

Use the tag v1.5.0-rc.1 on docker

Dezzorex commented 3 years ago

Thanks, seems to work on the main charges now, but getting 0 amount on short charges now, so might be a bug there?

info: TeslaMateAgile.PriceHelper[0] Calculated cost 0 and energy 0 kWh for charging process 63

image

MattJeanes commented 3 years ago

Yeah it's kind of intentional, TeslaMate should do the same thing with the energy used column I believe? It requires a minimum data set to accurately calculate phases. If you see - in 'Used' on the Charges page in Grafana it means TeslaMate has had the same issue while calculating energy usage. I could lower the threshold but I want to keep the behaviour identical to TeslaMate if posible.

MattJeanes commented 3 years ago

I have now released this as v1.5.0 - if the short charges is causing you an issue please raise a new issue and we can work something out.