MattJeanes / TeslaMateAgile

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

Very short top-up charges don't get costed. #29

Closed gandm closed 1 year ago

gandm commented 2 years ago

I have quite a number of charges that are 2-3mins long. The car is just topping up every now and again. These show with a cost of charge 0.00. I get messages in the log for these short duration charges like this:-

  warn:_ TeslaMateAgile.PriceHelper[0] Unable to determine phases for charges
  info: TeslaMateAgile.PriceHelper[0]  Calculated cost 0 and energy 0 kWh for charging process 26

Note the phase warning.

It appears to be caused by this line in your code:

which appears to check there are at least 15 charge rows for any particular charge id otherwise it returns null. The charges with no cost have less than this amount therefore it doesn't calculate the charge cost and generates an error with the erroneous phase message.

MattJeanes commented 2 years ago

Yeah so this is also a limitation in TeslaMate itself as the code is pretty much ported directly from there, A possible way to work around this would be to provide a way to manually specify the amount of phases in the config, then it will calculate them for everything hopefully. Will keep this issue open to track implementation of this, and also open to any suggestions for better ways to do it.

erlingjd commented 1 year ago

I have a similar issue with longer charges not able to determine phases:

2023-04-11 07:06:25.251 info: TeslaMateAgile.PriceHelper[0] Looking for finished charging processes with no cost set in the 'Hjemme' geofence (id: 1) 2023-04-11 07:06:25.294 info: TeslaMateAgile.PriceHelper[0] Calculating cost for charges 04/10/2023 22:05:23 UTC - 04/11/2023 03:17:55 UTC 2023-04-11 07:06:25.714 warn: TeslaMateAgile.PriceHelper[0] Unable to determine phases for charges 2023-04-11 07:06:25.714 info: TeslaMateAgile.PriceHelper[0] Calculated cost 0 and energy 0 kWh for charging process 468

But sometimes it works and I haven't figured out why:

2023-04-10 14:06:23.316 info: TeslaMateAgile.PriceHelper[0] Calculating cost for charges 04/10/2023 09:32:11 UTC - 04/10/2023 12:01:17 UTC 2023-04-10 14:06:23.756 info: TeslaMateAgile.PriceHelper[0] Phase correction: 2 -> 3 2023-04-10 14:06:23.765 info: TeslaMateAgile.PriceHelper[0] Calculated cost 6.68 and energy 9.81 kWh for charging process 466

Any suggestions?

erlingjd commented 1 year ago

I also have this error from the Tibber API sometimes:

2023-04-11 06:06:25.227 info: TeslaMateAgile.PriceHelper[0] Calculating cost for charges 04/10/2023 22:05:23 UTC - 04/11/2023 03:17:55 UTC 2023-04-11 06:06:26.091 fail: TeslaMateAgile.PriceHelper[0] Failed to calculate charging cost / energy for charging process 468 System.Exception: Mismatch of requested price info from Tibber API (expected: 7, actual: 6) at TeslaMateAgile.Services.TibberService.GetPriceData(DateTimeOffset from, DateTimeOffset to) in /src/TeslaMateAgile/Services/TibberService.cs:line 105 at TeslaMateAgile.PriceHelper.CalculateChargeCost(IEnumerable`1 charges) in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 86 at TeslaMateAgile.PriceHelper.Update() in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 79

If these happen, they are OK the next time TeslaMateAgile is Looking for finished charging processes with no cost set and doesn't seem to affect the error in my previous post

MattJeanes commented 1 year ago

v1.12.0 is now released with a new TeslaMate__Phases setting which will allow these short charges to be calculated 🙂

erlingjd commented 8 months ago

Thank you! All short charges are now calculated