MattJeanes / TeslaMateAgile

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

Personalised prices #16

Closed cyrillopez closed 3 years ago

cyrillopez commented 3 years ago

Hi Is it a way to define personalised prices for differents periods ? I don't have Octopus Energy or Tibber provider but a french provider with differents prices according to hours Between 8.00 am and 11.00pm 0,1799 Between 11.00 pm and 2.00 am 0,1346 Between 2.00 am and 6.00 am 0,1095 Between 6.00 am and 8.00 am 0,1346 It seems that it is not possible to define other provider than the two you set Thanks

MattJeanes commented 3 years ago

Hey just to let you know I'm working on this at the moment, I've done the core implementation now but I need to handle time zones properly which could be tricky! I'll let you know when I have something for you to test, hopefully soon 😄

MattJeanes commented 3 years ago

@cyrillopez this is ready for testing now - can you please give it a go and make sure it works well for you? It's in a RC release right now, you can pull it from docker with the tag v1.5.0-rc.2 or get it from GitHub releases.

Check the updated README on this project for usage instructions, it is the new FixedPrice provider. Hope it works well!

cyrillopez commented 3 years ago

@MattJeanes thanks a lot for the update I just install it I will keep you update

cyrillopez commented 3 years ago

Hi @MattJeanes

I have an error Here is my config and log

teslamateagile: image: mattjeanes/teslamateagile:v1.5.0-rc.2 restart: always environment:

  • DATABASE_USER=teslamate
  • DATABASE_PASS=secret
  • DATABASE_NAME=teslamate
  • DATABASE_HOST=database
  • TeslaMate__UpdateIntervalSeconds=300
  • TeslaMate__GeofenceId=1
  • TeslaMate__EnergyProvider=FixedPrice
  • FixedPrice__TimeZone="Europe/Paris" # Sets timezone to resolve the times below in
  • FixedPricePrices0="08:00-23:00=0.1799" # You can have as many as these as you need
  • FixedPricePrices1="23:00-02:00=0.1346"
  • FixedPricePrices3="02:00-06:00=0.1095"
  • FixedPricePrices2="06:00-08:00=0.1346"
  • LoggingLogLevelDefault=Debug # Enables debug logging, useful for seeing exactly how a charge was calculated

info: TeslaMateAgile.PriceService[0]
Price service is starting
info: TeslaMateAgile.PriceService[0]
Using energy provider FixedPrice
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
dbug: TeslaMateAgile.PriceService[0]
Updating prices
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app/
fail: TeslaMateAgile.PriceService[0]
Failed to update prices
System.ArgumentException: value (Parameter 'Failed to parse fixed price value: 0.1095"')
at TeslaMateAgile.Services.FixedPriceService.GetFixedPrices(FixedPriceOptions options) in /src/TeslaMateAgile/Services/FixedPriceService.cs:line 85
at TeslaMateAgile.Services.FixedPriceService..ctor(IOptions1 options) in /src/TeslaMateAgile/Services/FixedPriceService.cs:line 22 at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.b__0(ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at TeslaMateAgile.PriceService.DoWork() in /src/TeslaMateAgile/PriceService.cs:line 60
info: TeslaMateAgile.PriceService[0]
Waiting 300 seconds until next update

MattJeanes commented 3 years ago

Interesting, try removing the double quote marks " from the new environment variables and make sure the sequence is linear, it currently goes 0,1,3,2 and it should go 0,1,2,3

cyrillopez commented 3 years ago

@MattJeanes Thanks, without quote it's ok For the sequence, it was just a test

1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 info: TeslaMateAgile.PriceService[0]
Price service is starting
info: TeslaMateAgile.PriceService[0]
Using energy provider FixedPrice
dbug: TeslaMateAgile.PriceService[0]
Updating prices
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app/
info: TeslaMateAgile.PriceHelper[0]
Updating prices
info: TeslaMateAgile.PriceHelper[0]
No new charging processes
dbug: TeslaMateAgile.PriceService[0]
Price update complete
info: TeslaMateAgile.PriceService[0]
Waiting 300 seconds until next update

MattJeanes commented 3 years ago

Okay great, can you try it on some charges to make sure it is calculating values as you would expect? In the database you can set the cost column in charging_processes table to NULL for some particular charge records

There is some more information on how to reset charges here: https://github.com/MattJeanes/TeslaMateAgile#recalculating-charge-costs

cyrillopez commented 3 years ago

@MattJeanes It works well I have delete a cost on my test yesterday for 20 minutes between 2 period My last cost was 0.26€ et then 0.36€ with log bellow The last cost was calculated with only one price at 0.1095 for 2.34kw

Thanks a lot for this development

info: TeslaMateAgile.PriceHelper[0]
Calculating cost for charges 02/07/2021 21:50:46 UTC - 02/07/2021 22:10:24 UTC
dbug: TeslaMateAgile.PriceHelper[0]
Calculated charge cost for 02/07/2021 07:00:00 UTC - 02/07/2021 22:00:00 UTC (unit cost: 0.1799, fee per kWh: 0): 0.194303817431111107381984 for 1.08006568888888886816 energy
dbug: TeslaMateAgile.PriceHelper[0]
Calculated charge cost for 02/07/2021 22:00:00 UTC - 02/08/2021 01:00:00 UTC (unit cost: 0.1346, fee per kWh: 0): 0.169673637279999982426624 for 1.26057679999999986944 energy
info: TeslaMateAgile.PriceHelper[0]
Calculated cost 0.36 and energy 2.34 kWh for charging process 649

MattJeanes commented 3 years ago

That is fantastic to hear, I will close this issue once this release goes out properly (not in an RC)

I'm glad it is working well for you

cyrillopez commented 3 years ago

@MattJeanes I have delete all cost since few days to force all new costs But some of them have an error

TeslaMateAgile.PriceHelper[0]
Calculating cost for charges 01/26/2021 00:39:45 UTC - 01/26/2021 04:14:30 UTC
dbug: TeslaMateAgile.PriceHelper[0]
Calculated charge cost for 01/25/2021 22:00:00 UTC - 01/26/2021 01:00:00 UTC (unit cost: 0.1346, fee per kWh: 0): 0.257886830741666652017700 for 1.91594970833333322450 energy
fail: TeslaMateAgile.PriceHelper[0]
Failed to calculate charging cost / energy for charging process 631
System.Exception: Charge calculation failed, pricing calculated for 60 / 628, likely missing price data
at TeslaMateAgile.PriceHelper.CalculateChargeCost(IEnumerable`1 charges)
at TeslaMateAgile.PriceHelper.Update() in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 54

Here is my last config active

  • FixedPricePrices0=08:00-23:00=0.1799 # You can have as many as these as you need
  • FixedPricePrices1=23:00-02:00=0.1346
  • FixedPricePrices2=02:00-06:00=0.1095
  • FixedPricePrices3=06:00-08:00=0.1346

The error seems to have impact pass between sequence 1 and 2 (i have time code from Paris so UTC +1)

MattJeanes commented 3 years ago

Oops, you're absolutely right! I thought I was testing for this scenario but apparently not 😢

I have now fixed this and published v1.5.0-rc.3 - can you give it a go with this one and see if it works? Thank you

cyrillopez commented 3 years ago

@MattJeanes Thanks the 3 cost which were blocked have been well updated now Thanks again

MattJeanes commented 3 years ago

Perfect! Thank you for testing it

MattJeanes commented 3 years ago

This has now been released as v1.5.0