Octopus Agile as a feed/input

Same here… need to buy a license… but I can’t get Fully Kiosk to always stay asleep and stop the screen saver kicking in a couple of times a day… no bit deal, just a quick swipe up.

Will keep poking about.

If anyone has followed my various attempts to get this data reliably, I have created a Node-Red node that will pull the Agile pricing data in and give you various size minimum price blocks. Feed this into MQTT and EmonCMS will pick it up.

Very rough for now but works. Not exhaustively tested mind you…

Documentation is minimal right now :grinning:.

Install as any other node but use

npm install https://github.com/borpin/node-red-contrib-octopus.git

You might need to use --save.

I’m using NR within Home Assistant - it is just too easy not to - I can add this command within the config from HA.

3 Likes

Hi Brian,

I would like to give this a try, but in reponse to

npm install https://github.com/borpin/node-red-contrib-octopus.git

I get this error log, Sorry, do you know ehere i am going wrong?

Best Regards

James

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/usr/bin/node',
1 verbose cli   '/usr/bin/npm',
1 verbose cli   'install',
1 verbose cli   'https://github.com/borpin/node-red-contrib-octopus.git'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose config Skipping project config: /home/pi/.npmrc. (matches userconfig)
5 verbose npm-session ad6d68bb836573a7
6 silly install loadCurrentTree
7 silly install readLocalPackageData
8 info lifecycle [email protected]~prepack: [email protected]
9 silly fetchPackageMetaData error for git+https://github.com/borpin/node-red-contrib-octopus.git premature close
10 timing stage:rollbackFailedOptional Completed in 2ms
11 timing stage:runTopLevelLifecycles Completed in 2486ms
12 verbose stack Error: premature close
12 verbose stack     at PassThrough.onclose (/usr/lib/node_modules/npm/node_modules/end-of-stream/index.js:47:67)
12 verbose stack     at PassThrough.emit (events.js:323:22)
12 verbose stack     at emitCloseNT (internal/streams/destroy.js:69:8)
12 verbose stack     at processTicksAndRejections (internal/process/task_queues.js:83:21)
13 verbose cwd /home/pi
14 verbose Linux 4.19.75-v7l+
15 verbose argv "/usr/bin/node" "/usr/bin/npm" "install" "https://github.com/borpin/node-red-contrib-octopus.git"
16 verbose node v12.16.1
17 verbose npm  v6.13.4
18 error premature close
19 verbose exit [ 1, true ]

Short answer is no :slight_smile:. I have only tried to install it into a Node-Red inside Home Assistant. I presume this is outside that.

Did you try the --save?

You might be better asking on the Node-Red forum. If you @ me in I’ll see the question and if there is anything I need to do I can try and sort that out.

Hi Brian,

Thanks for the quick reply! I did try the --save, and also with sudo, which resulted in a permissions error oddly enough.

I have just installed node red on my emonpi so its a bare install, I think i will have quick go with HA if thats the known working route!

Kind Regards

James

If you have HA installed somewhere, then it is definitely the best route assuming you are either using HASSIO or the Supervised version. You can add NR in as an add-on as well as InfluxDB and Grafana. All this can then get automatically backed up.

I am becoming more and more impressed with HA as a full system - all the bits just seem to work seamlessly together.

Hi Brian,

I have HA and the node red add on installed and working. Next daft question?

There do i runn your install command from? If i run from a ssh shell i get

npm WARN npm npm does not support Node.js v10.15.2
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can’t make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9.
npm WARN npm You can find the latest version at https://nodejs.org/
npm WARN saveError ENOENT: no such file or directory, open ‘/home/james/package.json’
npm WARN enoent ENOENT: no such file or directory, open ‘/home/james/package.json’
npm WARN james No description
npm WARN james No repository field.
npm WARN james No README data
npm WARN james No license field.

So it evidently doesnt know where to put everything, and its not apearing as a node.

“I can add this command within the config from HA.” Sorry for being daft, I have no experience of HA or Node red, I can i run this from the GUI somewhere?

Best Regards

James

image

Found it :slight_smile:

Sorry for the daft question.

Best regards

James

I tell folk there is no such thing

I use as below

image

You can also load a specific branch

image

One issue I have found is that as I prevent the node running too often, this is a pain when testing! I need to add a specific inject message to force update :slight_smile:

1 Like

Good Morning Brian,

I have been playing with this sucessfully for a while, but yesterday its seems to have broken.

Node red doesnt seem to like you package anymore, did you change something? Is your build still ok?

[07:36:13] INFO: Starting installation of custom NPM/Node-RED packages…
npm ERR! code EINVALIDTAGNAME
npm ERR! Invalid tag name “:”: Tags may not have any characters that encodeURIComponent encodes.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-04-17T06_36_15_858Z-debug.log
[07:36:15] FATAL: Failed to install a specified npm package

Best Regards

James

Hi James, how are you installing it?

Just restarted my Home Assistant add-on and it loads the package no problem. Has anything else changed?

I did update the version and added an output for use with InfluxDB a week ago.

[edit]

[08:16:06] INFO: Starting installation of custom NPM/Node-RED packages...
+ [email protected]
+ [email protected]
added 2 packages from 17 contributors and audited 3759 packages in 23.547s

Add-on config (partial)

npm_packages:
  - 'git+https://github.com/borpin/node-red-contrib-octopus.git'
  - canvas-gauges
init_commands: []
1 Like

Hi Brian,

Thankyou, I swapped

‘npm install GitHub - borpin/node-red-contrib-octopus: Octopus Node-Red node --save’

for

 - 'git+https://github.com/borpin/node-red-contrib-octopus.git'

and this fixed it!

Great work on this, its very usefull, thank you for sharing!

Best Regards

James

1 Like

Hi @borpin just wanted to let you know that I just installed your node red node from GitHub and it works perfectly.

Just what I needed, many thanks
Cheers
Mark

1 Like

I have created a feed that takes the Agile costs and loads them into Emoncms (input). I run a python script every 30 minutes (+1) which loads the value.

This is great for seeing the costs now but I wanted to feed in the costs for the future ( aka the Octopus Agile app).

The idea is to combine these projected costs along with other areas as per the initial request for help.

Is there a way of directly loading the feed with future values rather then relying on the input? I assume a feed takes the current input value and provides a timestamp. SO is there a method I could insert directly into the feed which would then complete what I need - maybe there is an API call I could send data to feed rather than input?

thanking you in advance - Andy B

Apologies everyone. I have found the details for feed API so will follow that.

Having tried in vain to create something myself in NR, just discovered this very nice contribution, thank you @borpin

I’m trying to get the live price for Octopus’ Cosy product which i gather is just a change to the Product & Tarriff code in request URL. Is there any way to modify this either in the Nodered GUI or a config file somewhere? As you can probably tell my engineering skills are somewhat limited!

I have the raw Cosy data coming from Octopus OK thanks to @Timbones, just need to isolate the current price for which this custom node appears to handle all the complexity.

BASE_URL="https://api.octopus.energy"
PRODUCT_CODE="COSY-22-12-08"
TARIFF_CODE="E-1R-$PRODUCT_CODE-J"
TARIFF_URL="$BASE_URL/v1/products/$PRODUCT_CODE/electricity-tariffs/$TARIFF_CODE/standard-unit-rates/"'

Many thanks

Currently no. When I did that, there was just one Tariff!

Thank you! I am obviosuly v. late to the party and just discovered this. Assuming easy enough to mqtt back to emoncms, it’s just what i needed. I’ll have a tinker

If you want a Node-RED solution try this (you will need to modify the URL used)

[{"id":"3f62582d090894ec","type":"debug","z":"24bde98641010730","name":"debug 11","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":320,"wires":[]},{"id":"d049f0c637498499","type":"http request","z":"24bde98641010730","name":"Agile API Request","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://api.octopus.energy/v1/products/AGILE-FLEX-22-11-25/electricity-tariffs/E-1R-AGILE-FLEX-22-11-25-J/standard-unit-rates/","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":330,"y":260,"wires":[["96ddd52228ca5970"]]},{"id":"96ddd52228ca5970","type":"json","z":"24bde98641010730","name":"Convert to Objects","property":"payload","action":"","pretty":false,"x":530,"y":260,"wires":[["1bec2a814c3bb42b"]]},{"id":"2eb46e6b364e2529","type":"inject","z":"24bde98641010730","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":150,"y":260,"wires":[["d049f0c637498499"]]},{"id":"1bec2a814c3bb42b","type":"function","z":"24bde98641010730","name":"Get Current Price from Object","func":"const currentTime = new Date();\n\n// Find the most recent rate that's still valid\nlet currentRate = null;\nmsg.payload.results.forEach(rate => {\n  const validTo = new Date(rate.valid_to);\n  const validFrom = new Date(rate.valid_from);\n\n  if (validFrom <= currentTime && validTo > currentTime) {\n    currentRate = rate;\n    return;\n  }\n});\n\nlet output = \"\";\nif (currentRate) {\n  output = currentRate.value_inc_vat.toString();\n} else {\n  output = \"No current rate available.\";\n}\n// Set the modified payload\nmsg.payload = output;\n\n// Set Global Variable - use  global.get(\"agile_current_price\") \nglobal.set(\"agile_current_price\", msg.payload);\n\n// Return the modified message\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":770,"y":260,"wires":[["3f62582d090894ec"]]}]

Copy and import to Node-RED.

1 Like

Thanks so much…