Function Repository Resource:

OctopusEnergyConsumption

Source Notebook

Read energy consumption data from smart meters managed by the UK energy company Octopus Energy

Contributed by: Jon McLoone

ResourceFunction["OctopusEnergyConsumption"][credentials]

reads energy consumption data from the gas or electricity meter described by the Association credentials.

Details and Options

The gas or electricity meter description consists of an Association with three required keys: APIKey, SerialNumber and either MPAN (for electricity) or MPRN (for gas). This information is available by logging in to Octopus Developer.
The data is returned as DateObject and real values. Electricity meters return data in KWh but gas meters return either KWh or m3 depending on the smart meter type.
ResourceFunction["OctopusEnergyConsumption"] supports the following options:
"MaxRecords"100the number of records to attempt to retreive
"Interval"Automaticthe time to aggregate usage over. Automatic is 30 minute periods. Available choices are: 
“Hour”,”Day”,”Week”,”Quarter”
"StartTime"Automaticthe date and time of the first record to return
"EndTime"Automaticthe date and time of the last record to return ("StartTime" must also be specified).

Examples

Basic Examples (1) 

Plot the most recent 100 half-hourly records of electricity consumption:

In[1]:=
DateListPlot[
 ResourceFunction[
  "OctopusEnergyConsumption"][<|"APIKey" -> "XXX", "MPAN" -> "12345678", "SerialNumber" -> "11111111"|>], PlotLabel -> "Electricity consumption"]
Out[17]=

Scope (1) 

An MPRN value is required to retrieve gas usage (note that gas and electricity meters at the same property have different serial numbers):

In[18]:=
DateListPlot[
 ResourceFunction[
  "OctopusEnergyConsumption"][<|"APIKey" -> "XXX", "MPRN" -> "87654321", "SerialNumber" -> "22222222"|>], PlotLabel -> "Gas consumption"]
Out[18]=

Options (3) 

The maximum number of records you can request is 25,000:

In[19]:=
DateListPlot[
 ResourceFunction[
  "OctopusEnergyConsumption"][<|"APIKey" -> "XXX", "MPAN" -> "12345678", "SerialNumber" -> "11111111"|>, "MaxRecords" -> 25000], PlotLabel -> "Electricity consumption", PlotRange -> All]
Out[19]=

You can fetch records for a given period:

In[20]:=
DateListPlot[
 ResourceFunction[
  "OctopusEnergyConsumption"][<|"APIKey" -> "XXX", "MPAN" -> "12345678", "SerialNumber" -> "11111111"|>, "MaxRecords" -> 25000, "StartTime" -> DateObject[{2022, 1, 1}], "EndTime" -> DateObject[{2022, 1, 31}]], PlotLabel -> "Electricity consumption", PlotRange -> All]
Out[20]=

Fetch weekly consumption:

In[21]:=
DateListPlot[
 ResourceFunction[
  "OctopusEnergyConsumption"][<|"APIKey" -> "XXX", "MPAN" -> "12345678", "SerialNumber" -> "11111111"|>, "Interval" -> "Week"], PlotLabel -> "Electricity consumption", PlotRange -> All]
Out[21]=

Publisher

Jon McLoone

Version History

  • 1.0.0 – 27 May 2022

License Information