-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[aWATTar] Schedule API update more than once per day #17068
[aWATTar] Schedule API update more than once per day #17068
Conversation
b9eec9d
to
f7871a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, would be nice if @Wolfgang1966 can confirm.
@tl-photography - after reading the issue you are trying to solve, I have a few questions: Is it correct that the service provided some false values? And to resolve that you want to call more frequently? Besides this I would assume that prices are usually fixed once received? |
The price that got retrieved at 1500 where correct at this time. But approximately 10 minutes later, new prices had been announced. It seems it 99% of the time ok to check only once a day. I only fix the other 1%. :) |
So it's not that prices were wrong, but expected day-ahead prices were missing? If this is the case, perhaps the binding should keep polling only when prices are missing? I don't know the details of the binding, but I know the domain from working on the Energi Data Service binding. |
The price where not missing, the API did return data that was available at the time. The issue is that the price data then was updated and the plugin would not contact the API again. In fact, the schedule of the plugin is to contact the API once a day at 1500. Data was available then and also shown in OpenHAB. At 1508, the prices got updated and the plugin would not schedule an update of it, since it already had data available. |
So going back to one of my first questions again:
Why were the prices updated, are they not supposed to be fixed once published? |
You're probably asking the wrong guy here. I'm not working for the EPEX. The only thing I know, they did change. Besides, what are we discussing here? Is there anything wrong with checking three times instead of once? |
I tried to find the historical data, but it seems they are not publicly available for longer than 3 days. But judging from the page https://www.epexspot.com/en/market-data delays in the published data or updates to them are not uncommon. Looking back to the issues they had, I could imagine that the data got published and then updated later on. This then probably got reflected in the awattar API as well. Since the API allows up to 100 updates per day, I would say checking the API 3 times is reasonable and would always have the correct data ready for the next day. |
I'm only asking some questions trying to obtain information that can possibly help me understand the problem being solved, because I think it is hard to assess a fix without really understanding the underlying problem. The point I'm unsuccessfully trying to make is that auctioned day-ahead electricity prices should be fixed (by contract), so they won't (should not) change. That's the point of the whole system. There might be changes in currency exchange rates, so if the obtained prices are not in EUR, there could be small adjustments, depending on how the service works. I fail to see how additional calls at arbitrary times will fix anything. And in that case, why only every three hours, and why stop at midnight? I guess the prices could still change? To summarize, you have stated:
Yet they were updated. How much did they change? If the changes were small, could currency exchange explain such small differences? |
IMO they were wrong, at least on 26/06/24. I guess that happened because EPEX didn't provide proper prices (due to their technical problem). If there are 100 free calls per day, why don't we call every hour? The result is cached anyway, so we can compare the newly retrieved data with the cached data and only refresh the child things when the data changed. |
OK, in that case I guess there is an assumption that prices are more likely to be correct the later they are published? Because otherwise fetching them more frequently could also lead to prices going from correct to wrong? If this assumption is indeed plausible, then I agree it will help to call more often, although it's a work-around for a broken service publishing wrong prices. 😕 |
The prices should indeed be agreed by 1230 CEST and awattar states the prices would be available "after 1400". They do not state a clear termination. Delays seem to happen more frequently von the EPEX, as can be seen in the link I posted, but are usually within the 1230 to 1400 window. The more recent prices are more "correct" since they are the agreed ones by the market. Too summarize: there is a termination, but it can be violated by the EPEX and therefore updates to the API data might happen. I guess we could also just retrieve the data once at 2300 and get the always the correct one, but as I already said, I think it's reasonable to poll the API three times after 1500. So we get the data as fast as possible and also would get the latest data, if updates did occur. |
Just to be clear, I did check the data during that day, when it was still available, and the service was not broken. It did reflect the prices that where announced by the EPEX at the time. Unfortunately, I did not make any screenshots. But in the linked issue there are two attached. |
The question is: what prices do they use when there is no price from EPEX? Or did EPEX provide a price and changed that one later? |
Unfortunately, the price difference was enormous. The usual price would be 0.15€/kWh, the updated prices, due to the software fault at the EPEX, where up to 2€/kWh. |
The EPEX did provide a price before 1500 and it got updated later, afaik. |
...awattar/src/main/java/org/openhab/binding/awattar/internal/handler/AwattarBridgeHandler.java
Show resolved
Hide resolved
Hi @tl-photography , first of all a great THANK YOU for addressing that issue. I noticed it when I was made aware of the very high hourly prices in the morning of that day and saw that the binding did not provide the correct values. But I did not dig deeper into the details. So, @jlaur , I can confirm that there indeed was a problem and the PR addresses it. I don't know the exact root cause why the aWATTar API provided wrong prices first, but I agree with @tl-photography that the EPEX spot system problem at that special day might have had something to do with it. About @J-N-K s idea to refresh every hour: I am also thinking about something like that now, but in the meantime I also started thinking about the binding from the API providers perspective. Currently there are hopefully only a few users of that binding, so the request peak every afternoon is acceptable hopefully. But the more users the binding gets, the higher the peak will become as clocks are synchronized very well nowadays. So from my point of view the price refresh should run at "random" times and decoupled from the thing refreshes, so that the load at the aWATTar API gets distributed over times and does not hit them in a sharp peak every hour. That goes beyond the scope of your change, but as you are currently dealing with the refresh anyway, how about addressing this potential problem also? An idea could be to refresh once with binding start and then compute a next refresh time as a random time between one and two hours in the future? And only if prices are not available after 14:00, compute a more frequent retry, but also only every few minutes? If you don't want to do this then it is also ok for me. In this case I may add this later after your PR is finalized and merged. One more remark: We should mention this more frequent price updates somewhere in the binding description as changed prices might lead to unforseeable changes in the BestPrice Thing calculations. Especially it might be that consecutive Things are not consecutive anymore after a recalculation, and non-consecutive things do not exactly stick to the configured timing. |
This sounds like premature optimizations. Any provider of such API is (or should be) aware of these foreseeable spikes in traffic and take measures accordingly. |
Sure! For the avoidance of doubt: My concerns have been addressed, since in fact the published prices were wrong, and the likelihood of correct prices increases over time:
|
I'm not sure I agree here. If exact time of availability is not known and it's not critical for the binding to get the prices at any specific moment, then I don't see any harm in adding some jitter so all clients don't call at exactly the same time. Even distribution over a few minutes can help. Most likely openHAB traffic is minimal so in reality it probably won't matter much, but I think in general it's a good courtesy and design to do this. Example from Energi Data Service with just one minute of call distribution: Lines 65 to 74 in 12a1f76
A few other used strategies (just for sharing): Anyway, it's definitely outside the scope of this PR. |
For the optimisation part I would say that some minimal jitter around the hours should be ok. We could add a random delay between 0-5 minutes on the timestamp, should be easy to implement I guess...
I do see your point here, but from my knowledge of services like these, people behind such APIs are indeed happy of a little randomisation. Scaling the system for such peak loads is a pain in the ass, especially when you then have almost no traffic at the remaining time. I can add this to the code, I will just need a little time since I'll be not available for a week or two. We could also just merge this now and optimise it later. |
@tl-photography Did you see my comment? |
I think the prices would usually already stable at 1500. There is a very very small change they would change until 1800 and nearly impossible at 2100. So this is really just to cover that one edge case. I agree that there might be a chance of broken schedules when a consecutive range is already running and is scheduled to run longer than the update. I also think it should not turn it off, as @J-N-K mentioned. This should be addressed at some point, but I'm not sure if we can fix that quickly. |
@tl-photography Can you address the only remaining comment by @Wolfgang1966 and add a note about the more frequent refreshes and the slight chance there might be discontinuities in the best price thing to the docs? I would like to see this merged so I can progress with the |
Sure, will update the PR in the evening! |
update the docs with a short comment on this. |
49800b7
to
0e791dc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always start a new sentence on a new line.
@@ -18,6 +18,8 @@ The `prices` Thing provides todays and (after 14:00) tomorrows net and gross pri | |||
|
|||
The `bestprice` Thing identifies the hours with the cheapest prices based on the given parameters. | |||
|
|||
Note: The Thing will schedule updates of the aWATTar API at 15:00, 18:00 and 21:00. If late updates occur, e.g. after 2100, there is a chance that consecutive best prices will be rescheduled. As a consequence, a time schedule spanning over an update slot might be interrupted and rescheduled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: The Thing will schedule updates of the aWATTar API at 15:00, 18:00 and 21:00. If late updates occur, e.g. after 2100, there is a chance that consecutive best prices will be rescheduled. As a consequence, a time schedule spanning over an update slot might be interrupted and rescheduled. | |
Note: The Thing will schedule updates of the aWATTar API at 15:00, 18:00 and 21:00. If late updates occur, e.g. after 21:00, there is a chance that consecutive best prices will be rescheduled. | |
As a consequence, a time schedule spanning over an update slot might be interrupted and rescheduled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was that the reason for the failed build? o_O
0e791dc
to
0b5a1f5
Compare
@Wolfgang1966 Any objections? Otherwise I'll merge. |
Signed-off-by: Thomas Leber <thomas@tl-photography.at>
6452ed9
to
876e131
Compare
What changed in the last push? If you force push we can't track changes. |
I accidentially synced my branch with the main repo, resulting in a merge from github. I rebased it again, getting rid of the merge. Code is the same as before. i actually wanted to sync my main branch. sorry for that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks @tl-photography
...awattar/src/main/java/org/openhab/binding/awattar/internal/handler/AwattarBridgeHandler.java
Outdated
Show resolved
Hide resolved
...awattar/src/main/java/org/openhab/binding/awattar/internal/handler/AwattarBridgeHandler.java
Show resolved
Hide resolved
...awattar/src/main/java/org/openhab/binding/awattar/internal/handler/AwattarBridgeHandler.java
Show resolved
Hide resolved
This is just a fyi: Today's market seems to be in risk of being decoupled again, as there seems to be some technical issues. At the time I'm writing this, there are still no prices published by the aWATTar API. |
Just checked ENTSO-E: Prices for tomorrow are available there now: And now awattar.de has them also |
Yes, aWATTar DE and AT do now have prices. The issue seemed to be resolved in time. |
Signed-off-by: Thomas Leber <thomas@tl-photography.at>
Signed-off-by: Thomas Leber <thomas@tl-photography.at> Signed-off-by: Patrik Gfeller <patrik.gfeller@proton.me>
Signed-off-by: Thomas Leber <thomas@tl-photography.at>
Signed-off-by: Thomas Leber <thomas@tl-photography.at>
Shedules the API update more than once per day.