Updated 25/09 - problem was the returned time format from Octopus had changed.
Continuing the discussion from Integrating Octopus Go API in to emonCMS:
I’ve written a Node-Red flow to import your Octopus consumption data into emonCMS.
Short version
Import this flow into Node Red - follow the embedded instructions.
[{"id":"294d21ac.2850ae","type":"debug","z":"9ae82de6.3d714","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":770,"y":180,"wires":[]},{"id":"414a095d.7f2e98","type":"http request","z":"9ae82de6.3d714","name":"Octopus Get Data","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"basic","x":327,"y":60,"wires":[["8d8c8096.9b3f9"]]},{"id":"58561661.49bee8","type":"inject","z":"9ae82de6.3d714","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":60,"wires":[["b657a771.70b908"]]},{"id":"7e0b0ad9.132b44","type":"http request","z":"9ae82de6.3d714","name":"Put data to emoncms","method":"GET","ret":"txt","paytoqs":"query","url":"","tls":"","persist":false,"proxy":"","authType":"","x":740,"y":120,"wires":[["294d21ac.2850ae"]]},{"id":"70cf228a.32aa9c","type":"delay","z":"9ae82de6.3d714","name":"","pauseType":"rate","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":520,"y":120,"wires":[["7e0b0ad9.132b44"]]},{"id":"b657a771.70b908","type":"function","z":"9ae82de6.3d714","name":"Octopus - build consumption URL","func":"var newmsg = {};\n\nvar host = \"https://api.octopus.energy/v1\";\nvar mpn = \"\";\nvar meter = \"\";\n\n// number of half hour periods max 25000 (will take a long time to load)\n// run with a small number of items to create the input so you can add\n// the processing to it.\n//\n// For ongoing loading of data, set to 48 and run once a day.\n\nvar page_size = 48;\n\nnewmsg.url = host;\nnewmsg.url += \"/electricity-meter-points/\" + mpn;\nnewmsg.url += \"/meters/\" + meter;\nnewmsg.url += \"/consumption/?page_size=\" + page_size;\n\nreturn newmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":200,"y":120,"wires":[["414a095d.7f2e98"]]},{"id":"8d8c8096.9b3f9","type":"function","z":"9ae82de6.3d714","name":"Send data as emonCMS Input","func":"var arrayobj = msg.payload.results;\nvar newmsg = {};\n\nvar apikey =\"12345\";\n\n// for host if you get a 404 error, this might require 'http://x.x.x.x/emoncms/input/post?'\n// should also work for emoncms.org\nvar host = \"http://x.x.x.x/input/post?\";\nvar node_name = \"octopus\"\n\narrayobj.reverse();\narrayobj.forEach(myFunction)\n\nfunction myFunction(item, index, arr) {\n newmsg.url = host;\n newmsg.url += \"node=\" + node_name;\n newmsg.url += \"\\&fulljson={ \\\"time\\\": \\\"\" + encodeURIComponent(arr[index].interval_start) + \"\\\", \";\n newmsg.url += \"\\\"consumption\\\": \" + arr[index].consumption + \"}\";\n newmsg.url += \"\\&apikey=\" + apikey;\n node.send(newmsg);\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":610,"y":60,"wires":[["70cf228a.32aa9c"]]},{"id":"30c1ce17.0526a2","type":"comment","z":"9ae82de6.3d714","name":"Instructions for use","info":"### Preparation\n\nModify the 2 functions with your own details from Octopus (MPN, MPRN) and from emonCMS (API).\n\nModify the *Octopus Get Data* node and add the Octopus API Key\n\nPage size should be just a few first time to create the Input.\n\nOnce the input has been created in emonCMS, you can add the processing to it. Create 2 Feeds;\n\n* Just Log to Feed\n* PHPFINA Fixed Interval\n* Period of 30 Mins.\n\nRun once again and check the data is received.\n\nModify page_size to a maximum of 25000.\n\nEach consumption period will take 1s to import (to ensure emonCMS can keep up - this may be too conservative).","x":390,"y":180,"wires":[]}]
Longer version;
In Node red go to the hamburger menu (top right) click on import and paste the copied text into the box there. Click Import. Deploy the nodes that appear. Click on the Comment box for Instructions.
Notes
I have found that to view the data on the Graphing page you mat need these settings
Change to 1800 and click reload.
It seems the first few data points get loaded immediately, but once feedwriter has cycled, it will buffer for the length of the feedwriter sleep so in this case you usually only see an update of data every 300s
On Admin page
On the Inputs page, because the time used is very old, it will say inactive although the values will change.
You might need to add emoncms
to the host variable in the function so
192.168.2.50/emoncms/input
HTH
[edit 06/09/20]
In the Node-Red http_rquest node, add this (colon is not needed);