utilities/telegraf-plugins#17: Partially created Export account broke plugin



Issue Information

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

Created: 24-Jul-23 15:45



Description

It looks like my export MPAN has probably started showing up against my account - I noticed the plugin had stopped collecting pricing and consumption data.

When triggered manually, it throws an exception

Traceback (most recent call last):
  File "/home/ben/Documents/src.old/telegraf-plugins/octopus-energy/./octopus-energy.py", line 305, in <module>
    main(api_key, mpan)
  File "/home/ben/Documents/src.old/telegraf-plugins/octopus-energy/./octopus-energy.py", line 288, in main
    meter_info['consumption'] = getConsumption(meter_info, session)
  File "/home/ben/Documents/src.old/telegraf-plugins/octopus-energy/./octopus-energy.py", line 56, in getConsumption
    result = session.get(f"https://api.octopus.energy/v1/electricity-meter-points/{meter['mpan']}/meters/{meter['serial']}/consumption?period_from={from_str}")    
KeyError: 'serial'


Toggle State Changes

Activity


assigned to @btasker

Yep, the result of the call against /accounts/{octo_account} now has two MPANs:

'electricity_meter_points': [
{
'mpan': '<redacted>', 
'profile_class': 8, 
'consumption_standard': 2900, 
'meters': [], 
'agreements': [
   {
    'tariff_code': 'E-1R-VAR-22-11-01-A', 
    'valid_from': '2023-07-25T00:00:00+01:00', 
    'valid_to': None
   }], 
'is_export': True
}, 

{
'mpan': '<redacted>',
'profile_class': 1, 
'consumption_standard': 6088, 
'meters': [
   {
    'serial_number': '<redacted>', 
    'registers': [
       {
        'identifier': '1',
        'rate': 'STANDARD',
        'is_settlement_register': True
       }
     ]
   }
], '
agreements': [
   {'tariff_code': 'E-1R-VAR-22-11-01-A', 
    'valid_from': '2023-07-05T00:00:00+01:00',
    'valid_to': '2023-07-09T00:00:00+01:00'
   }, 
   {'tariff_code': 'E-1R-AGILE-FLEX-22-11-25-A', 
    'valid_from': '2023-07-09T00:00:00+01:00', 
    'valid_to': None}
   ], 
   'is_export': False}
],

The export entry doesn't currently have a meter recorded against it at all (presumably because things aren't fully set up on the Octopus side yet).

So, we should be checking that there's a meter registered at all before trying to get consumption info.

Commit 62b6ed7 addresses that.

verified

mentioned in commit github-mirror/telegraf-plugins@62b6ed781624385e330d017e6dfbc2da92999d97

Commit: github-mirror/telegraf-plugins@62b6ed781624385e330d017e6dfbc2da92999d97 
Author: B Tasker                            
                            
Date: 2023-07-24T16:52:32.000+01:00 

Message

Don't try and fetch consumption if we don't know the meter serial (utilities/telegraf-plugins#17)

The meter's serial number is required when fetching consumption information. When Octopus are in the process of setting up an export account the API may return the new MPAN with no meters registered against it - this change prevents that from breaking collection of other info

+3 -1 (4 lines changed)

Although the change stops the script breaking, it's worth noting there's a small oddity in the API responses.

The meter point in question looks like this:

{
'mpan': '<redacted>', 
'profile_class': 8, 
'consumption_standard': 2900, 
'meters': [], 
'agreements': [
   {
    'tariff_code': 'E-1R-VAR-22-11-01-A', 
    'valid_from': '2023-07-25T00:00:00+01:00', 
    'valid_to': None
   }
], 
'is_export': True
}

On the face of it it all looks OK, but E-1R-VAR-22-11-01-A is an import tariff

   {
      "code": "VAR-22-11-01",
      "direction": "IMPORT",
      "full_name": "Flexible Octopus November 2022 v1",
      "display_name": "Flexible Octopus",
      "description": "Flexible Octopus offers great value and 100% renewable electricity. As a variable tariff, your prices can rise and fall with wholesale prices - but we'll always give you notice of a change.",
      "is_variable": true,
      "is_green": false,
      "is_tracker": false,
      "is_prepay": false,
      "is_business": false,
      "is_restricted": false,
      "term": null,
      "available_from": "2023-03-28T10:35:00+01:00",
      "available_to": null,
      "links": [

Presumably that's just the default that gets registered against an account.

I noticed, because - although it displays a tariff code - we didn't seem to be outputting associated pricing information (the lack of serial should, logically, have been breaking the LP generation).

changed title from {-Export details-} broke plugin to {+Partially created Export account+} broke plugin

It just needed a bit of whitespace fixing - the details were appended to addresses in the wrong loop, so we only collected the last.

As expected, LP generation then started breaking because the new entry doesn't yet have a serial. That's also been addressed.

In commit 4a7184c I've made the final change: preventing pricing from being output if it can't apply to that MPAN (i.e. if it's an import tariff associated with an export mpan and vice-versa).

verified

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

Commit: github-mirror/telegraf-plugins@aa155ba82d33b12e002623db8cba04010b06c1cd 
Author: B Tasker                            
                            
Date: 2023-07-24T17:10:56.000+01:00 

Message

Fix pass-through of multiple tariffs - utilities/telegraf-plugins#17

+14 -8 (22 lines changed)
verified

mentioned in commit github-mirror/telegraf-plugins@4a7184c7c11c607d324ebc4e1db7d4029afae6a4

Commit: github-mirror/telegraf-plugins@4a7184c7c11c607d324ebc4e1db7d4029afae6a4 
Author: B Tasker                            
                            
Date: 2023-07-24T17:14:00.000+01:00 

Message

Only emit pricing information if it flows in the correct direction utilities/telegraf-plugins#17

During export account setup, an import tariff may temporarily be associated. Don't emit import pricing when this happens - export mpans should only link in export tariffs.

+6 -2 (8 lines changed)

mentioned in issue #18