diff --git a/app/octopus_to_influxdb.py b/app/octopus_to_influxdb.py index 1cdb509..ffa5cb4 100644 --- a/app/octopus_to_influxdb.py +++ b/app/octopus_to_influxdb.py @@ -7,6 +7,8 @@ import maya import requests from influxdb import InfluxDBClient +from influxdb_client import InfluxDBClient, Point +from influxdb_client.client.write_api import SYNCHRONOUS def retrieve_paginated_data( @@ -31,7 +33,7 @@ def retrieve_paginated_data( return results -def store_series(connection, series, metrics, rate_data): +def store_series(connection, version, org, bucket, series, metrics, rate_data): agile_data = rate_data.get('agile_unit_rates', []) agile_rates = { @@ -114,8 +116,10 @@ def tags_for_measurement(measurement): } for measurement in metrics ] - connection.write_points(measurements) - + if (version == 2): + connection.write(bucket, org, measurements) + elif (version == 1): + connection.write_points(measurements) @click.command() @click.option( @@ -130,13 +134,28 @@ def cmd(config_file, from_date, to_date): config = ConfigParser() config.read(config_file) - influx = InfluxDBClient( - host=config.get('influxdb', 'host', fallback="localhost"), - port=config.getint('influxdb', 'port', fallback=8086), - username=config.get('influxdb', 'user', fallback=""), - password=config.get('influxdb', 'password', fallback=""), - database=config.get('influxdb', 'database', fallback="energy"), - ) + org=config.get('influxdb', 'org', fallback="") + database=config.get('influxdb', 'database', fallback="energy") + influx_version=(config.getint('influxdb', 'version', fallback=2)) + + if (influx_version == 2): + influx = InfluxDBClient( + url=config.get('influxdb', 'url', fallback="http://localhost:8086"), + token=config.get('influxdb', 'token', fallback=""), + org=org, + ) + write_api = influx.write_api(write_options=SYNCHRONOUS) + elif (influx_version == 1): + influx = InfluxDBClient( + host=config.get('influxdb', 'host', fallback="localhost"), + port=config.getint('influxdb', 'port', fallback=8086), + username=config.get('influxdb', 'user', fallback=""), + password=config.get('influxdb', 'password', fallback=""), + database=database, + ) + write_api = influx + else: + raise click.ClickException('Influx version not supported') api_key = config.get('octopus', 'api_key') if not api_key: @@ -214,7 +233,7 @@ def cmd(config_file, from_date, to_date): api_key, agile_url, from_iso, to_iso ) click.echo(f' {len(rate_data["electricity"]["agile_unit_rates"])} rates.') - store_series(influx, 'electricity', e_consumption, rate_data['electricity']) + store_series(write_api, influx_version, org, database, 'electricity', e_consumption, rate_data['electricity']) click.echo( f'Retrieving gas data for {from_iso} until {to_iso}...', @@ -224,8 +243,8 @@ def cmd(config_file, from_date, to_date): api_key, g_url, from_iso, to_iso ) click.echo(f' {len(g_consumption)} readings.') - store_series(influx, 'gas', g_consumption, rate_data['gas']) + store_series(write_api, influx_version, org, database, 'gas', g_consumption, rate_data['gas']) if __name__ == '__main__': - cmd() \ No newline at end of file + cmd() diff --git a/app/requirements.txt b/app/requirements.txt index 904a2da..33d2871 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -1,4 +1,5 @@ requests >= 2.20.0 influxdb == 5.2.0 Click == 7.0 -maya == 0.5.0 \ No newline at end of file +maya == 0.5.0 +influxdb-client >= 1.24.0 diff --git a/energy_dashboard_flux.json b/energy_dashboard_flux.json new file mode 100644 index 0000000..8ce4c06 --- /dev/null +++ b/energy_dashboard_flux.json @@ -0,0 +1,1746 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "gnetId": null, + "graphTooltip": 0, + "id": 7, + "links": [], + "panels": [ + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "octograph-test", + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, + "format": "kwatth", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 2, + "w": 6, + "x": 0, + "y": 0 + }, + "id": 6, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false + }, + "tableColumn": "", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "none" + ], + "type": "fill" + } + ], + "measurement": "electricity", + "orderByTime": "ASC", + "policy": "default", + "query": "from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"electricity\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"consumption\")\r\n |> keep(columns:[\"_value\"])\r\n |> sum()", + "rawQuery": true, + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "consumption" + ], + "type": "field" + }, + { + "params": [], + "type": "sum" + } + ] + ], + "tags": [] + } + ], + "thresholds": "", + "title": "Electricity used", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "total" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "octograph-test", + "decimals": 2, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, + "format": "currencyGBP", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 2, + "w": 6, + "x": 6, + "y": 0 + }, + "id": 10, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false + }, + "tableColumn": "", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "none" + ], + "type": "fill" + } + ], + "measurement": "electricity", + "orderByTime": "ASC", + "policy": "default", + "query": "from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"electricity\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"cost\")\r\n |> keep(columns:[\"_value\"])\r\n |> sum()\r\n |> map(fn: (r) => ({\r\n _value: r._value / 100.0\r\n })\r\n )", + "rawQuery": true, + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "cost" + ], + "type": "field" + }, + { + "params": [], + "type": "sum" + } + ] + ], + "tags": [] + } + ], + "thresholds": "", + "title": "Go cost (units only)", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "total" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "octograph-test", + "decimals": 2, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, + "format": "currencyGBP", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 2, + "w": 6, + "x": 12, + "y": 0 + }, + "id": 12, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false + }, + "tableColumn": "", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "none" + ], + "type": "fill" + } + ], + "measurement": "electricity", + "orderByTime": "ASC", + "policy": "default", + "query": "from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"electricity\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"total_cost\")\r\n |> keep(columns:[\"_value\"])\r\n |> sum()\r\n |> map(fn: (r) => ({\r\n _value: r._value / 100.0\r\n })\r\n )", + "rawQuery": true, + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "cost" + ], + "type": "field" + }, + { + "params": [], + "type": "sum" + } + ] + ], + "tags": [] + } + ], + "thresholds": "", + "title": "Go cost (total)", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "total" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "octograph-test", + "decimals": 4, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, + "format": "currencyGBP", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 2, + "w": 6, + "x": 18, + "y": 0 + }, + "id": 14, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false + }, + "tableColumn": "", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "none" + ], + "type": "fill" + } + ], + "measurement": "electricity", + "orderByTime": "ASC", + "policy": "default", + "query": "consumption = from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"electricity\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"consumption\")\r\n |> keep(columns:[\"_start\",\"_value\"])\r\n |> sum()\r\n\r\ncost = from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"electricity\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"total_cost\")\r\n |> keep(columns:[\"_start\",\"_value\"])\r\n |> sum()\r\n\r\njoin(tables: {cost: cost, consumption: consumption}, on: [\"_start\"])\r\n |> map(fn: (r) => ({_value: (r._value_cost / r._value_consumption) / 100.0 }))", + "rawQuery": true, + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "cost" + ], + "type": "field" + }, + { + "params": [], + "type": "sum" + } + ] + ], + "tags": [] + } + ], + "thresholds": "", + "title": "Go effective unit cost", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "total" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "octograph-test", + "decimals": 2, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, + "format": "currencyGBP", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 2, + "w": 6, + "x": 6, + "y": 2 + }, + "id": 17, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false + }, + "tableColumn": "", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "none" + ], + "type": "fill" + } + ], + "measurement": "electricity", + "orderByTime": "ASC", + "policy": "default", + "query": "from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"electricity\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"agile_cost\")\r\n |> keep(columns:[\"_value\"])\r\n |> sum()\r\n |> map(fn: (r) => ({\r\n _value: r._value / 100.0\r\n })\r\n )", + "rawQuery": true, + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "cost" + ], + "type": "field" + }, + { + "params": [], + "type": "sum" + } + ] + ], + "tags": [] + } + ], + "thresholds": "", + "title": "Agile cost (units only)", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "total" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "octograph-test", + "decimals": 2, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, + "format": "currencyGBP", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 2, + "w": 6, + "x": 12, + "y": 2 + }, + "id": 18, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false + }, + "tableColumn": "", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "none" + ], + "type": "fill" + } + ], + "measurement": "electricity", + "orderByTime": "ASC", + "policy": "default", + "query": "from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"electricity\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"agile_total_cost\")\r\n |> keep(columns:[\"_value\"])\r\n |> sum()\r\n |> map(fn: (r) => ({\r\n _value: r._value / 100.0\r\n })\r\n )", + "rawQuery": true, + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "cost" + ], + "type": "field" + }, + { + "params": [], + "type": "sum" + } + ] + ], + "tags": [] + } + ], + "thresholds": "", + "title": "Agile cost (total)", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "total" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "octograph-test", + "decimals": 4, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, + "format": "currencyGBP", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 2, + "w": 6, + "x": 18, + "y": 2 + }, + "id": 19, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false + }, + "tableColumn": "", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "none" + ], + "type": "fill" + } + ], + "measurement": "electricity", + "orderByTime": "ASC", + "policy": "default", + "query": "consumption = from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"electricity\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"consumption\")\r\n |> keep(columns:[\"_start\",\"_value\"])\r\n |> sum()\r\n\r\ncost = from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"electricity\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"agile_total_cost\")\r\n |> keep(columns:[\"_start\",\"_value\"])\r\n |> sum()\r\n\r\njoin(tables: {cost: cost, consumption: consumption}, on: [\"_start\"])\r\n |> map(fn: (r) => ({_value: (r._value_cost / r._value_consumption) / 100.0 }))", + "rawQuery": true, + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "cost" + ], + "type": "field" + }, + { + "params": [], + "type": "sum" + } + ] + ], + "tags": [] + } + ], + "thresholds": "", + "title": "Agile effective unit cost", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "total" + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "octograph-test", + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 9, + "w": 24, + "x": 0, + "y": 4 + }, + "hiddenSeries": false, + "id": 2, + "legend": { + "alignAsTable": false, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.4.3", + "pointradius": 5, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "Go cost", + "yaxis": 2, + "zindex": -1 + }, + { + "alias": "Agile cost", + "yaxis": 2, + "zindex": -1 + }, + { + "alias": "agile_cost", + "yaxis": 2 + }, + { + "alias": "cost", + "yaxis": 2 + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "alias": "Usage", + "groupBy": [ + { + "params": [ + "30m" + ], + "type": "time" + }, + { + "params": [ + "linear" + ], + "type": "fill" + } + ], + "measurement": "electricity", + "orderByTime": "ASC", + "policy": "default", + "query": "from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"electricity\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"consumption\")\r\n |> keep(columns:[\"_value\", \"_time\", \"_field\"])\r\n |> aggregateWindow(every: 30m, fn: mean)", + "rawQuery": false, + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "consumption" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [] + }, + { + "alias": "Go cost", + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "linear" + ], + "type": "fill" + } + ], + "hide": false, + "measurement": "electricity", + "orderByTime": "ASC", + "policy": "default", + "query": "from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"electricity\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"agile_cost\" or r[\"_field\"] == \"cost\")\r\n |> keep(columns:[\"_value\", \"_time\", \"_field\"])\r\n |> map(fn: (r) => ({\r\n _value: r._value / 100.0,\r\n _time: r._time,\r\n _field: r._field\r\n })\r\n )\r\n |> aggregateWindow(every: 30m, fn: mean)", + "rawQuery": true, + "refId": "B", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "cost" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Electricity", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "$$hashKey": "object:108", + "format": "kwatth", + "label": "Usage", + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "$$hashKey": "object:109", + "decimals": 2, + "format": "currencyGBP", + "label": "Cost", + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "octograph-test", + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, + "format": "kwatth", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 2, + "w": 6, + "x": 0, + "y": 13 + }, + "id": 7, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false + }, + "tableColumn": "", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "none" + ], + "type": "fill" + } + ], + "measurement": "gas", + "orderByTime": "ASC", + "policy": "default", + "query": "from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"gas\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"consumption\")\r\n |> keep(columns:[\"_value\"])\r\n |> sum()", + "rawQuery": true, + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "consumption" + ], + "type": "field" + }, + { + "params": [], + "type": "sum" + } + ] + ], + "tags": [] + } + ], + "thresholds": "", + "title": "Gas used", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "total" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "octograph-test", + "decimals": 2, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, + "format": "currencyGBP", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 2, + "w": 6, + "x": 6, + "y": 13 + }, + "id": 11, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false + }, + "tableColumn": "", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "none" + ], + "type": "fill" + } + ], + "measurement": "electricity", + "orderByTime": "ASC", + "policy": "default", + "query": "from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"gas\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"cost\")\r\n |> keep(columns:[\"_value\"])\r\n |> sum()\r\n |> map(fn: (r) => ({\r\n _value: r._value / 100.0\r\n })\r\n )", + "rawQuery": true, + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "cost" + ], + "type": "field" + }, + { + "params": [], + "type": "sum" + } + ] + ], + "tags": [] + } + ], + "thresholds": "", + "title": "Gas cost (units only)", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "total" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "octograph-test", + "decimals": 2, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, + "format": "currencyGBP", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 2, + "w": 6, + "x": 12, + "y": 13 + }, + "id": 13, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false + }, + "tableColumn": "", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "none" + ], + "type": "fill" + } + ], + "measurement": "electricity", + "orderByTime": "ASC", + "policy": "default", + "query": "from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"gas\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"total_cost\")\r\n |> keep(columns:[\"_value\"])\r\n |> sum()\r\n |> map(fn: (r) => ({\r\n _value: r._value / 100.0\r\n })\r\n )", + "rawQuery": true, + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "cost" + ], + "type": "field" + }, + { + "params": [], + "type": "sum" + } + ] + ], + "tags": [] + } + ], + "thresholds": "", + "title": "Gas cost (total)", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "total" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "octograph-test", + "decimals": 4, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, + "format": "currencyGBP", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 2, + "w": 6, + "x": 18, + "y": 13 + }, + "id": 15, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false + }, + "tableColumn": "", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "none" + ], + "type": "fill" + } + ], + "measurement": "electricity", + "orderByTime": "ASC", + "policy": "default", + "query": "consumption = from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"electricity\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"consumption\")\r\n |> keep(columns:[\"_start\",\"_value\"])\r\n |> sum()\r\n\r\ncost = from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"gas\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"total_cost\")\r\n |> keep(columns:[\"_start\",\"_value\"])\r\n |> sum()\r\n\r\njoin(tables: {cost: cost, consumption: consumption}, on: [\"_start\"])\r\n |> map(fn: (r) => ({_value: (r._value_cost / r._value_consumption) / 100.0 }))", + "rawQuery": true, + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "cost" + ], + "type": "field" + }, + { + "params": [], + "type": "sum" + } + ] + ], + "tags": [] + } + ], + "thresholds": "", + "title": "Gas effective unit cost", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "total" + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "octograph-test", + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 9, + "w": 24, + "x": 0, + "y": 15 + }, + "hiddenSeries": false, + "id": 8, + "legend": { + "alignAsTable": false, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.4.3", + "pointradius": 5, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "Cost", + "yaxis": 2, + "zindex": -1 + }, + { + "alias": "cost", + "yaxis": 2 + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "alias": "Usage", + "groupBy": [ + { + "params": [ + "30m" + ], + "type": "time" + }, + { + "params": [ + "linear" + ], + "type": "fill" + } + ], + "measurement": "gas", + "orderByTime": "ASC", + "policy": "default", + "query": "from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"gas\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"consumption\")\r\n |> keep(columns:[\"_value\", \"_time\", \"_field\"])\r\n |> aggregateWindow(every: 30m, fn: mean)", + "rawQuery": false, + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "consumption" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [] + }, + { + "alias": "Cost", + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "linear" + ], + "type": "fill" + } + ], + "hide": false, + "measurement": "electricity", + "orderByTime": "ASC", + "policy": "default", + "query": "from(bucket: \"energy\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"gas\")\r\n |> filter(fn: (r) => r[\"_field\"] == \"cost\")\r\n |> keep(columns:[\"_value\", \"_time\", \"_field\"])\r\n |> map(fn: (r) => ({\r\n _value: r._value / 100.0,\r\n _time: r._time,\r\n _field: r._field\r\n })\r\n )\r\n |> aggregateWindow(every: 30m, fn: mean)", + "rawQuery": true, + "refId": "B", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "cost" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Gas", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "$$hashKey": "object:419", + "format": "kwatth", + "label": "Usage", + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "$$hashKey": "object:420", + "decimals": 2, + "format": "currencyGBP", + "label": "Cost", + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + } + ], + "refresh": false, + "schemaVersion": 27, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "2021-01-01T00:00:00.000Z", + "to": "2021-03-07T23:59:59.000Z" + }, + "timepicker": { + "refresh_intervals": [ + "5s", + "10s", + "30s", + "1m", + "5m", + "15m", + "30m", + "1h", + "2h", + "1d" + ], + "time_options": [ + "5m", + "15m", + "1h", + "6h", + "12h", + "24h", + "2d", + "7d", + "30d" + ] + }, + "timezone": "", + "title": "Energy usage", + "uid": "7Nqpoj-ik", + "version": 5 +} diff --git a/energy_dashboard.json b/energy_dashboard_influxql.json similarity index 100% rename from energy_dashboard.json rename to energy_dashboard_influxql.json diff --git a/example-octograph.ini b/example-octograph.ini index 9142191..d99b3f4 100644 --- a/example-octograph.ini +++ b/example-octograph.ini @@ -1,9 +1,10 @@ [influxdb] -host = localhost -port = 8086 -user = user -password = password +# InfluxDB v1 requires different parameters to be set here: username, password, host, and port. +version = 2 +url=http://localhost:8086 +token=0123456789ABCDEF database = energy +org = myorg [octopus] api_key = sk_live_1234 @@ -26,7 +27,7 @@ serial_number = 12A3456 standing_charge = 16.80 unit_rate = 3.03 # 1 for SMETS1 meters, 2 for SMETS2 meters -meter_type = 1 +meter_type = 2 # 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