Compare commits

4 Commits

Author SHA1 Message Date
Ben Roberts
917d038bf9 Drop time-of-day tag which makes data difficult to use with victoria-metrics/promql 2020-08-31 14:01:47 +01:00
Ben Roberts
ca49193748 Cast config settings to floats 2020-08-31 14:01:38 +01:00
Ben Roberts
c6517663bc Update example config file with SMETS2 settings 2020-08-31 13:52:31 +01:00
Ben Roberts
73cf170e18 Handle unit conversion for SMETS2 gas meters
SMETS2 gas meter consumption is measured in m3 rather than kWh, so conversion
from one unit to the other is required.
Algorithm and description of terms is taken from:
https://www.theenergyshop.com/guides/how-to-convert-gas-units-to-kwh

This commit adds additional config file options to the `gas` section:
- `meter_type` (default `1` for backward compatibility)
  Enables unit conversion from m3 to kWh before reporting metrics to influxdb
- `volume_correction_factor` (default `1.02264`)
- `calorific_value` (default `40`)
2020-08-31 12:06:42 +01:00
2 changed files with 15 additions and 1 deletions

View File

@@ -71,6 +71,9 @@ def store_series(connection, series, metrics, rate_data):
def fields_for_measurement(measurement): def fields_for_measurement(measurement):
consumption = measurement['consumption'] consumption = measurement['consumption']
conversion_factor = rate_data.get('conversion_factor', None)
if conversion_factor:
consumption *= conversion_factor
rate = active_rate_field(measurement) rate = active_rate_field(measurement)
rate_cost = rate_data[rate] rate_cost = rate_data[rate]
cost = consumption * rate_cost cost = consumption * rate_cost
@@ -99,7 +102,7 @@ def store_series(connection, series, metrics, rate_data):
time = period.datetime().strftime('%H:%M') time = period.datetime().strftime('%H:%M')
return { return {
'active_rate': active_rate_field(measurement), 'active_rate': active_rate_field(measurement),
'time_of_day': time, #'time_of_day': time,
} }
measurements = [ measurements = [
@@ -149,6 +152,9 @@ def cmd(config_file, from_date, to_date):
g_mpan = config.get('gas', 'mpan', fallback=None) g_mpan = config.get('gas', 'mpan', fallback=None)
g_serial = config.get('gas', 'serial_number', fallback=None) g_serial = config.get('gas', 'serial_number', fallback=None)
g_meter_type = config.get('gas', 'meter_type', fallback=1)
g_vcf = config.get('gas', 'volume_correction_factor', fallback=1.02264)
g_cv = config.get('gas', 'calorific_value', fallback=40)
if not g_mpan or not g_serial: if not g_mpan or not g_serial:
raise click.ClickException('No gas meter identifiers') raise click.ClickException('No gas meter identifiers')
g_url = 'https://api.octopus.energy/v1/gas-meter-points/' \ g_url = 'https://api.octopus.energy/v1/gas-meter-points/' \
@@ -184,6 +190,8 @@ def cmd(config_file, from_date, to_date):
'gas', 'standing_charge', fallback=0.0 'gas', 'standing_charge', fallback=0.0
), ),
'unit_rate': config.getfloat('gas', 'unit_rate', fallback=0.0), 'unit_rate': config.getfloat('gas', 'unit_rate', fallback=0.0),
# SMETS1 meters report kWh, SMET2 report m^3 and need converting to kWh first
'conversion_factor': (float(g_vcf) * float(g_cv)) / 3.6 if int(g_meter_type) > 1 else None,
} }
} }

View File

@@ -25,3 +25,9 @@ mpan = 12345
serial_number = 12A3456 serial_number = 12A3456
standing_charge = 16.80 standing_charge = 16.80
unit_rate = 3.03 unit_rate = 3.03
# 1 for SMETS1 meters, 2 for SMETS2 meters
meter_type = 1
# volume correction factor, and calorific values used to convert SMETS2 consumption from m^3 to kWh
# Defaults are typically used values. Your energy bill will show you the values used for your supply.
volume_correction_factor = 1.02264
calorific_value = 40