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

Support for Awattar #19

Closed nottheedge closed 3 years ago

nottheedge commented 3 years ago

Hi,

I just found your plugin for Teslamate and it's exactly what I'd need for my installation - if it would support Awattar (https://www.awattar.de/services/api) as there is also an API available. Could you implement it, too?

Thanks, Joerg

MattJeanes commented 3 years ago

Hi @nottheedge, it looks to be a fairly simple API to use and implement, I've added in the API quickly and published a pre-release version for your testing to see if it's working as you expect.

I anticipate there will be a problem with VAT as the API does not include prices with VAT. Is this something that you would require?

If so, what is the VAT calculation for electricity in the region this energy provider operates in, presumably Germany only?

You can access the pre-release version with docker tag v1.7.0-rc.2

(edit: just updated to rc.2 to fix a bug around not getting all the required price data)

Refer to the guide in the README on how to force TeslaMateAgile to recalculate charges for testing.

Let me know if you run into any troubles. This looks to hopefully be a quick win 😄

MattJeanes commented 3 years ago

Hey @nottheedge - just checking in, did you manage to try this out? I am waiting on your feedback before releasing this properly to make sure it's all good 😄

nottheedge commented 3 years ago

My apologies I didn’t recognise that you send me a message 6 days ago. Will have a look next days.

MattJeanes commented 3 years ago

No worries, cheers!

nottheedge commented 3 years ago

I got it installed but I assume I can't recalculate charges at my home as the prices per hour are only valid for next 24h. A backward calculation is impossible. My car is plugged in and it will charge tomorrow 2-4am for (7,5ct at 2am, 7,35ct at 3am and 7,45ct at 4am). Let see what's gonna happen.

Related to your question about VAT calculation you only need to multiply with 1,19 as we have 19% per kWh. Probably you could set it as parameter inside docker-compose to be flexible?

Regards, Joerg

MattJeanes commented 3 years ago

Hey @nottheedge, just checking in again to see if you managed to give it a go?

Thanks for the info about VAT, I'll add an option specifically for this provider which has a default VAT rate of 19% if not set but you will be able to override it. This is because the other providers automatically include VAT in their prices so it is not something we need to worry about and it may confuse users if we add an option to add VAT to Octopus Agile prices when they are already included for example.

Hopefully everything (other than the lack of VAT) is working correctly for you?

MattJeanes commented 3 years ago

I have now pushed a new release candidate v1.7.0-rc.4 with the the VAT multiplier option added, it is Awattar__VATMultiplier and it is set by default to 1.19 so you shouldn't generally need to set it at all unless you claim the VAT back or something but it's there just in case.

Could you please try out this new version and make sure everything is nice and happy and then we can properly release v1.7.0 😄

nottheedge commented 3 years ago

So far it looks good. As I charge the car over several hours there are different prices each hour. How do you cumulate it? Is there kind of database which stores the prices if charging is in progress? It's just to check if it cumulates correctly.

MattJeanes commented 3 years ago

Yeah so it's actually pretty complicated but essentially TeslaMate samples the current charging state during a charge every 5 seconds or so so we know at any particular point how much power was being drawn and can calculate it over a particular datetime range, which TeslaMateAgile uses to calculate for each price from the aWATTar API relevant to your charging session.

You can calculate it roughly by knowing your normal charge rate (e.g. 7.2kW) and multiplying it by the current cost per hour divided by how much of that hour it was charging

So for example if your charge was from 00:30 to 02:00 and it was 5p/kWh for 00:00-01:00 and 10p/kWh for 01:00-02:00 and you were charging at 7kW: For the first hour you'd basically go 7/60*30=3.5kWh then 5p*3.5kWh=17.5p for the first hour, then for the second hour that would be 7/60*60=7kWh as its a full hour and then 10p*7kWh=70p and then just add them together to get a rough charge cost of 87.5p

This is essentially how TeslaMateAgile calculates it but on a much smaller timestep for more accuracy so if you compare the two outputs it should be within a few pennies (or cent or whatever)

Hope that makes sense!

MattJeanes commented 3 years ago

v1.7.0 has now been released with aWATTar support, so I will close this. If there are any issues with the implementation please raise a new issue! Cheers