From 25cfd8f4c66f44124474c553baa57b651fd40d49 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Mon, 3 Aug 2020 21:22:38 +0100 Subject: [PATCH 01/53] Attempt 1 at adding Agile Outgoing --- README.md | 2 +- octopus.html | 15 ++++++++++++--- octopus.js | 24 ++++++++++++++++++------ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ccefb19..c9089fd 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ node-red-contrib-octopus # Under Development -A Node-RED node to extract the Octopus Agile future price data via the API. +A Node-RED node to extract the Octopus Agile (or Agile Outgoing) future price data via the API. My [referral code](https://share.octopus.energy/wise-jade-356) if you are switching to Octopus and feel kind. diff --git a/octopus.html b/octopus.html index 5fea6c3..3a61110 100644 --- a/octopus.html +++ b/octopus.html @@ -21,6 +21,14 @@ + +
+ +
@@ -90,7 +98,7 @@

Outputs

Details

-

Query the Octopus Agile API for future pricing. +

Query the Octopus Agile (or Agile Outgoing) API for future pricing.

The pricing data is broken up into 30 min periods. The data for the next 24Hrs (23:00Z - 23:00Z) is released at approximately 16:00Z. The request is set to obtain all data available from now so the number of data periods returned by the API varies between approximately 15 and 63. @@ -111,15 +119,16 @@

References

defaults: { name: {value:"Octopus"}, region: {value:"A"}, + tariff: {value:"AGILE"}, numblocks: {value:"4"} }, inputs:1, - outputs:3, + outputs:4, outputLabels: ["raw","processed","influxdb"], icon: "octopus.png", align: "right", label: function() { - return this.name||this.region; + return this.name||this.region||this.tariff; }, labelStyle: function() { return this.name?"node_label_italic":""; diff --git a/octopus.js b/octopus.js index 8384933..dad0163 100644 --- a/octopus.js +++ b/octopus.js @@ -27,8 +27,16 @@ module.exports = function(RED) { } this.region = n.region - - var baseurl = "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-"; + + this.tariff = n.tariff + + var baseurl = ""; + + if (this.tariff == "AGILE") { + baseurl = "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-"; + } else { + baseurl = "https://api.octopus.energy/v1/products/AGILE-OUTGOING-19-05-13/electricity-tariffs/E-1R-AGILE-OUTGOING-19-05-13-"; + } var https = require("https"); var next_run = new Date(0); @@ -105,12 +113,16 @@ module.exports = function(RED) { var msg3 = {}; msg3.payload = []; - - msg.payload.results.forEach(function(item, index) { - msg3.payload.push([{ value_inc_vat : item.value_inc_vat, + if (this.tariff == "AGILE") { + msg.payload.results.forEach(function(item, index) { + sg3.payload.push([{ value_inc_vat : item.value_inc_vat, "time": new Date(item.valid_from).getTime() *1000 *1000}, {"source" : "Agile"}]); }); - + } else { + msg.payload.results.forEach(function(item, index) { + sg3.payload.push([{ value_inc_vat : item.value_inc_vat, + "time": new Date(item.valid_from).getTime() *1000 *1000}, {"source" : "Outgoing"}]); + } msg3.measurement = "OctopusPrice"; next_run = next_half_hour; From 147db84ee5a57829350873718c74c85fce84cd9d Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Mon, 3 Aug 2020 21:59:30 +0100 Subject: [PATCH 02/53] Attempt 2/fixes Fix number of outputs and rename node for identifiability --- octopus.html | 2 +- octopus.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/octopus.html b/octopus.html index 3a61110..b508a09 100644 --- a/octopus.html +++ b/octopus.html @@ -123,7 +123,7 @@

References

numblocks: {value:"4"} }, inputs:1, - outputs:4, + outputs:3, outputLabels: ["raw","processed","influxdb"], icon: "octopus.png", align: "right", diff --git a/octopus.js b/octopus.js index dad0163..973de73 100644 --- a/octopus.js +++ b/octopus.js @@ -189,5 +189,5 @@ module.exports = function(RED) { - RED.nodes.registerType("octopus in",octopusin); + RED.nodes.registerType("octopus in tj",octopusin); } From 9ba3603ebee17193c831c0ed7a6d816ef624b98c Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Mon, 3 Aug 2020 22:09:34 +0100 Subject: [PATCH 03/53] nursery school fixes semicolons and closed brackets --- octopus.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/octopus.js b/octopus.js index 973de73..02e300a 100644 --- a/octopus.js +++ b/octopus.js @@ -26,9 +26,9 @@ module.exports = function(RED) { }); } - this.region = n.region + this.region = n.region; - this.tariff = n.tariff + this.tariff = n.tariff; var baseurl = ""; @@ -117,11 +117,12 @@ module.exports = function(RED) { msg.payload.results.forEach(function(item, index) { sg3.payload.push([{ value_inc_vat : item.value_inc_vat, "time": new Date(item.valid_from).getTime() *1000 *1000}, {"source" : "Agile"}]); - }); + } else { msg.payload.results.forEach(function(item, index) { sg3.payload.push([{ value_inc_vat : item.value_inc_vat, "time": new Date(item.valid_from).getTime() *1000 *1000}, {"source" : "Outgoing"}]); + }); } msg3.measurement = "OctopusPrice"; From b9318dff45c8e1ae63779f0083003d0562af78cf Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Mon, 3 Aug 2020 22:16:45 +0100 Subject: [PATCH 04/53] Update octopus.js Ctrl+C the brackets, don't control X... --- octopus.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/octopus.js b/octopus.js index 02e300a..fbf5adc 100644 --- a/octopus.js +++ b/octopus.js @@ -117,7 +117,7 @@ module.exports = function(RED) { msg.payload.results.forEach(function(item, index) { sg3.payload.push([{ value_inc_vat : item.value_inc_vat, "time": new Date(item.valid_from).getTime() *1000 *1000}, {"source" : "Agile"}]); - + }); } else { msg.payload.results.forEach(function(item, index) { sg3.payload.push([{ value_inc_vat : item.value_inc_vat, @@ -127,8 +127,7 @@ module.exports = function(RED) { msg3.measurement = "OctopusPrice"; next_run = next_half_hour; - } - catch(err) { + } catch(err) { node.error(err,msg); // Failed to parse, pass it on } From 0d13a10255b454af565d9f944c8dcae758204ead Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Mon, 3 Aug 2020 22:20:28 +0100 Subject: [PATCH 05/53] rename node Renamed because no longer need identifiability --- octopus.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopus.js b/octopus.js index fbf5adc..b8d0e65 100644 --- a/octopus.js +++ b/octopus.js @@ -189,5 +189,5 @@ module.exports = function(RED) { - RED.nodes.registerType("octopus in tj",octopusin); + RED.nodes.registerType("octopus in",octopusin); } From 70e17a24d9e496856efc673bc4919d795867a7ce Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Mon, 3 Aug 2020 22:25:00 +0100 Subject: [PATCH 06/53] fix octopus.js I fat finger removed the m from msg3 --- octopus.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octopus.js b/octopus.js index b8d0e65..6fbf798 100644 --- a/octopus.js +++ b/octopus.js @@ -115,12 +115,12 @@ module.exports = function(RED) { msg3.payload = []; if (this.tariff == "AGILE") { msg.payload.results.forEach(function(item, index) { - sg3.payload.push([{ value_inc_vat : item.value_inc_vat, + msg3.payload.push([{ value_inc_vat : item.value_inc_vat, "time": new Date(item.valid_from).getTime() *1000 *1000}, {"source" : "Agile"}]); }); } else { msg.payload.results.forEach(function(item, index) { - sg3.payload.push([{ value_inc_vat : item.value_inc_vat, + msg3.payload.push([{ value_inc_vat : item.value_inc_vat, "time": new Date(item.valid_from).getTime() *1000 *1000}, {"source" : "Outgoing"}]); }); } From d27be64ca9d362126dfca43bc5dbe729c6e8215c Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Mon, 3 Aug 2020 22:38:31 +0100 Subject: [PATCH 07/53] Trying to unbreak Agile --- octopus.html | 2 +- octopus.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/octopus.html b/octopus.html index b508a09..f6d8e7a 100644 --- a/octopus.html +++ b/octopus.html @@ -24,7 +24,7 @@
- diff --git a/octopus.js b/octopus.js index 6fbf798..8c61a8e 100644 --- a/octopus.js +++ b/octopus.js @@ -32,10 +32,10 @@ module.exports = function(RED) { var baseurl = ""; - if (this.tariff == "AGILE") { - baseurl = "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-"; - } else { + if (this.tariff == "OUTGOING") { baseurl = "https://api.octopus.energy/v1/products/AGILE-OUTGOING-19-05-13/electricity-tariffs/E-1R-AGILE-OUTGOING-19-05-13-"; + } else { + baseurl = "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-"; } var https = require("https"); var next_run = new Date(0); @@ -113,15 +113,15 @@ module.exports = function(RED) { var msg3 = {}; msg3.payload = []; - if (this.tariff == "AGILE") { + if (this.tariff == "OUTGOING") { msg.payload.results.forEach(function(item, index) { msg3.payload.push([{ value_inc_vat : item.value_inc_vat, - "time": new Date(item.valid_from).getTime() *1000 *1000}, {"source" : "Agile"}]); + "time": new Date(item.valid_from).getTime() *1000 *1000}, {"source" : "Outgoing"}]); }); } else { msg.payload.results.forEach(function(item, index) { msg3.payload.push([{ value_inc_vat : item.value_inc_vat, - "time": new Date(item.valid_from).getTime() *1000 *1000}, {"source" : "Outgoing"}]); + "time": new Date(item.valid_from).getTime() *1000 *1000}, {"source" : "Agile"}]); }); } msg3.measurement = "OctopusPrice"; From 2041923f8f52a265c639451a1b3394e5c7c3e786 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Mon, 3 Aug 2020 22:48:10 +0100 Subject: [PATCH 08/53] Update octopus.js different Outgoing check because everything is coming back as agile --- octopus.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopus.js b/octopus.js index 8c61a8e..d4eb029 100644 --- a/octopus.js +++ b/octopus.js @@ -113,7 +113,7 @@ module.exports = function(RED) { var msg3 = {}; msg3.payload = []; - if (this.tariff == "OUTGOING") { + if (APIurl.includes("OUTGOING")) { msg.payload.results.forEach(function(item, index) { msg3.payload.push([{ value_inc_vat : item.value_inc_vat, "time": new Date(item.valid_from).getTime() *1000 *1000}, {"source" : "Outgoing"}]); From 0fe28df3684b27e558dab81a1a8a5e0c87302668 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Wed, 5 Aug 2020 11:43:18 +0100 Subject: [PATCH 09/53] Try switching to n.tariff --- octopus.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopus.js b/octopus.js index d4eb029..aaa16fb 100644 --- a/octopus.js +++ b/octopus.js @@ -113,7 +113,7 @@ module.exports = function(RED) { var msg3 = {}; msg3.payload = []; - if (APIurl.includes("OUTGOING")) { + if (n.tariff == "OUTGOING") { msg.payload.results.forEach(function(item, index) { msg3.payload.push([{ value_inc_vat : item.value_inc_vat, "time": new Date(item.valid_from).getTime() *1000 *1000}, {"source" : "Outgoing"}]); From 39dbd803c5641e585f18ceb5d0f9676ef2558c75 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Wed, 5 Aug 2020 17:17:22 +0100 Subject: [PATCH 10/53] min/max price block update Documentation and code changes to add selection for min vs max block, and associated calcuation changes. --- octopus.html | 23 +++++++++++++++-------- octopus.js | 48 +++++++++++++++++++++++++----------------------- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/octopus.html b/octopus.html index f6d8e7a..e231b07 100644 --- a/octopus.html +++ b/octopus.html @@ -27,7 +27,13 @@ +
+
+ +
@@ -74,14 +80,14 @@

Outputs

Minimum Price within available data
payload.max_price_inc_vatfloat
Maximum Price within available data
-
min_blocksArray
-
An array of minimum price blocks
+
minmax_blocksArray
+
An array of price blocks, either minimum or maximum depending on option chosen
@@ -89,7 +95,7 @@

Outputs

  • InfluxDB Formatted Data (influxdb out node)
    payloadarray
    -
    Array of data pairs of value and time. The 'source' is set to 'Agile'
    +
    Array of data pairs of value and time. The 'source' is set to 'Agile' or 'Outgoing' depending on the tariff chosen
    measurementstring
    A value for the InfluxDB measurement value (default OctopusPrice). Can be overwritten in the InfluxDB input node
    @@ -120,6 +126,7 @@

    References

    name: {value:"Octopus"}, region: {value:"A"}, tariff: {value:"AGILE"}, + minmax: {value:"MIN"}, numblocks: {value:"4"} }, inputs:1, @@ -128,7 +135,7 @@

    References

    icon: "octopus.png", align: "right", label: function() { - return this.name||this.region||this.tariff; + return this.name||this.region||this.tariff||this.minmax; }, labelStyle: function() { return this.name?"node_label_italic":""; diff --git a/octopus.js b/octopus.js index aaa16fb..324df31 100644 --- a/octopus.js +++ b/octopus.js @@ -25,17 +25,17 @@ module.exports = function(RED) { return parseInt(item.trim()); }); } - - this.region = n.region; - - this.tariff = n.tariff; + - var baseurl = ""; + var baseurl = ""; + var influxDBsource =""; - if (this.tariff == "OUTGOING") { - baseurl = "https://api.octopus.energy/v1/products/AGILE-OUTGOING-19-05-13/electricity-tariffs/E-1R-AGILE-OUTGOING-19-05-13-"; + if (n.tariff == "OUTGOING") { + baseurl = "https://api.octopus.energy/v1/products/AGILE-OUTGOING-19-05-13/electricity-tariffs/E-1R-AGILE-OUTGOING-19-05-13-"; + influxDBsource = {"source" : "Outgoing"}; } else { - baseurl = "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-"; + baseurl = "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-"; + influxDBsource = {"source" : "Agile"}; } var https = require("https"); var next_run = new Date(0); @@ -59,9 +59,9 @@ module.exports = function(RED) { // add start and end used to msg - strip milliseconds msg.start_time = start_time.replace(/\.[0-9]{3}/, ''); msg.end_time = end_time.replace(/\.[0-9]{3}/, ''); - msg.region = this.region; + msg.region = n.region; - var APIurl = baseurl + this.region + '/standard-unit-rates/?' + 'period_from=' + start_time + '&' + 'period_to=' + end_time; + var APIurl = baseurl + n.region + '/standard-unit-rates/?' + 'period_from=' + start_time + '&' + 'period_to=' + end_time; https.get(APIurl, function(res) { msg.rc = res.statusCode; @@ -102,28 +102,30 @@ module.exports = function(RED) { } // blocks are now listed in same order as main data (push each item of an array reverses it) // msg.blocks = blocks_result; - let min_block_start = blocks_result.indexOf(Math.min(...blocks_result)) + block - 1; - msg.min_block_start = min_block_start; - - blocks_output.push({ "min Block Price": Math.min(...blocks_result), "min Block valid From":msg.payload.results[min_block_start].valid_from, "min_block_size_mins": block * 30 }); + let minmax_block_start = ""; + if (n.minmax == "MIN") { + minmax_block_start = blocks_result.indexOf(Math.min(...blocks_result)) + block - 1; + msg.minmax_block_start = minmax_block_start; + blocks_output.push({ "min Block Price": Math.min(...blocks_result), "min Block valid From":msg.payload.results[minmax_block_start].valid_from, "block_size_mins": block * 30 }); + } else if (n.minmax == "MAX") { + minmax_block_start = blocks_result.indexOf(Math.max(...blocks_result)) + block - 1; + msg.minmax_block_start = minmax_block_start; + blocks_output.push({ "Max Block Price": Math.max(...blocks_result), "Max Block valid From":msg.payload.results[minmax_block_start].valid_from, "block_size_mins": block * 30 }); + } + + //blocks_output.push({ "min Block Price": Math.min(...blocks_result), "min Block valid From":msg.payload.results[minmax_block_start].valid_from, "min_block_size_mins": block * 30 }); // msg2.payload.min_block = { "min Block Price": Math.min(...blocks_result), "min Block valid From":msg.payload.results[min_block_start].valid_from, "min_block_size_mins": num_blocks * 30 }; } }); - msg2.payload.min_blocks = blocks_output; + msg2.payload.minmax_blocks = blocks_output; var msg3 = {}; msg3.payload = []; - if (n.tariff == "OUTGOING") { msg.payload.results.forEach(function(item, index) { msg3.payload.push([{ value_inc_vat : item.value_inc_vat, - "time": new Date(item.valid_from).getTime() *1000 *1000}, {"source" : "Outgoing"}]); + "time": new Date(item.valid_from).getTime() *1000 *1000}, influxDBsource]); }); - } else { - msg.payload.results.forEach(function(item, index) { - msg3.payload.push([{ value_inc_vat : item.value_inc_vat, - "time": new Date(item.valid_from).getTime() *1000 *1000}, {"source" : "Agile"}]); - }); - } + msg3.measurement = "OctopusPrice"; next_run = next_half_hour; From a4c65fefa558413f664a6b5d0e6c7cbecb7ba0cb Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Wed, 5 Aug 2020 17:27:31 +0100 Subject: [PATCH 11/53] Update documentation for clarity --- octopus.html | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/octopus.html b/octopus.html index e231b07..fdac187 100644 --- a/octopus.html +++ b/octopus.html @@ -30,11 +30,12 @@
  • - - + + +
    Whether to calculate the minimum or maximum priced block using the Period length below.
    From c99aa12321c3753c0167f0bee7d025ec59055498 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Wed, 5 Aug 2020 17:38:31 +0100 Subject: [PATCH 12/53] Removed min_block_start from output 1 Not required --- octopus.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/octopus.js b/octopus.js index 324df31..9aa3f05 100644 --- a/octopus.js +++ b/octopus.js @@ -105,11 +105,9 @@ module.exports = function(RED) { let minmax_block_start = ""; if (n.minmax == "MIN") { minmax_block_start = blocks_result.indexOf(Math.min(...blocks_result)) + block - 1; - msg.minmax_block_start = minmax_block_start; blocks_output.push({ "min Block Price": Math.min(...blocks_result), "min Block valid From":msg.payload.results[minmax_block_start].valid_from, "block_size_mins": block * 30 }); } else if (n.minmax == "MAX") { minmax_block_start = blocks_result.indexOf(Math.max(...blocks_result)) + block - 1; - msg.minmax_block_start = minmax_block_start; blocks_output.push({ "Max Block Price": Math.max(...blocks_result), "Max Block valid From":msg.payload.results[minmax_block_start].valid_from, "block_size_mins": block * 30 }); } From 9b025554d790537c454362a9d6afa446771c31f2 Mon Sep 17 00:00:00 2001 From: Toby Saunders Date: Wed, 19 Aug 2020 22:26:10 +0100 Subject: [PATCH 13/53] Consumption with API v0.1 --- octopus.html | 22 ++++++++++++++-------- octopus.js | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/octopus.html b/octopus.html index fdac187..b3303ad 100644 --- a/octopus.html +++ b/octopus.html @@ -41,10 +41,14 @@
    - +
    + + +
    +
    + + +
    The Period length is the number of 30 minute blocks to average to find cheapest period of that length (e.g. 2,4 for 60 min and 120min periods).
    @@ -128,15 +132,17 @@

    References

    region: {value:"A"}, tariff: {value:"AGILE"}, minmax: {value:"MIN"}, - numblocks: {value:"4"} + numblocks: {value:"4"}, + apikey: {value:"none"}, + consupmtionurl: {value:"none"} }, inputs:1, - outputs:3, - outputLabels: ["raw","processed","influxdb"], + outputs:4, + outputLabels: ["raw","processed","influxdb","influxdbconsumption], icon: "octopus.png", align: "right", label: function() { - return this.name||this.region||this.tariff||this.minmax; + return this.name||this.region||this.tariff||this.minmax||this.apikey; }, labelStyle: function() { return this.name?"node_label_italic":""; diff --git a/octopus.js b/octopus.js index 9aa3f05..b80ddce 100644 --- a/octopus.js +++ b/octopus.js @@ -29,6 +29,7 @@ module.exports = function(RED) { var baseurl = ""; var influxDBsource =""; + var consumptionDBsource = {"source" : "Agile"}; if (n.tariff == "OUTGOING") { baseurl = "https://api.octopus.energy/v1/products/AGILE-OUTGOING-19-05-13/electricity-tariffs/E-1R-AGILE-OUTGOING-19-05-13-"; @@ -127,12 +128,49 @@ module.exports = function(RED) { msg3.measurement = "OctopusPrice"; next_run = next_half_hour; + + + var msg4 = {}; + var outputx = {}; + if (n.apikey != "none") { + https.get(n.consumptionurl, function(res) { + outputx.rc = res.statusCode; + outputx.payload = ""; + res.setEncoding('utf8'); + res.on('data', function(chunk) { + outputx.payload += chunk; + }); + res.on('end', function() { + if (outputx.rc === 200) { + try { + outputx.payload = JSON.parse(outputx.payload); + // Extract the inc VAt prices into an Array + outputx.consumption_array = outputx.payload.results.map(a => a.consumption); + // map returns results in reverse (probably includes a push) - put back in same order as main data. + outputx.price_array.reverse(); + + msg4.payload = []; + outputx.payload.results.forEach(function(item, index) { + msg4.payload.push([{ consumption : item.consumption, + "time": new Date(item.interval_start).getTime() * 1000 * 1000}, consumptionDBsource]); + }); + msg4.measurement = "OctopusConsumption"; + + + } + + + + + + + } catch(err) { node.error(err,msg); // Failed to parse, pass it on } // set time for next request on success - node.send([msg, msg2, msg3]); + node.send([msg, msg2, msg3, msg4]); } }); }).on('error', function(e) { From fc3fcc10d4d48256191e9901487278c561b2a7fa Mon Sep 17 00:00:00 2001 From: Toby Saunders Date: Wed, 19 Aug 2020 22:39:07 +0100 Subject: [PATCH 14/53] Close all the brackets --- octopus.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/octopus.js b/octopus.js index b80ddce..f8d330a 100644 --- a/octopus.js +++ b/octopus.js @@ -155,8 +155,16 @@ module.exports = function(RED) { "time": new Date(item.interval_start).getTime() * 1000 * 1000}, consumptionDBsource]); }); msg4.measurement = "OctopusConsumption"; + } catch(err) { + node.error(err,msg); + // Failed to parse, pass it on + } + } - + }); + }).on('error', function(e) { + node.error(e,msg); + }); } From caa3975fa6913973f4e76fb07d8068b8b18fb751 Mon Sep 17 00:00:00 2001 From: Toby Saunders Date: Wed, 19 Aug 2020 22:51:09 +0100 Subject: [PATCH 15/53] Fix spelling mistakes --- octopus.html | 4 ++-- octopus.js | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/octopus.html b/octopus.html index b3303ad..209a578 100644 --- a/octopus.html +++ b/octopus.html @@ -134,7 +134,7 @@

    References

    minmax: {value:"MIN"}, numblocks: {value:"4"}, apikey: {value:"none"}, - consupmtionurl: {value:"none"} + consumptionurl: {value:"none"} }, inputs:1, outputs:4, @@ -142,7 +142,7 @@

    References

    icon: "octopus.png", align: "right", label: function() { - return this.name||this.region||this.tariff||this.minmax||this.apikey; + return this.name||this.region||this.tariff||this.minmax||this.apikey||this.consumptionurl; }, labelStyle: function() { return this.name?"node_label_italic":""; diff --git a/octopus.js b/octopus.js index f8d330a..3d84188 100644 --- a/octopus.js +++ b/octopus.js @@ -144,10 +144,6 @@ module.exports = function(RED) { if (outputx.rc === 200) { try { outputx.payload = JSON.parse(outputx.payload); - // Extract the inc VAt prices into an Array - outputx.consumption_array = outputx.payload.results.map(a => a.consumption); - // map returns results in reverse (probably includes a push) - put back in same order as main data. - outputx.price_array.reverse(); msg4.payload = []; outputx.payload.results.forEach(function(item, index) { From 3f575bfa94a6890cbf254c2a40596fd70da3b5f2 Mon Sep 17 00:00:00 2001 From: Toby Saunders Date: Wed, 19 Aug 2020 23:01:43 +0100 Subject: [PATCH 16/53] More spelling mistakes --- octopus.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopus.html b/octopus.html index 209a578..3362624 100644 --- a/octopus.html +++ b/octopus.html @@ -138,7 +138,7 @@

    References

    }, inputs:1, outputs:4, - outputLabels: ["raw","processed","influxdb","influxdbconsumption], + outputLabels: ["raw","processed","influxdb","influxdbconsumption"], icon: "octopus.png", align: "right", label: function() { From 2ec63a6ce05a9ac56a38818eee8454bb1fdc1ce6 Mon Sep 17 00:00:00 2001 From: Toby Saunders Date: Wed, 19 Aug 2020 23:23:32 +0100 Subject: [PATCH 17/53] Authentication on Consumption request --- octopus.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/octopus.js b/octopus.js index 3d84188..33fc017 100644 --- a/octopus.js +++ b/octopus.js @@ -63,7 +63,7 @@ module.exports = function(RED) { msg.region = n.region; var APIurl = baseurl + n.region + '/standard-unit-rates/?' + 'period_from=' + start_time + '&' + 'period_to=' + end_time; - + https.get(APIurl, function(res) { msg.rc = res.statusCode; msg.payload = ""; @@ -133,7 +133,17 @@ module.exports = function(RED) { var msg4 = {}; var outputx = {}; if (n.apikey != "none") { - https.get(n.consumptionurl, function(res) { + + var options = { + host: 'api.octopus.energy', + port: 443, + path: n.consumptionurl, + // authentication headers + headers: { + 'Authorization': 'Basic ' + new Buffer(n.apikey + ':').toString('base64') + } + }; + https.get(options, function(res) { outputx.rc = res.statusCode; outputx.payload = ""; res.setEncoding('utf8'); From 3c2f49d12071edcf3c9b25f07ede010a765be535 Mon Sep 17 00:00:00 2001 From: Toby Saunders Date: Wed, 19 Aug 2020 23:31:00 +0100 Subject: [PATCH 18/53] Tightened error handling --- octopus.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octopus.js b/octopus.js index 33fc017..e12f56b 100644 --- a/octopus.js +++ b/octopus.js @@ -162,14 +162,14 @@ module.exports = function(RED) { }); msg4.measurement = "OctopusConsumption"; } catch(err) { - node.error(err,msg); + node.error(err,outputx); // Failed to parse, pass it on } } }); }).on('error', function(e) { - node.error(e,msg); + node.error(e,outputx); }); } From 04152d777d8d5b7fda789c01655e90e2f57861d3 Mon Sep 17 00:00:00 2001 From: Toby Saunders Date: Wed, 19 Aug 2020 23:36:28 +0100 Subject: [PATCH 19/53] Removed overriding scope, added protocol to url --- octopus.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/octopus.js b/octopus.js index e12f56b..7744179 100644 --- a/octopus.js +++ b/octopus.js @@ -135,7 +135,7 @@ module.exports = function(RED) { if (n.apikey != "none") { var options = { - host: 'api.octopus.energy', + host: 'https://api.octopus.energy', port: 443, path: n.consumptionurl, // authentication headers @@ -143,14 +143,14 @@ module.exports = function(RED) { 'Authorization': 'Basic ' + new Buffer(n.apikey + ':').toString('base64') } }; - https.get(options, function(res) { - outputx.rc = res.statusCode; + https.get(options, function(resc) { + outputx.rc = resc.statusCode; outputx.payload = ""; - res.setEncoding('utf8'); - res.on('data', function(chunk) { + resc.setEncoding('utf8'); + resc.on('data', function(chunk) { outputx.payload += chunk; }); - res.on('end', function() { + resc.on('end', function() { if (outputx.rc === 200) { try { outputx.payload = JSON.parse(outputx.payload); From 122241fe3603bd9bcbc9d65f32f428c094926423 Mon Sep 17 00:00:00 2001 From: Toby Saunders Date: Wed, 19 Aug 2020 23:49:25 +0100 Subject: [PATCH 20/53] Trying to get errors to show --- octopus.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/octopus.js b/octopus.js index 7744179..bc85c7a 100644 --- a/octopus.js +++ b/octopus.js @@ -135,12 +135,12 @@ module.exports = function(RED) { if (n.apikey != "none") { var options = { - host: 'https://api.octopus.energy', + host: 'api.octopus.energy', port: 443, path: n.consumptionurl, // authentication headers headers: { - 'Authorization': 'Basic ' + new Buffer(n.apikey + ':').toString('base64') + 'Authorization' : 'Basic ' + new Buffer(n.apikey + ':').toString('base64') } }; https.get(options, function(resc) { @@ -165,6 +165,8 @@ module.exports = function(RED) { node.error(err,outputx); // Failed to parse, pass it on } + } else { + console.log(outputx.payload); } }); From 8688dabf72daa1974bb3d8b3d3cab4430a26898e Mon Sep 17 00:00:00 2001 From: Toby Saunders Date: Wed, 19 Aug 2020 23:53:07 +0100 Subject: [PATCH 21/53] Same again --- octopus.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopus.js b/octopus.js index bc85c7a..112b0bd 100644 --- a/octopus.js +++ b/octopus.js @@ -166,7 +166,7 @@ module.exports = function(RED) { // Failed to parse, pass it on } } else { - console.log(outputx.payload); + msg4.payload = outputx.payload; } }); From f9ebb7f92d1acb83ec0439cf2b77de5cf1064517 Mon Sep 17 00:00:00 2001 From: Toby Saunders Date: Thu, 20 Aug 2020 08:38:05 +0100 Subject: [PATCH 22/53] Update octopus.js --- octopus.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/octopus.js b/octopus.js index 112b0bd..a63c270 100644 --- a/octopus.js +++ b/octopus.js @@ -173,6 +173,8 @@ module.exports = function(RED) { }).on('error', function(e) { node.error(e,outputx); }); + } else { + msg4 = msg3; } From 212fb708949efb9ed75bd8db62659485cf41d36e Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Thu, 20 Aug 2020 22:22:01 +0100 Subject: [PATCH 23/53] Troubleshooting --- octopus.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octopus.js b/octopus.js index a63c270..be48035 100644 --- a/octopus.js +++ b/octopus.js @@ -140,7 +140,7 @@ module.exports = function(RED) { path: n.consumptionurl, // authentication headers headers: { - 'Authorization' : 'Basic ' + new Buffer(n.apikey + ':').toString('base64') + 'Authorization': 'Basic ' + new Buffer(n.apikey).toString('base64') } }; https.get(options, function(resc) { @@ -168,7 +168,7 @@ module.exports = function(RED) { } else { msg4.payload = outputx.payload; } - + msg4.payload = outputx.payload; }); }).on('error', function(e) { node.error(e,outputx); From a2184fd03446714c603aeecca8a5abe0331df0cc Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Thu, 20 Aug 2020 22:24:57 +0100 Subject: [PATCH 24/53] Update octopus.js --- octopus.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/octopus.js b/octopus.js index be48035..4146b30 100644 --- a/octopus.js +++ b/octopus.js @@ -145,10 +145,11 @@ module.exports = function(RED) { }; https.get(options, function(resc) { outputx.rc = resc.statusCode; - outputx.payload = ""; + outputx.payload = []; resc.setEncoding('utf8'); resc.on('data', function(chunk) { outputx.payload += chunk; + msg4.payload = []; }); resc.on('end', function() { if (outputx.rc === 200) { @@ -165,10 +166,7 @@ module.exports = function(RED) { node.error(err,outputx); // Failed to parse, pass it on } - } else { - msg4.payload = outputx.payload; - } - msg4.payload = outputx.payload; + }); }).on('error', function(e) { node.error(e,outputx); From c75c574c35d01aa67b0e08a59c3902d1604917cd Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Thu, 20 Aug 2020 22:27:23 +0100 Subject: [PATCH 25/53] Debug logging --- octopus.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/octopus.js b/octopus.js index 4146b30..62cbbe6 100644 --- a/octopus.js +++ b/octopus.js @@ -143,19 +143,26 @@ module.exports = function(RED) { 'Authorization': 'Basic ' + new Buffer(n.apikey).toString('base64') } }; + console.log("1"); https.get(options, function(resc) { + console.log("2"); outputx.rc = resc.statusCode; + console.log(outputx.rc); outputx.payload = []; resc.setEncoding('utf8'); resc.on('data', function(chunk) { + console.log("3"); outputx.payload += chunk; msg4.payload = []; }); + console.log("4"); resc.on('end', function() { + console.log("5"); if (outputx.rc === 200) { + console.log("6"); try { outputx.payload = JSON.parse(outputx.payload); - + console.log("8"); msg4.payload = []; outputx.payload.results.forEach(function(item, index) { msg4.payload.push([{ consumption : item.consumption, @@ -166,6 +173,9 @@ module.exports = function(RED) { node.error(err,outputx); // Failed to parse, pass it on } + } else { + console.log("7"); + } }); }).on('error', function(e) { From 5ea63659f66c62fadf25e0b007eafa7a9608ddb1 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Thu, 20 Aug 2020 22:34:25 +0100 Subject: [PATCH 26/53] Update octopus.js --- octopus.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/octopus.js b/octopus.js index 62cbbe6..a3378b0 100644 --- a/octopus.js +++ b/octopus.js @@ -71,6 +71,7 @@ module.exports = function(RED) { res.on('data', function(chunk) { msg.payload += chunk; }); + var msg4 = {}; res.on('end', function() { if (msg.rc === 200) { try { @@ -143,25 +144,22 @@ module.exports = function(RED) { 'Authorization': 'Basic ' + new Buffer(n.apikey).toString('base64') } }; - console.log("1"); + https.get(options, function(resc) { - console.log("2"); outputx.rc = resc.statusCode; console.log(outputx.rc); outputx.payload = []; resc.setEncoding('utf8'); resc.on('data', function(chunk) { - console.log("3"); outputx.payload += chunk; msg4.payload = []; }); console.log("4"); resc.on('end', function() { - console.log("5"); if (outputx.rc === 200) { - console.log("6"); try { outputx.payload = JSON.parse(outputx.payload); + console.log(outputx.payload); console.log("8"); msg4.payload = []; outputx.payload.results.forEach(function(item, index) { From 12e870b05e8139fe5d14b2f1a388f3dea678d9ff Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Thu, 20 Aug 2020 22:42:34 +0100 Subject: [PATCH 27/53] Update octopus.js --- octopus.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/octopus.js b/octopus.js index a3378b0..6daac59 100644 --- a/octopus.js +++ b/octopus.js @@ -131,7 +131,7 @@ module.exports = function(RED) { next_run = next_half_hour; - var msg4 = {}; + var outputx = {}; if (n.apikey != "none") { @@ -153,8 +153,7 @@ module.exports = function(RED) { resc.on('data', function(chunk) { outputx.payload += chunk; msg4.payload = []; - }); - console.log("4"); + }); resc.on('end', function() { if (outputx.rc === 200) { try { @@ -179,9 +178,7 @@ module.exports = function(RED) { }).on('error', function(e) { node.error(e,outputx); }); - } else { - msg4 = msg3; - } + } From 4a57880b43b1084601747c110de46a978a573da6 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Thu, 20 Aug 2020 23:00:35 +0100 Subject: [PATCH 28/53] Update octopus.js --- octopus.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/octopus.js b/octopus.js index 6daac59..bfd66eb 100644 --- a/octopus.js +++ b/octopus.js @@ -121,10 +121,9 @@ module.exports = function(RED) { var msg3 = {}; msg3.payload = []; - msg.payload.results.forEach(function(item, index) { - msg3.payload.push([{ value_inc_vat : item.value_inc_vat, - "time": new Date(item.valid_from).getTime() *1000 *1000}, influxDBsource]); - }); + msg.payload.results.forEach(function(item, index) { + msg3.payload.push([{ value_inc_vat : item.value_inc_vat, "time": new Date(item.valid_from).getTime() *1000 *1000}, influxDBsource]); + }); msg3.measurement = "OctopusPrice"; @@ -161,13 +160,14 @@ module.exports = function(RED) { console.log(outputx.payload); console.log("8"); msg4.payload = []; - outputx.payload.results.forEach(function(item, index) { - msg4.payload.push([{ consumption : item.consumption, - "time": new Date(item.interval_start).getTime() * 1000 * 1000}, consumptionDBsource]); - }); + outputx.payload.results.forEach(function(item, index) { + console.log(item); + msg4.payload.push([{ consumption : item.consumption, "time": new Date(item.interval_start).getTime() *1000 *1000}, consumptionDBsource]); + }); msg4.measurement = "OctopusConsumption"; } catch(err) { node.error(err,outputx); + console.log("Error 1"); // Failed to parse, pass it on } } else { @@ -177,6 +177,7 @@ module.exports = function(RED) { }); }).on('error', function(e) { node.error(e,outputx); + console.log("Error 2"); }); } From c1d4909c927844438fc80db4e0063a200d07aa75 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Thu, 20 Aug 2020 23:14:57 +0100 Subject: [PATCH 29/53] Update octopus.js --- octopus.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/octopus.js b/octopus.js index bfd66eb..9943543 100644 --- a/octopus.js +++ b/octopus.js @@ -157,11 +157,9 @@ module.exports = function(RED) { if (outputx.rc === 200) { try { outputx.payload = JSON.parse(outputx.payload); - console.log(outputx.payload); console.log("8"); msg4.payload = []; - outputx.payload.results.forEach(function(item, index) { - console.log(item); + outputx.payload.results.forEach(function(item, index) { msg4.payload.push([{ consumption : item.consumption, "time": new Date(item.interval_start).getTime() *1000 *1000}, consumptionDBsource]); }); msg4.measurement = "OctopusConsumption"; From f3e00f51978e9a21c52e009b2f55065631c964db Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Thu, 20 Aug 2020 23:21:20 +0100 Subject: [PATCH 30/53] Update octopus.js --- octopus.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/octopus.js b/octopus.js index 9943543..76d9a93 100644 --- a/octopus.js +++ b/octopus.js @@ -151,7 +151,6 @@ module.exports = function(RED) { resc.setEncoding('utf8'); resc.on('data', function(chunk) { outputx.payload += chunk; - msg4.payload = []; }); resc.on('end', function() { if (outputx.rc === 200) { @@ -159,10 +158,14 @@ module.exports = function(RED) { outputx.payload = JSON.parse(outputx.payload); console.log("8"); msg4.payload = []; + console.log(msg4.payload); outputx.payload.results.forEach(function(item, index) { msg4.payload.push([{ consumption : item.consumption, "time": new Date(item.interval_start).getTime() *1000 *1000}, consumptionDBsource]); }); + console.log(msg4.payload); + msg4.measurement = "OctopusConsumption"; + console.log(msg4.measurement); } catch(err) { node.error(err,outputx); console.log("Error 1"); From 14f758f127cb690b239b3767556c62572929e192 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Thu, 20 Aug 2020 23:29:03 +0100 Subject: [PATCH 31/53] Move node.send --- octopus.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/octopus.js b/octopus.js index 76d9a93..1bdf536 100644 --- a/octopus.js +++ b/octopus.js @@ -71,7 +71,6 @@ module.exports = function(RED) { res.on('data', function(chunk) { msg.payload += chunk; }); - var msg4 = {}; res.on('end', function() { if (msg.rc === 200) { try { @@ -161,11 +160,9 @@ module.exports = function(RED) { console.log(msg4.payload); outputx.payload.results.forEach(function(item, index) { msg4.payload.push([{ consumption : item.consumption, "time": new Date(item.interval_start).getTime() *1000 *1000}, consumptionDBsource]); - }); - console.log(msg4.payload); - + }); msg4.measurement = "OctopusConsumption"; - console.log(msg4.measurement); + node.send([msg, msg2, msg3, msg4]); } catch(err) { node.error(err,outputx); console.log("Error 1"); @@ -180,7 +177,9 @@ module.exports = function(RED) { node.error(e,outputx); console.log("Error 2"); }); - } + } else { + node.send([msg, msg2, msg3, msg4]); + } @@ -193,7 +192,7 @@ module.exports = function(RED) { // Failed to parse, pass it on } // set time for next request on success - node.send([msg, msg2, msg3, msg4]); + } }); }).on('error', function(e) { From 40ec82b882ef57c647eef511ce47614e46fc1e83 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Thu, 20 Aug 2020 23:36:02 +0100 Subject: [PATCH 32/53] Define msg4 --- octopus.js | 1 + 1 file changed, 1 insertion(+) diff --git a/octopus.js b/octopus.js index 1bdf536..8fafb22 100644 --- a/octopus.js +++ b/octopus.js @@ -131,6 +131,7 @@ module.exports = function(RED) { var outputx = {}; + var msg4 = {}; if (n.apikey != "none") { var options = { From 26b519995b9ae9c28db826e538dbffbfea434dfe Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Wed, 26 Aug 2020 11:58:08 +0100 Subject: [PATCH 33/53] Removed Debug logging --- octopus.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/octopus.js b/octopus.js index 8fafb22..562c79c 100644 --- a/octopus.js +++ b/octopus.js @@ -145,8 +145,7 @@ module.exports = function(RED) { }; https.get(options, function(resc) { - outputx.rc = resc.statusCode; - console.log(outputx.rc); + outputx.rc = resc.statusCode; outputx.payload = []; resc.setEncoding('utf8'); resc.on('data', function(chunk) { @@ -156,9 +155,8 @@ module.exports = function(RED) { if (outputx.rc === 200) { try { outputx.payload = JSON.parse(outputx.payload); - console.log("8"); msg4.payload = []; - console.log(msg4.payload); + outputx.payload.results.forEach(function(item, index) { msg4.payload.push([{ consumption : item.consumption, "time": new Date(item.interval_start).getTime() *1000 *1000}, consumptionDBsource]); }); @@ -166,17 +164,13 @@ module.exports = function(RED) { node.send([msg, msg2, msg3, msg4]); } catch(err) { node.error(err,outputx); - console.log("Error 1"); // Failed to parse, pass it on } - } else { - console.log("7"); - } + } }); }).on('error', function(e) { node.error(e,outputx); - console.log("Error 2"); }); } else { node.send([msg, msg2, msg3, msg4]); From b19f3949e8729dcc288af4bfb8b56d36febac469 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Wed, 16 Sep 2020 20:34:42 +0100 Subject: [PATCH 34/53] Changed .html to hide apikey --- octopus.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopus.html b/octopus.html index 3362624..2d8f16a 100644 --- a/octopus.html +++ b/octopus.html @@ -43,7 +43,7 @@
    - +
    From 7e21f53e904b14d671d27a0ebc0259989f3669ab Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Tue, 13 Oct 2020 14:35:11 +0100 Subject: [PATCH 35/53] fix JSON Key spaces --- octopus.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octopus.js b/octopus.js index 562c79c..9da9a5d 100644 --- a/octopus.js +++ b/octopus.js @@ -106,10 +106,10 @@ module.exports = function(RED) { let minmax_block_start = ""; if (n.minmax == "MIN") { minmax_block_start = blocks_result.indexOf(Math.min(...blocks_result)) + block - 1; - blocks_output.push({ "min Block Price": Math.min(...blocks_result), "min Block valid From":msg.payload.results[minmax_block_start].valid_from, "block_size_mins": block * 30 }); + blocks_output.push({ "min_block_price": Math.min(...blocks_result), "min_block_valid_from":msg.payload.results[minmax_block_start].valid_from, "block_size_mins": block * 30 }); } else if (n.minmax == "MAX") { minmax_block_start = blocks_result.indexOf(Math.max(...blocks_result)) + block - 1; - blocks_output.push({ "Max Block Price": Math.max(...blocks_result), "Max Block valid From":msg.payload.results[minmax_block_start].valid_from, "block_size_mins": block * 30 }); + blocks_output.push({ "max_block_price": Math.max(...blocks_result), "max_block_valid_from":msg.payload.results[minmax_block_start].valid_from, "block_size_mins": block * 30 }); } //blocks_output.push({ "min Block Price": Math.min(...blocks_result), "min Block valid From":msg.payload.results[minmax_block_start].valid_from, "min_block_size_mins": block * 30 }); From 825a6beb221a4d38941d98bf3edadff634abe7f0 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Mon, 16 Aug 2021 15:19:51 +0100 Subject: [PATCH 36/53] Added Octopus Go (test) --- octopus.html | 3 ++- octopus.js | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/octopus.html b/octopus.html index 2d8f16a..d3f7e18 100644 --- a/octopus.html +++ b/octopus.html @@ -27,6 +27,7 @@
    @@ -109,7 +110,7 @@

    Outputs

    Details

    -

    Query the Octopus Agile (or Agile Outgoing) API for future pricing. +

    Query the Octopus Agile, Octopus Go (or Agile Outgoing) API for future pricing.

    The pricing data is broken up into 30 min periods. The data for the next 24Hrs (23:00Z - 23:00Z) is released at approximately 16:00Z. The request is set to obtain all data available from now so the number of data periods returned by the API varies between approximately 15 and 63. diff --git a/octopus.js b/octopus.js index 9da9a5d..a69ca1a 100644 --- a/octopus.js +++ b/octopus.js @@ -20,8 +20,8 @@ module.exports = function(RED) { var node = this; var num_blocks = []; - if (n.numblocks !== undefined) { num_blocks = n.numblocks.split(",").map(function(item) { + if (n.numblocks !== undefined) { return parseInt(item.trim()); }); } @@ -34,9 +34,12 @@ module.exports = function(RED) { if (n.tariff == "OUTGOING") { baseurl = "https://api.octopus.energy/v1/products/AGILE-OUTGOING-19-05-13/electricity-tariffs/E-1R-AGILE-OUTGOING-19-05-13-"; influxDBsource = {"source" : "Outgoing"}; - } else { + } else if (n.tariff == "AGILE") { baseurl = "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-"; influxDBsource = {"source" : "Agile"}; + } else { + baseurl = "https://api.octopus.energy/v1/products/GO-21-05-13/electricity-tariffs/E-1R-GO-21-05-13-"; + influxDBsource = {"source" : "Go"}; } var https = require("https"); var next_run = new Date(0); @@ -58,7 +61,7 @@ module.exports = function(RED) { msg2.payload = {}; // add start and end used to msg - strip milliseconds - msg.start_time = start_time.replace(/\.[0-9]{3}/, ''); + msg.start_time = start_time.replace(/\.[0-9]{3}/, '');n msg.end_time = end_time.replace(/\.[0-9]{3}/, ''); msg.region = n.region; From 0d4b5805863a724c0488dcd491221ba6368dfdc5 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Mon, 16 Aug 2021 15:24:09 +0100 Subject: [PATCH 37/53] Update octopus.js --- octopus.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopus.js b/octopus.js index a69ca1a..73a03c3 100644 --- a/octopus.js +++ b/octopus.js @@ -23,7 +23,7 @@ module.exports = function(RED) { num_blocks = n.numblocks.split(",").map(function(item) { if (n.numblocks !== undefined) { return parseInt(item.trim()); - }); + }; } From dd24affdbcb66b5b0c9ce82ba82104780214760e Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Mon, 16 Aug 2021 15:35:23 +0100 Subject: [PATCH 38/53] Update octopus.js --- octopus.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopus.js b/octopus.js index 73a03c3..1f70fe6 100644 --- a/octopus.js +++ b/octopus.js @@ -24,7 +24,7 @@ module.exports = function(RED) { if (n.numblocks !== undefined) { return parseInt(item.trim()); }; - } + }); var baseurl = ""; From 17098bb3caafe3c85054bf39cd7a5db9d4968d14 Mon Sep 17 00:00:00 2001 From: tjsaunders Date: Fri, 24 Dec 2021 20:07:17 +0000 Subject: [PATCH 39/53] Remove random "n" from octopus.js --- octopus.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopus.js b/octopus.js index 1f70fe6..34e5cd8 100644 --- a/octopus.js +++ b/octopus.js @@ -61,7 +61,7 @@ module.exports = function(RED) { msg2.payload = {}; // add start and end used to msg - strip milliseconds - msg.start_time = start_time.replace(/\.[0-9]{3}/, '');n + msg.start_time = start_time.replace(/\.[0-9]{3}/, ''); msg.end_time = end_time.replace(/\.[0-9]{3}/, ''); msg.region = n.region; From 6e29bce352719e65ebebf87683e03df39e153a74 Mon Sep 17 00:00:00 2001 From: tjsaunders Date: Fri, 24 Dec 2021 20:45:45 +0000 Subject: [PATCH 40/53] sysout apiurl --- octopus.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/octopus.js b/octopus.js index 34e5cd8..a2e338a 100644 --- a/octopus.js +++ b/octopus.js @@ -67,6 +67,7 @@ module.exports = function(RED) { var APIurl = baseurl + n.region + '/standard-unit-rates/?' + 'period_from=' + start_time + '&' + 'period_to=' + end_time; + print(APIurl); https.get(APIurl, function(res) { msg.rc = res.statusCode; msg.payload = ""; @@ -187,6 +188,8 @@ module.exports = function(RED) { } catch(err) { node.error(err,msg); + + // Failed to parse, pass it on } // set time for next request on success From 595326bdb3bb1b622bcdf817d1d7a14da83bf711 Mon Sep 17 00:00:00 2001 From: tjsaunders Date: Fri, 24 Dec 2021 21:14:50 +0000 Subject: [PATCH 41/53] again --- octopus.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octopus.js b/octopus.js index a2e338a..a6b8db8 100644 --- a/octopus.js +++ b/octopus.js @@ -67,7 +67,7 @@ module.exports = function(RED) { var APIurl = baseurl + n.region + '/standard-unit-rates/?' + 'period_from=' + start_time + '&' + 'period_to=' + end_time; - print(APIurl); + console.log(APIurl); https.get(APIurl, function(res) { msg.rc = res.statusCode; msg.payload = ""; @@ -188,7 +188,7 @@ module.exports = function(RED) { } catch(err) { node.error(err,msg); - + // Failed to parse, pass it on } From d175f6209f01d846ff37aa20a5045b3b89ea91a4 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Thu, 18 Aug 2022 18:29:17 +0100 Subject: [PATCH 42/53] Added base url form field --- octopus.html | 4 ++++ octopus.js | 15 +++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/octopus.html b/octopus.html index d3f7e18..1adb3a5 100644 --- a/octopus.html +++ b/octopus.html @@ -29,6 +29,10 @@ +

    +
    + +
    diff --git a/octopus.js b/octopus.js index a6b8db8..b0504aa 100644 --- a/octopus.js +++ b/octopus.js @@ -27,18 +27,25 @@ module.exports = function(RED) { }); - var baseurl = ""; + var baseurl = n.baseurl; var influxDBsource =""; var consumptionDBsource = {"source" : "Agile"}; + if (n.tariff == "OUTGOING") { - baseurl = "https://api.octopus.energy/v1/products/AGILE-OUTGOING-19-05-13/electricity-tariffs/E-1R-AGILE-OUTGOING-19-05-13-"; + if (n.baseurl == "") { + baseurl = "https://api.octopus.energy/v1/products/AGILE-OUTGOING-19-05-13/electricity-tariffs/E-1R-AGILE-OUTGOING-19-05-13-"; + } influxDBsource = {"source" : "Outgoing"}; } else if (n.tariff == "AGILE") { - baseurl = "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-"; + if (n.baseurl == "") { + baseurl = "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-"; + } influxDBsource = {"source" : "Agile"}; } else { - baseurl = "https://api.octopus.energy/v1/products/GO-21-05-13/electricity-tariffs/E-1R-GO-21-05-13-"; + if (n.baseurl == "") { + baseurl = "https://api.octopus.energy/v1/products/GO-22-07-05/electricity-tariffs/E-1R-GO-22-07-05-"; + } influxDBsource = {"source" : "Go"}; } var https = require("https"); From a181c8389c5c8df6eb6f636461fc6bc2fa42847c Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Thu, 18 Aug 2022 18:38:22 +0100 Subject: [PATCH 43/53] Fix .html omission --- octopus.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/octopus.html b/octopus.html index 1adb3a5..841d173 100644 --- a/octopus.html +++ b/octopus.html @@ -135,6 +135,7 @@

    References

    defaults: { name: {value:"Octopus"}, region: {value:"A"}, + baseurl: {value:""}, tariff: {value:"AGILE"}, minmax: {value:"MIN"}, numblocks: {value:"4"}, @@ -147,7 +148,7 @@

    References

    icon: "octopus.png", align: "right", label: function() { - return this.name||this.region||this.tariff||this.minmax||this.apikey||this.consumptionurl; + return this.name||this.region||this.baseurl||this.tariff||this.minmax||this.apikey||this.consumptionurl; }, labelStyle: function() { return this.name?"node_label_italic":""; From 02a5021b53a3ef40c3bfe0a61d3d65bf7c9f8579 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Fri, 28 Oct 2022 12:19:02 +0100 Subject: [PATCH 44/53] Add identifier functionality --- octopus.html | 19 ++++++-- octopus.js | 8 ++-- test.html | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+), 9 deletions(-) create mode 100644 test.html diff --git a/octopus.html b/octopus.html index 841d173..bd54c91 100644 --- a/octopus.html +++ b/octopus.html @@ -2,6 +2,10 @@
    +
    +
    + +
    @@ -33,7 +37,9 @@
    +
    +
    Example: https://api.octopus.energy/v1/products/GO-22-03-29/electricity-tariffs/E-1R-GO-22-03-29-
    -
    +
    +
    The Period length is the number of 30 minute blocks to average to find cheapest period of that length (e.g. 2,4 for 60 min and 120min periods).
    @@ -53,8 +60,9 @@
    -
    -
    The Period length is the number of 30 minute blocks to average to find cheapest period of that length (e.g. 2,4 for 60 min and 120min periods).
    +
    +
    Example: /v1/electricity-meter-points/1419009111000/meters/IDENTIFIER/consumption/?page_size=5000
    + + + From 1862c89d3f405e2593edb212d2a1b9e7ca8123ed Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Sat, 29 Oct 2022 17:34:15 +0100 Subject: [PATCH 47/53] Update Influxdb output --- octopus.html | 6 +++--- octopus.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/octopus.html b/octopus.html index 941de6f..8b0ee44 100644 --- a/octopus.html +++ b/octopus.html @@ -61,7 +61,7 @@ -
    Example: /v1/electricity-meter-points/IDENTIFIER/meters/IDENTIFIER/consumption/?page_size=5000
    +
    Example: /v1/electricity-meter-points/MPAN/meters/SERIAL/consumption/?page_size=5000
    @@ -148,8 +148,8 @@

    References

    minmax: {value:"MIN"}, numblocks: {value:"4"}, apikey: {value:"none"}, - consumptionurl: {value:"none"}, - comboidentifier: {value:"none",required: true} + consumptionurl: {value:""}, + comboidentifier: {value:"",required: true} }, inputs:1, outputs:4, diff --git a/octopus.js b/octopus.js index 62c1604..42027da 100644 --- a/octopus.js +++ b/octopus.js @@ -132,7 +132,7 @@ module.exports = function(RED) { var msg3 = {}; msg3.payload = []; msg.payload.results.forEach(function(item, index) { - msg3.payload.push([{ value_inc_vat : item.value_inc_vat, identifier: n.comboidentifier, "time": new Date(item.valid_from).getTime() *1000 *1000}, influxDBsource]); + msg3.payload.push([{ value_inc_vat : item.value_inc_vat, "time": new Date(item.valid_from).getTime() *1000 *1000},{"identifier": n.comboidentifier, influxDBsource}]); }); msg3.measurement = "OctopusPrice"; @@ -169,7 +169,7 @@ module.exports = function(RED) { msg4.payload = []; outputx.payload.results.forEach(function(item, index) { - msg4.payload.push([{ consumption : item.consumption, "identifier": n.comboidentifier, "time": new Date(item.interval_start).getTime() *1000 *1000}, consumptionDBsource]); + msg4.payload.push([{ consumption : item.consumption, "time": new Date(item.interval_start).getTime() *1000 *1000},{"identifier": n.comboidentifier, influxDBsource}]); }); msg4.measurement = "OctopusConsumption"; node.send([msg, msg2, msg3, msg4]); From 031ca360d927dc3bd9b714595991b9def128cafd Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Sat, 29 Oct 2022 17:39:19 +0100 Subject: [PATCH 48/53] Fix influxdb field syntax --- octopus.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/octopus.js b/octopus.js index 42027da..0fe0b9d 100644 --- a/octopus.js +++ b/octopus.js @@ -36,17 +36,17 @@ module.exports = function(RED) { if (n.baseurl == "") { baseurl = "https://api.octopus.energy/v1/products/AGILE-OUTGOING-19-05-13/electricity-tariffs/E-1R-AGILE-OUTGOING-19-05-13-"; } - influxDBsource = {"source" : "Outgoing"}; + influxDBsource = "Outgoing"; } else if (n.tariff == "AGILE") { if (n.baseurl == "") { baseurl = "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-"; } - influxDBsource = {"source" : "Agile"}; + influxDBsource = "Agile"; } else { if (n.baseurl == "") { baseurl = "https://api.octopus.energy/v1/products/GO-22-07-05/electricity-tariffs/E-1R-GO-22-07-05-"; } - influxDBsource = {"source" : "Go"}; + influxDBsource = "Go"; } var https = require("https"); var next_run = new Date(0); @@ -132,7 +132,7 @@ module.exports = function(RED) { var msg3 = {}; msg3.payload = []; msg.payload.results.forEach(function(item, index) { - msg3.payload.push([{ value_inc_vat : item.value_inc_vat, "time": new Date(item.valid_from).getTime() *1000 *1000},{"identifier": n.comboidentifier, influxDBsource}]); + msg3.payload.push([{ value_inc_vat : item.value_inc_vat, "time": new Date(item.valid_from).getTime() *1000 *1000},{"identifier": n.comboidentifier, source: influxDBsource}]); }); msg3.measurement = "OctopusPrice"; @@ -169,7 +169,7 @@ module.exports = function(RED) { msg4.payload = []; outputx.payload.results.forEach(function(item, index) { - msg4.payload.push([{ consumption : item.consumption, "time": new Date(item.interval_start).getTime() *1000 *1000},{"identifier": n.comboidentifier, influxDBsource}]); + msg4.payload.push([{ consumption : item.consumption, "time": new Date(item.interval_start).getTime() *1000 *1000},{"identifier": n.comboidentifier, source: influxDBsource}]); }); msg4.measurement = "OctopusConsumption"; node.send([msg, msg2, msg3, msg4]); From e655b52798acdd8e8fd72df9c91be2b1151e5a56 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Sat, 29 Oct 2022 19:17:57 +0100 Subject: [PATCH 49/53] Added datatype tag to influxdb output --- octopus.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octopus.js b/octopus.js index 0fe0b9d..9b4152d 100644 --- a/octopus.js +++ b/octopus.js @@ -132,7 +132,7 @@ module.exports = function(RED) { var msg3 = {}; msg3.payload = []; msg.payload.results.forEach(function(item, index) { - msg3.payload.push([{ value_inc_vat : item.value_inc_vat, "time": new Date(item.valid_from).getTime() *1000 *1000},{"identifier": n.comboidentifier, source: influxDBsource}]); + msg3.payload.push([{ value_inc_vat : item.value_inc_vat, "time": new Date(item.valid_from).getTime() *1000 *1000},{"identifier": n.comboidentifier, data: "tariff", source: influxDBsource}]); }); msg3.measurement = "OctopusPrice"; @@ -169,7 +169,7 @@ module.exports = function(RED) { msg4.payload = []; outputx.payload.results.forEach(function(item, index) { - msg4.payload.push([{ consumption : item.consumption, "time": new Date(item.interval_start).getTime() *1000 *1000},{"identifier": n.comboidentifier, source: influxDBsource}]); + msg4.payload.push([{ consumption : item.consumption, "time": new Date(item.interval_start).getTime() *1000 *1000},{"identifier": n.comboidentifier, data: "consumption", source: influxDBsource}]); }); msg4.measurement = "OctopusConsumption"; node.send([msg, msg2, msg3, msg4]); From 456cb410cbab9e402b122a40c39b11c1529eabc4 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Sat, 29 Oct 2022 19:33:12 +0100 Subject: [PATCH 50/53] Add tag for meter type. Change measurement name --- octopus.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/octopus.js b/octopus.js index 9b4152d..162d5f2 100644 --- a/octopus.js +++ b/octopus.js @@ -132,10 +132,10 @@ module.exports = function(RED) { var msg3 = {}; msg3.payload = []; msg.payload.results.forEach(function(item, index) { - msg3.payload.push([{ value_inc_vat : item.value_inc_vat, "time": new Date(item.valid_from).getTime() *1000 *1000},{"identifier": n.comboidentifier, data: "tariff", source: influxDBsource}]); + msg3.payload.push([{ value_inc_vat : item.value_inc_vat, "time": new Date(item.valid_from).getTime() *1000 *1000},{"identifier": n.comboidentifier, data: "tariff", meter: "electricity" , source: influxDBsource}]); }); - msg3.measurement = "OctopusPrice"; + msg3.measurement = "octopus"; next_run = next_half_hour; @@ -169,9 +169,9 @@ module.exports = function(RED) { msg4.payload = []; outputx.payload.results.forEach(function(item, index) { - msg4.payload.push([{ consumption : item.consumption, "time": new Date(item.interval_start).getTime() *1000 *1000},{"identifier": n.comboidentifier, data: "consumption", source: influxDBsource}]); + msg4.payload.push([{ consumption : item.consumption, "time": new Date(item.interval_start).getTime() *1000 *1000},{"identifier": n.comboidentifier, data: "consumption", meter: "electricity", source: influxDBsource}]); }); - msg4.measurement = "OctopusConsumption"; + msg4.measurement = "octopus"; node.send([msg, msg2, msg3, msg4]); } catch(err) { node.error(err,outputx); From f0aff83c2de989a847450e27c4db25a276ac0a03 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Sat, 3 Dec 2022 16:17:30 +0000 Subject: [PATCH 51/53] Consumption Meter Type --- octopus.html | 14 +++++++++++--- octopus.js | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/octopus.html b/octopus.html index 8b0ee44..65d2ce5 100644 --- a/octopus.html +++ b/octopus.html @@ -62,7 +62,13 @@
    Example: /v1/electricity-meter-points/MPAN/meters/SERIAL/consumption/?page_size=5000
    - +
    + + +