BottlecapDave / HomeAssistant-OctopusEnergy

Unofficial Home Assistant integration for interacting with Octopus Energy
https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/
MIT License
535 stars 50 forks source link

HA restart causes Previous day accumulation cost to be incorrect due to lack of completed dispatches #751

Closed pacemaker82 closed 4 months ago

pacemaker82 commented 4 months ago

Describe the bug

Integration receives an update for previous day's accumulation kWh and cost is calculated. With IOG this includes completed dispatches applied. Cost is accurate.

When you restart HA after this happens, the data is again retrieved from octopus and re-calculated, this time without the completed dispatches, and only based on the base tariff information. This leads to a wildly incorrect calculation.

Checking the completed dispatches, they are there in the sensor, but are not reflected as being used to calculate the previous day accumulated cost.

Reproduction steps

Restart HA

Previous day accumulation cost is calculated, without completed dispatches.

Check sensor for completed dispatches, confirm they are there.

previous day accumulation cost remains incorrect hours later.

Expected behaviour

Previous day accumulation cost reflects base tariff + completed dispatches.

Tariff Code

E-1R-INTELLI-BB-VAR-23-03-01-J

Integration Version

10.1.10

Home Assistant Version

2024.1.5

Fresh Install?

Fresh install

Home Assistant Logs

na

Confirmation

pacemaker82 commented 4 months ago

Here's the attributes for the previous day accumulation cost not taking into consideration the dispatches. Have also copied the dispatches below from theintelligent_dispatching sensor. For ease look at the 10.00-10.30 timeframe (should be cheap per completed dispatches below).

Tariff code E-1R-INTELLI-BB-VAR-23-03-01-J Charges

And below is the completed dispatches:

Completed dispatches - start: '2024-02-12T10:00:00+00:00' end: '2024-02-12T10:30:00+00:00' charge_in_kwh: -1.03 source: null location: AT_HOME

BottlecapDave commented 4 months ago

Hello and sorry that you're seeing this. I assume that the cost corrects itself eventually. I think what I'll do is delay the calculation until dispatch information is available. A fix should be available in the next release.

pacemaker82 commented 4 months ago

Hi @BottlecapDave - no the cost hasnt corrected since the HA restart yesterday (nearly 22 hours ago now). It doesnt seem to re-evaluate. I presume it will only re-evaluate (and be correct) when new data comes in today for yesterday's data. As long as I dont restart HA it will be OK - guess there's some kind of race condition or order of events when HA reloads where the completed dispatches werent ready in time to do the calculation on restart.

Screenshot 2024-02-14 at 07 51 34

As you can see above, it seems to get the data from API often but isnt re-evaluating it. 09.20am was the restart time

pacemaker82 commented 4 months ago

Just wanted to comment that the cost "fixed" itself once the new data came in for the next previous day (if that makes sense). Meaning if the data was the same, it didnt re-evaluate and remained incorrect. The following previous day's data was correct and using the completed dispatches as expected.

BottlecapDave commented 4 months ago

Hello. This should hopefully be fixed in v10.1.1. Please confirm when you can :)

pacemaker82 commented 4 months ago

This seems to have worked OK, however something interesting happened.

The previous day import cost entity updated this morning around 8.35am to £2.49. I then updated to 10.1.1, the price has changed again, now £2.10 (you can see the price changes here toward the end of the chart). I am now unsure which price is or was accurate (the pre 10.1.1 price, or the 10.1.1/10.1.2 price).

Below is the price chart and the kWh chart. You can see the total kWh didnt change, but the total price did.

Screenshot 2024-02-18 at 10 19 13 Screenshot 2024-02-18 at 10 23 14
pacemaker82 commented 4 months ago

Actually, it looks like the pre 10.1.1 cost did not include any extra completedDispatches (there was one at 5.30-6.00am which is outside of the normal window). If I calculate the costs where that slot was at full rate, I get the £ 2.49 total.

Will keep an eye on it when it refreshes tomorrow to make sure any reported cost is including out of band dispatches.

BottlecapDave commented 4 months ago

Correct. As per the changelog for 10.1.1, there was a chance upon restart when the cost was incorrect as it was calculated before completed dispatches were retrieved.

BottlecapDave commented 4 months ago

I'll close this issue as the original issue seems to have been fixed. Please open a new issue if you find something different, as it helps me keeping track of issues and others who find the same problems.

pacemaker82 commented 4 months ago

Just to be clear though, there was no restart of HA until AFTER 10.1.1 was installed. The initial incorrect price (on the old version of the integration) happened naturally.

BottlecapDave commented 4 months ago

That might have been OE being slow at giving completed dispatches.