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

Tibber "Failed to calculate charging cost" #50

Closed isondre closed 5 months ago

isondre commented 5 months ago

Tibbers API didn't like me trying to calculate prices of my over 1000 charges in one go. Is there a way to do it in batches?

info: TeslaMateAgile.PriceHelper[0]

  Calculating cost for charges 12/29/2023 08:08:10 UTC - 12/29/2023 08:08:37 UTC

fail: TeslaMateAgile.PriceHelper[0]

  Failed to calculate charging cost / energy for charging process 1226

  GraphQL.Client.Http.GraphQLHttpRequestException: The HTTP request failed with status code TooManyRequests

     at TeslaMateAgile.Services.TibberService.SendRequest(GraphQLHttpRequest request) in /src/TeslaMateAgile/Services/TibberService.cs:line 139

     at TeslaMateAgile.Services.TibberService.GetPriceData(DateTimeOffset from, DateTimeOffset to) in /src/TeslaMateAgile/Services/TibberService.cs:line 67

     at TeslaMateAgile.PriceHelper.CalculateChargeCost(IEnumerable`1 charges) in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 96

     at TeslaMateAgile.PriceHelper.Update() in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 74
MattJeanes commented 5 months ago

Hey, for this I would recommend temporarily setting the cost for to something other than null in the charging_processes table in the database directly for most of them, and nulling them out slowly over time to let TeslaMateAgile pick them up.

Maybe use some very weird or specific number so you don't confuse it with the real ones!

isondre commented 5 months ago

Any tips to automate this? I don't really feel like sitting nulling out charges over the next few days.

MattJeanes commented 5 months ago

Yeah, you could use psql to run a query (psuedo-code) similar to:

UPDATE charging_processes SET cost=NULL WHERE id IN (SELECT id FROM charging_processes WHERE cost = 12345 limit 1)

And have that on some kind of scheduled task / cronjob, make sure to adjust cost / limit as necessary.

isondre commented 5 months ago

Thank you. I have now changed all entries with NULL to another price that won't interfere with actual prices.

I now only have two entries with NULL and tried starting Agile again.

`info: TeslaMateAgile.PriceHelper[0]

  Calculating cost for charges 10/05/2023 17:15:24 UTC - 10/05/2023 17:18:53 UTC

fail: TeslaMateAgile.PriceHelper[0]

  Failed to calculate charging cost / energy for charging process 1170

  GraphQL.Client.Http.GraphQLHttpRequestException: The HTTP request failed with status code BadRequest

     at TeslaMateAgile.Services.TibberService.SendRequest(GraphQLHttpRequest request) in /src/TeslaMateAgile/Services/TibberService.cs:line 139

     at TeslaMateAgile.Services.TibberService.GetPriceData(DateTimeOffset from, DateTimeOffset to) in /src/TeslaMateAgile/Services/TibberService.cs:line 67

     at TeslaMateAgile.PriceHelper.CalculateChargeCost(IEnumerable`1 charges) in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 96

     at TeslaMateAgile.PriceHelper.Update() in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 74

info: TeslaMateAgile.PriceHelper[0]

  Calculating cost for charges 12/29/2023 08:08:10 UTC - 12/29/2023 08:08:37 UTC

fail: TeslaMateAgile.PriceHelper[0]

  Failed to calculate charging cost / energy for charging process 1226

  GraphQL.Client.Http.GraphQLHttpRequestException: The HTTP request failed with status code BadRequest

     at TeslaMateAgile.Services.TibberService.SendRequest(GraphQLHttpRequest request) in /src/TeslaMateAgile/Services/TibberService.cs:line 139

     at TeslaMateAgile.Services.TibberService.GetPriceData(DateTimeOffset from, DateTimeOffset to) in /src/TeslaMateAgile/Services/TibberService.cs:line 67

     at TeslaMateAgile.PriceHelper.CalculateChargeCost(IEnumerable`1 charges) in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 96

     at TeslaMateAgile.PriceHelper.Update() in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 74

info: TeslaMateAgile.PriceService[0]

  Waiting 300 seconds until next update`

I have tried accessing Tibber API with no issues, so it is not a soft ban like last night.

MattJeanes commented 5 months ago

Hmm... it's possible that you may be requesting a time too far in the past and the API doesn't like it, maybe try a more recent one or try those dates manually in the API and see what it does.

isondre commented 5 months ago

Okay, will give that a try. Seems weird though, since it had no problem collecting cost from 2021-2023 last night.

isondre commented 5 months ago

Thanks for the help!

Found the culprit, it was user error. I forgot to update the API token in the compose file after making a new one in Tibber last night.. Everything is working fine now.

You at least helped me slow down the requests! 😄

MattJeanes commented 5 months ago

Glad I could be of (some) assistance 🙂