Octopus App- Calculations with solar and battery

Now that Octopus Agile tariff has its peak consistently below the ‘Go’ daytime tariff I thought it would be useful to compare Agile and Go for my usage pattern to see if it was worth switching to Agile.

I found that the calculations in the app produce some strange results probably because I have both SolarPV and a battery. Here is a typical days results.

At night when there is no solar but there is battery discharge, The energy discharged by the battery appears as ‘Export’.

During the Octopus Go night time period when there is neither solar nor battery discharge (because the battery is charging), there is still a small segment labelled ‘Export’. Looking at the code the problem seems to be that grid export is calculated as

                let kwh_solar_used = kwh_use - kwh_import;
                let kwh_export = kwh_solar - kwh_solar_used;

If kwh_solar is zero then by definition kwh_export must be zero also and so
kwh_export = kwh_use
which cannot be correct.

As I solution I made a fork and modified octopus.php to use an explicit export_kwh feed which simplifies all the calculations. An export_kwh feed can be easily made in the same way as the import_kwh feed already required by the app.

My revised octopus.php can be seen at /delboy711/octopus.php if anyone is interested.

The graph now looks like this

The gaps between the bars are when battery discharge is active so there is neither import nor export.

Note: These changes will not have any effect if a half hour metered feed is used because the original code works differently if a metered feed is used, and I do not have one to test with.

I also made some little changes to fix a couple of niggles I had with the output.

  • Octopus Go import costs were not calculated when SolarPV was enabled.

  • Octopus Go import costs were always shown as £0.00 in the summary.

  • The value of solar self consumption for Go tariff was not shown in the summary.


Looks interesting. If you just have a consumption feed (or pull the data in via the API, it would give you better figures possibly.

Create a PR for @TrystanLea to look at. I know he made some changes recently to include the different Agile tariffs - have you pull that in?

I asked Trystan to make go optional, as it makes a mess of the graphs if you are not interested in that.