Create a gist now

Instantly share code, notes, and snippets.

@dceejay /README.md
Last active Dec 23, 2015

What would you like to do?
Get UK Power Demand

#Read UK Power Demand

Uses the web service from the National Grid to fetch the current overall UK Electricity Demand.

    http://realtimeweb-prod.nationalgrid.com/SystemData.aspx

The reponse is then parsed into two parts.

  • The first is an object containing the power in MW and the operating frequency in Hertz
  • The second is true/false depending if that frequency is above 50Hz.

This is an indicator of excessive demand. If over 50 Hz then the demand is low. If under 50Hz then the grid is under heavy load. This signal could for example be used to turn off some appliance to help reduce the overall power usage.

[{"id":"11b032a3.ee4fcd","type":"inject","name":"Tick","topic":"","payload":"","repeat":"","crontab":"*/5 * * * *","once":false,"x":161,"y":828,"z":"6480e14.f9b7f2","wires":[["a2b3542e.5d4ca8"]]},{"id":"a2b3542e.5d4ca8","type":"http request","name":"UK Power","method":"GET","url":"http://realtimeweb-prod.nationalgrid.com/SystemData.aspx","x":301,"y":828,"z":"6480e14.f9b7f2","wires":[["2631e2da.d9ce1e"]]},{"id":"2631e2da.d9ce1e","type":"function","name":"UK Power Demand","func":"// does a simple text extract parse of the http output to provide an\n// object containing the uk power demand, frequency and time\n\nif (~msg.payload.indexOf('<span')) {\n var dem = msg.payload.split('Demand:')[1].split(\"MW\")[0];\n var fre = msg.payload.split('Frequency:')[1].split(\"Hz\")[0];\n\n msg.payload = {};\n msg.payload.demand = parseInt(dem.split(\">\")[1].split(\"<\")[0]);\n msg.payload.frequency = parseFloat(fre.split(\">\")[1].split(\"<\")[0]);\n \n msg2 = {};\n msg2.payload = (msg.payload.frequency >= 50) ? true : false;\n\n return [msg,msg2];\n}\n\nreturn null;","outputs":"2","valid":true,"x":478,"y":828,"z":"6480e14.f9b7f2","wires":[["8e56f4d3.71a908"],["cd84371b.327bc8"]]},{"id":"8e56f4d3.71a908","type":"debug","name":"","active":true,"complete":false,"x":678,"y":798,"z":"6480e14.f9b7f2","wires":[]},{"id":"cd84371b.327bc8","type":"debug","name":"","active":true,"complete":false,"x":679,"y":869,"z":"6480e14.f9b7f2","wires":[]}]

Currently uses the deprecated HTTP Get node - here's a version using HTTP Request:

[{"id":"de18370f.21e7c8","type":"http request","name":"UK Power","method":"GET","url":"http://www.nationalgrid.com/ngrealtime/realtime/systemdata.aspx","x":269,"y":314,"z":"b670be7.f498f4","wires":[["bc031853.43fce8"]]}]

aniston commented Nov 27, 2014

Uk National Grid has moved since a long time, the web site is http://realtimeweb-prod.nationalgrid.com/SystemData.aspx and if you leave out the SystemData.aspx you can get more options ☺️
a modified version of the HTTP request:

[{"id":"e4f63997.1b09c8","type":"http request","name":"UK Power","method":"GET","url":"http://realtimeweb-prod.nationalgrid.com/SystemData.aspx","x":142,"y":127,"z":"fd606400.029fa","wires":[[]]}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment