utilities/telegraf-plugins#14: Octopus Energy Pricing Plugin



Issue Information

Issue Type: issue
Status: closed
Reported By: btasker
Assigned To: btasker

Created: 05-Jul-23 07:55



Description

We're moving onto Octopus Energy.

They expose an API allowing retrieval of tariff information as well as consumption.

Last night I started writing a plugin to collect pricing information for any meters under a specific octopus account.

This issue is being raised to track further development of that.



Toggle State Changes

Activity


assigned to @btasker

The plugin (as currently written) requires two environment variables be set

  • OCTOPUS_KEY: the account's API Key (can be found here)
  • OCTOPUS_ACCOUNT: the Octopus account number

With those details it will

  • Place an API call to fetch account information
  • From that information, identify any meters associated with the account
  • Extract the tariff code for each meter
  • Use the tariff code to calculate the product identifier
  • Use both of those to fetch pricing information

At the moment we just build a big JSON blob - there's no line protocol being generated yet.

As well as Octopus' API docs, I used the excellent post by Guy Lipman to figure out which API endpoints needed calling.

One of the things we need to decide is how we want to handle the pricing info.

What we get back from the API looks like this

[
{
  'value_exc_vat': 29.2574, 
  'value_inc_vat': 30.72027, 
  'valid_from': '2023-06-30T23:00:00Z', 
  'valid_to': None, 
  'payment_method': 'DIRECT_DEBIT'
}, 
{
  'value_exc_vat': 29.9142,
  'value_inc_vat': 31.40991,
  'valid_from': '2023-06-30T23:00:00Z',
  'valid_to': None, 'payment_method':
  'NON_DIRECT_DEBIT'
}, 
{
  'value_exc_vat': 48.9338, 
  'value_inc_vat': 51.38049, 
  'valid_from': '2023-03-31T23:00:00Z', 
  'valid_to': '2023-06-30T23:00:00Z', 
  'payment_method': 'DIRECT_DEBIT'
}
]

(dodgy formatting is because I've pasted the resulting python dict in rather than the raw json)

I've cut it short, but it goes back to whenever the tariff was created. For Agile there will obviously be many more entries because the pricing is every half hour.

The question is: how do we want to handle exposing this pricing information?

    • Do we just extract the latest price and attach that to the meter info?
    • Do we do a 1:1 conversion (so in the example above, generate 3 lines of line protocol)
    • Do we calculate each hour (or even 30m) between valid_from and valid_to and generate a line of LP for that?

I don't think I like option 1) at all.

Option 2) is OK, but means that we'll likely - in effect - be doing Option 3) at query time instead (the majority of the time, pricing information is going to be JOINed to consumption so that costs can be calculated)

I think the answer probably is to generate the iterations. The API supports provision of a period_from= argument in the request, so that can be used to ensure we don't end up doing this work for months at a time.

verified

mentioned in commit github-mirror/telegraf-plugins@2cb04d2132b81a40e69cf155060da22666674058

Commit: github-mirror/telegraf-plugins@2cb04d2132b81a40e69cf155060da22666674058 
Author: B Tasker                            
                            
Date: 2023-07-05T08:55:07.000+01:00 

Message

Fetch property and tariff details from Octopus' API (utilities/telegraf-plugins#14)

This is going to need a tidy - I started it late last night shortly before I ran out of Southern Comfort.

But, it does work and fetch the details. The next stage will be build some logic to turn it into Line Protocol

+92 -0 (92 lines changed)
verified

mentioned in commit github-mirror/telegraf-plugins@b3621e66c2db047660a27e10d9b829492ca8a105

Commit: github-mirror/telegraf-plugins@b3621e66c2db047660a27e10d9b829492ca8a105 
Author: B Tasker                            
                            
Date: 2023-07-05T12:44:21.000+01:00 

Message

Limit tariff data to that which applies in the last 24h (utilities/telegraf-plugins#14)

+9 -1 (10 lines changed)
verified

mentioned in commit github-mirror/telegraf-plugins@c0010267fae08a827e7dec071a55549e0aaa1800

Commit: github-mirror/telegraf-plugins@c0010267fae08a827e7dec071a55549e0aaa1800 
Author: B Tasker                            
                            
Date: 2023-07-05T12:56:31.000+01:00 

Message

Start generating pricing LP (utilities/telegraf-plugins#14)

+48 -0 (48 lines changed)
verified

mentioned in commit github-mirror/telegraf-plugins@6f985b67cb90ffd815deda0eb4d1e8201c5fafc8

Commit: github-mirror/telegraf-plugins@6f985b67cb90ffd815deda0eb4d1e8201c5fafc8 
Author: B Tasker                            
                            
Date: 2023-07-05T17:13:09.000+01:00 

Message

Generate a line of line protocol for each 30m of a tariff price (utilities/telegraf-plugins#14)

+24 -4 (28 lines changed)
verified

mentioned in commit github-mirror/telegraf-plugins@3dbc85dd71c871dbb10cfbc55f059fa9d5e981f1

Commit: github-mirror/telegraf-plugins@3dbc85dd71c871dbb10cfbc55f059fa9d5e981f1 
Author: B Tasker                            
                            
Date: 2023-07-05T17:30:21.000+01:00 

Message

Add support for standing charge utilities/telegraf-plugins#14

+13 -1 (14 lines changed)

Although the main aim had been to collect tariff details, given the work involved in pulling out MPANs anyway, it's probably worth going a step further and grabbing consumption data too.

I've added support for consumption.

Given we're also collecting consumption, it's probably worth renaming the plugin from octopus-tariffs to octopus-energy (easier to do now than later, and the old name's no longer representative).

verified

mentioned in commit github-mirror/telegraf-plugins@c705b5ee07b90688e6b66b2520d1730e8f3775c1

Commit: github-mirror/telegraf-plugins@c705b5ee07b90688e6b66b2520d1730e8f3775c1 
Author: B Tasker                            
                            
Date: 2023-07-06T12:08:34.000+01:00 

Message

Rename to octopus-energy (utilities/telegraf-plugins#14)

Now that we're collecting more than just tariff data, the old name isn't really appropriate. Renaming as it'll be harder to do after release

+0 -0 (0 lines changed)
verified

mentioned in commit github-mirror/telegraf-plugins@fc2d2236aa600d54a409dc7067ead58afe247b0e

Commit: github-mirror/telegraf-plugins@fc2d2236aa600d54a409dc7067ead58afe247b0e 
Author: B Tasker                            
                            
Date: 2023-07-06T12:06:49.000+01:00 

Message

Add consumption handling utilities/telegraf-plugins#14

+46 -1 (47 lines changed)

I think I'm more or less at the stage where I should be ready to release

  • README has been created (commits inbound)
  • License headers have been added (BSD FTW)
  • Test install is happily sending data

However, Guy Lipman's post notes that

One of the complications of the price end-points is that they vary a bit between tariffs. I will first describe the Agile tariff, and then move to other tariffs in turn.

I'm actually ready to move onto Agile - I was expecting it to take a couple of weeks but they emailed me earlier (only brief hold up is I can't sign the terms + conditions because their server throws an error)

I can't see what the difference that Guy alludes to is - I think it might just be in the params that you can include in the URL, the path format and the response bodies look to be the same.

I think the answer to that, though, is to go ahead and merge and then raise a followup ticket once we're on Agile (if there's an issue).

verified

mentioned in commit github-mirror/telegraf-plugins@f3113b8504f655520a0a0505b9e31ef7b5187122

Commit: github-mirror/telegraf-plugins@f3113b8504f655520a0a0505b9e31ef7b5187122 
Author: B Tasker                            
                            
Date: 2023-07-06T19:35:32.000+01:00 

Message

Link back to the design issue

Design on this plugin was a bit haphazard, so seems worth linking back to utilities/telegraf-plugins#14 to help rationalise some of it

+2 -0 (2 lines changed)
unknown_key

mentioned in commit github-mirror/telegraf-plugins@119767a293db03362c5354706625eb6a85627086

Commit: github-mirror/telegraf-plugins@119767a293db03362c5354706625eb6a85627086 
Author: Ben Tasker                            
                            
Date: 2023-07-06T19:44:00.000+01:00 

Message

Merge pull request #3 from bentasker/octopus-tariffs

Add Octopus Energy Plugin (utilities/telegraf-plugins#14)

+361 -0 (361 lines changed)