Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Fixed Pricing Based on Day of Week #51

Closed
jakest opened this issue Feb 10, 2024 · 23 comments
Closed

Feature Request: Fixed Pricing Based on Day of Week #51

jakest opened this issue Feb 10, 2024 · 23 comments
Labels
help wanted Extra attention is needed

Comments

@jakest
Copy link

jakest commented Feb 10, 2024

My power plan is as follows:

Monday - Friday

  • 00:00-08:00 low tier
  • 08:00-10:00 high tier
  • 10:00-15:00 low tier
  • 15:00-20:00 high tier
  • 20:00-00:00 low tier

Saturday - Sunday

  • 00:00 - 23:59 low tier

When I charge during the weekend, the costs are calculated at a high tier rate if charging during one of the high tier times (only applicable on weekdays) as TeslaMateAgile can’t currently be setup with pricing tiers dependent upon the day of the week.

It would be amazing to be able to set up Fixed Pricing based on the day of the week to account for that.

@MattJeanes
Copy link
Owner

Hello! Is this quite a common thing to have it vary across different days of the week? I've heard of it varying across the year before e.g. summer and winter pricing but not really across a week before.

If you have Home Assistant I'd recommend using that to set your prices as dynamically as you like, details in the readme of how to do that. If not, I could try to add something for this but I'm not sure when I'll be able to get around to it. Contributions welcome of course!

@jakest
Copy link
Author

jakest commented Feb 10, 2024 via email

@MattJeanes MattJeanes added the help wanted Extra attention is needed label Feb 25, 2024
@jfg31113
Copy link

jfg31113 commented Nov 1, 2024

Here in Spain we also have diferent plans for weekdays and weekends:

Monday - Friday

00:00-08:00 low tier
08:00-10:00 mid tier
10:00-14:00 high tier
14:00-18:00 mid tier
18::00-22:00 high tier
22:00-00:00 mid tier

Saturday - Sunday

00:00 - 23:59 low tier

@MattJeanes
Copy link
Owner

MattJeanes commented Nov 5, 2024

Hey @jakest / @jfg31113 - I have made a first version of this and I would love if you could help me test it.

I've just released test version v1.17.0-rc.1 which contains a new FixedPriceWeekly provider which should do what you want.

I have tested various different scenarios but I can't promise that it'll work perfectly, so I invite you to give it a go and try and break it, and most importantly let me know what you think!

See the documentation for how to configure the new provider.

@jakest
Copy link
Author

jakest commented Nov 5, 2024 via email

@jakest
Copy link
Author

jakest commented Nov 5, 2024

@MattJeanes I'm getting the following log error with the following config.
teslamate-teslamateagile-1.csv

System.ArgumentException: price (Parameter 'Failed to parse fixed price: Sat-Sun=0.052004')

    image: mattjeanes/teslamateagile:latest
    restart: always
    environment:
      - DATABASE_USER=XXXX
      - DATABASE_PASS=XXXX
      - DATABASE_NAME=XXXX
      - DATABASE_HOST=XXXX
      - TeslaMate__UpdateIntervalSeconds=3600
      - TeslaMate__GeofenceId=1
      - TeslaMate__EnergyProvider=FixedPrice
      - FixedPrice__TimeZone=America/Denver
      - FixedPrice__Prices__0=Mon-Fri=00:00-08:00=0.052004
      - FixedPrice__Prices__1=Mon-Fri=08:00-10:00=0.253532
      - FixedPrice__Prices__2=Mon-Fri=10:00-15:00=0.052004
      - FixedPrice__Prices__3=Mon-Fri=15:00-20:00=0.253532
      - FixedPrice__Prices__4=Mon-Fri=20:00-00:00=0.052004
      - FixedPrice__Prices__5=Sat,Sun=0.052004

I've tried Sat-Sun as well. I've also tried Sat-Sun=00:00-00:00=0.052004. What should I be using for the same price the full weekend?

EDIT: Looks like whatever I do, it thinks there's a gap between Price 4 and Price 5 going from Friday - Saturday.

@MattJeanes
Copy link
Owner

Ah I see, make sure you are using the new FixedPriceWeekly in the TeslaMate__EnergyProvider setting 😄

@MattJeanes
Copy link
Owner

Oh, and all of the settings should be prefixed with FixedPriceWeekly instead of FixedPrice e.g.

      - TeslaMate__EnergyProvider=FixedPriceWeekly
      - FixedPriceWeekly__TimeZone=America/Denver
      - FixedPriceWeekly__Prices__0=Mon-Fri=00:00-08:00=0.052004
      - FixedPriceWeekly__Prices__1=Mon-Fri=08:00-10:00=0.253532
      - FixedPriceWeekly__Prices__2=Mon-Fri=10:00-15:00=0.052004
      - FixedPriceWeekly__Prices__3=Mon-Fri=15:00-20:00=0.253532
      - FixedPriceWeekly__Prices__4=Mon-Fri=20:00-00:00=0.052004
      - FixedPriceWeekly__Prices__5=Sat,Sun=0.052004

Apologies I needed to make it a brand new provider rather than extending the existing one hence the changes.

@jakest
Copy link
Author

jakest commented Nov 5, 2024

EDIT: Still failing with the following.

2024/11/05 14:04:20	stderr	 ---> System.ArgumentException: Requested value 'FixedPriceWeekly' was not found.
2024/11/05 14:04:20	stderr	 ---> System.FormatException: FixedPriceWeekly is not a valid value for EnergyProvider. 

Looks like I'm getting a new error now that is preventing the container from starting with this config.

  teslamateagile:
    image: mattjeanes/teslamateagile:latest
    restart: always
    environment:
      - DATABASE_USER=XXXX
      - DATABASE_PASS=XXXX
      - DATABASE_NAME=XXXX
      - DATABASE_HOST=XXXX
      - TeslaMate__UpdateIntervalSeconds=3600
      - TeslaMate__GeofenceId=1
      - TeslaMate__EnergyProvider=FixedPriceWeekly
      - FixedPriceWeekly__TimeZone=America/Denver
      - FixedPriceWeekly__Prices__0=Mon-Fri=00:00-08:00=0.052004
      - FixedPriceWeekly__Prices__1=Mon-Fri=08:00-10:00=0.253532
      - FixedPriceWeekly__Prices__2=Mon-Fri=10:00-15:00=0.052004
      - FixedPriceWeekly__Prices__3=Mon-Fri=15:00-20:00=0.253532
      - FixedPriceWeekly__Prices__4=Mon-Fri=20:00-00:00=0.052004
      - FixedPriceWeekly__Prices__5=Sat-Sun=0.052004

teslamate-teslamateagile-1(3).csv

@MattJeanes
Copy link
Owner

Ah I didn't notice from your previous config but you will need to explicitly use the preview version as latest won't get you the preview ones 🙂

image: mattjeanes/teslamateagile:latest -> image: mattjeanes/teslamateagile:v1.17.0-rc.1

@jakest
Copy link
Author

jakest commented Nov 5, 2024

I totally missed that, my fault. Was going to look at the SHA hash, then got busy with work. Looks like we had our first run! Looks like I only have one error now.

date	stream	content
2024/11/05 15:22:32	stdout	      Waiting 3600 seconds until next update
2024/11/05 15:22:32	stdout	info: TeslaMateAgile.PriceService[0]
2024/11/05 15:22:32	stdout	         at TeslaMateAgile.PriceHelper.Update() in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 75
2024/11/05 15:22:32	stdout	         at TeslaMateAgile.PriceHelper.CalculateChargeCost(IEnumerable`1 charges) in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 98
2024/11/05 15:22:32	stdout	         at TeslaMateAgile.PriceHelper.CalculateDynamicChargeCost(IEnumerable`1 charges, DateTimeOffset minDate, DateTimeOffset maxDate) in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 108
2024/11/05 15:22:32	stdout	         at TeslaMateAgile.Services.FixedPriceWeeklyService.GetPriceData(DateTimeOffset from, DateTimeOffset to) in /src/TeslaMateAgile/Services/FixedPriceWeeklyService.cs:line 36
2024/11/05 15:22:32	stdout	         at TeslaMateAgile.Services.FixedPriceWeeklyService.GetPriceDataForDate(DateTime date) in /src/TeslaMateAgile/Services/FixedPriceWeeklyService.cs:line 124
2024/11/05 15:22:32	stdout	      System.Exception: Invalid fixed price data, prices are not continuous
2024/11/05 15:22:32	stdout	      Failed to calculate charging cost / energy for charging process 2610
2024/11/05 15:22:32	stdout	fail: TeslaMateAgile.PriceHelper[0]
2024/11/05 15:22:32	stdout	      Calculating cost for charges 11/05/2024 19:15:12 UTC - 11/05/2024 20:50:33 UTC
2024/11/05 15:22:32	stdout	info: TeslaMateAgile.PriceHelper[0]
2024/11/05 15:22:31	stdout	      Looking for finished charging processes with no cost set in the 'Home' geofence (id: 1)
2024/11/05 15:22:31	stdout	info: TeslaMateAgile.PriceHelper[0]
2024/11/05 15:22:26	stdout	      Content root path: /app/
2024/11/05 15:22:26	stdout	info: Microsoft.Hosting.Lifetime[0]
2024/11/05 15:22:26	stdout	      Hosting environment: Production
2024/11/05 15:22:26	stdout	info: Microsoft.Hosting.Lifetime[0]
2024/11/05 15:22:26	stdout	      Application started. Press Ctrl+C to shut down.
2024/11/05 15:22:26	stdout	info: Microsoft.Hosting.Lifetime[0]
2024/11/05 15:22:26	stdout	      Using energy provider FixedPriceWeekly
2024/11/05 15:22:26	stdout	info: TeslaMateAgile.PriceService[0]
2024/11/05 15:22:26	stdout	      Price service is starting
2024/11/05 15:22:26	stdout	info: TeslaMateAgile.PriceService[0] 

It failed on the latest charge for some reason. Feels like we're so close.

2024-11-05_15-27-04

@jakest
Copy link
Author

jakest commented Nov 5, 2024

Actually, I just deleted a few more costs to see if it would update any of them. It looks like it's failing to update any entries that don't have a cost associated yet.

@MattJeanes
Copy link
Owner

Thanks, looking into that now - I can reproduce the error locally. It's erroring as part of a self-check in the internal part of the code, nothing wrong on your side this time!

@MattJeanes
Copy link
Owner

Okay, fixed! Looks like if your one of your time ranges crosses over exactly midnight it breaks! Please try the new version v1.17.0-rc.2 which resolves this problem.

image: mattjeanes/teslamateagile:v1.17.0-rc.2

@jakest
Copy link
Author

jakest commented Nov 5, 2024

Look at that! The one I didn't have a price for succeeded. The one I deleted the pricing information for manually is still failing, but since I only deleted it to test, it's likely not an edge case worth fixing. But just in case, here are the logs for that one.

2024/11/05 15:51:41	stdout	info: TeslaMateAgile.PriceHelper[0]
2024/11/05 15:51:41	stdout	         at TeslaMateAgile.PriceHelper.Update() in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 75
2024/11/05 15:51:41	stdout	         at TeslaMateAgile.PriceHelper.CalculateChargeCost(IEnumerable`1 charges) in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 98
2024/11/05 15:51:41	stdout	         at TeslaMateAgile.PriceHelper.CalculateDynamicChargeCost(IEnumerable`1 charges, DateTimeOffset minDate, DateTimeOffset maxDate) in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 151
2024/11/05 15:51:41	stdout	      System.Exception: Charge calculation failed, pricing calculated for 0 / 54, likely missing price data
2024/11/05 15:51:41	stdout	      Failed to calculate charging cost / energy for charging process 2607
2024/11/05 15:51:41	stdout	fail: TeslaMateAgile.PriceHelper[0]
2024/11/05 15:51:41	stdout	      Calculating cost for charges 11/04/2024 01:22:55 UTC - 11/04/2024 01:40:58 UTC 

By the way, do you have a way to accept donations? I really appreciate your help with this!

@MattJeanes
Copy link
Owner

Thank you, that is another useful test case too. Apologies, this new provider is rather complex in it's logic so trying to squash as many bugs as I can in it before releasing it to everyone. I can reproduce this issue as well, investigating now!

@MattJeanes
Copy link
Owner

Okay, fixed that problem too. That one was caused by the timezone jumping into the previous day (relative to UTC) and not correctly retrieving the prices for the previous date. I love timezones 😁

The new version v1.17.0-rc.3 should fix this problem!

image: mattjeanes/teslamateagile:v1.17.0-rc.3

As for donations, I've also just set up GitHub Sponsors if you want to contribute anything! I don't ask for donations and I do this work for free to give back to the community, but if you did want to I would appreciate your support a lot 😊

You can access GitHub Sponsors on the TeslaMateAgile repository main page or on my GitHub profile page, there should be a 'Sponsor' button there now.

@jakest
Copy link
Author

jakest commented Nov 5, 2024

I didn't even consider that. Good find! That resolved the issue. I'll let you know if I see anything else over the next few weeks.

Thanks again for adding this!

@MattJeanes
Copy link
Owner

Awesome, yes please keep me posted if anything is acting weird or erroring I would love to hear about it.

Keep in mind that even if it works there's a chance the calculated cost might be wrong if my calculations are wrong, which is definitely a possibility 👀 so if anything looks weird or doesn't seem to add up please shout!

You're welcome, and thank you also for helping me test it, real world test scenarios are so much more useful than my fake ones I made for testing which already missed a couple of real issues as we found out 😁

I've also just seen your donation, thank you very much!! It means a lot that you value my work enough to do that ❤️

@MattJeanes
Copy link
Owner

Hey @jakest - how's it been going? All good still or seeing any issues?

@jakest
Copy link
Author

jakest commented Nov 16, 2024 via email

@MattJeanes
Copy link
Owner

Awesome! Thank you for testing that out - let me know if you spot anything in future of course!

I'll keep this issue open until I push the release out properly, just waiting on some feedback on a different change in this update first 🙂

@MattJeanes
Copy link
Owner

This has now been released in version v1.17.0 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants