Skip to content

Instantly share code, notes, and snippets.

@mike-linus mike-linus/README.md Secret
Created Feb 24, 2016

Embed
What would you like to do?
Rainforest Eagle Smart Meter API

Author: Mike Thompson, GitHub: mike-linus Date: 24/2/2016

These examples show how to extract data and control the Rainforest Eagle using the recommended HTTP Rest API both locally and via the Internet Gateway.

For those of you trying to get the most out of the Rainforest Eagle, these example Node-Red flows should get you going. Having the flows in Node-Red opens up a huge range of automation possibilities. Enjoy :)

To use the flows:

  1. Modify the 'Format Request' function nodes to your specific credentials. For local requests, you need to add your own MAC address. For the Relay Gateway, the message headers need to be altered to your Gateway account.
  2. For all flows except the Gateway flow, modify the 'http request' nodes, tick 'use basic authentication?', add your 'Cloud ID' as the username, your 'Installation Code' as the password and your Eagle's IP address.
  3. For the Gateway flow, basic authentication is not used as the credentials are passed in the message header.
  4. To automate the flows, simply modify the 'inject node' to repeat at the required interval.
  5. To publish the data on a MQTT topic, just replace the debug node with an MQTT node.

Creating your own commands simply requires creating the appropriate command string in the 'Format request' node. Refer to the Eagle Rest API documentation for more information.

[{"id":"a33dd2c4.5cc23","type":"inject","z":"ed6f6725.129098","name":"Local Eagle request","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":182,"y":185,"wires":[["9213b618.6dec48"]]},{"id":"4de8035f.b217fc","type":"http request","z":"ed6f6725.129098","name":"","method":"POST","ret":"txt","url":"https://rainforestcloud.com:9445/cgi-bin/post_manager","x":642,"y":289,"wires":[["14fb55e8.eb04aa"]]},{"id":"6a9448a6.956bb8","type":"function","z":"ed6f6725.129098","name":"Format request","func":"//Create Eagle command XML fragment\nvar command = \"<Command>\\n\";\ncommand += \" <Name>get_instantaneous_demand</Name>\\n\";\ncommand += \"</Command>\\n\";\n\n//Modify header to include Gateway authentication\nmsg.headers = {\n \"Cloud-ID\" : \"000abc\",\n \"User\" : \"myemail@address\",\n \"Password\" : \"MyPasssword\"\n };\n \nmsg.payload = command;\n\nreturn msg;","outputs":1,"noerr":0,"x":473,"y":289,"wires":[["4de8035f.b217fc"]]},{"id":"1906e89f.e6f917","type":"xml","z":"ed6f6725.129098","name":"","attr":"","chr":"","x":847,"y":320,"wires":[["1554745b.eaab8c"]]},{"id":"38f42697.c70bda","type":"rbe","z":"ed6f6725.129098","name":"Ignore repeat values","func":"rbe","gap":"","start":"","x":1090,"y":234,"wires":[["1906e89f.e6f917"]]},{"id":"9b0df685.64f208","type":"http request","z":"ed6f6725.129098","name":"","method":"POST","ret":"txt","url":"http://192.168.2.4/cgi-bin/post_manager","x":634,"y":185,"wires":[["14fb55e8.eb04aa"]]},{"id":"9213b618.6dec48","type":"function","z":"ed6f6725.129098","name":"Format request","func":"//Create Eagle command XML fragment\nvar command = \"<Command>\\n\";\ncommand += \" <Name>get_instantaneous_demand</Name>\\n\";\ncommand += \" <MacId>0xabcdef0000001234</MacId>\\n\";\ncommand += \"</Command>\\n\";\n\nmsg.payload = command;\n\nreturn msg;","outputs":1,"noerr":0,"x":426,"y":185,"wires":[["9b0df685.64f208"]]},{"id":"49a0325d.b65fcc","type":"inject","z":"ed6f6725.129098","name":"Rainforest Relay Gateway request","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":234,"y":289,"wires":[["6a9448a6.956bb8"]]},{"id":"f086e714.0f7918","type":"inject","z":"ed6f6725.129098","name":"Reboot Eagle","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":181,"y":488,"wires":[["1dda3429.e225cc"]]},{"id":"1dda3429.e225cc","type":"function","z":"ed6f6725.129098","name":"Format request","func":"//Create Eagle command XML fragment\nvar command = \"<Command>\\n\";\ncommand += \" <Name>reboot</Name>\\n\";\ncommand += \" <MacId>0xabcdef0000001234</MacId>\\n\";\ncommand += \" <Target>Eagle</Target>\\n\";\ncommand += \"</Command>\\n\";\n\nmsg.payload = command;\n\nreturn msg;","outputs":1,"noerr":0,"x":418,"y":488,"wires":[["9d05b06a.62fa5"]]},{"id":"9d05b06a.62fa5","type":"http request","z":"ed6f6725.129098","name":"","method":"POST","ret":"txt","url":"http://192.168.2.4/cgi-bin/post_manager","x":601,"y":488,"wires":[["2a6138d1.d59ec8"]]},{"id":"2a6138d1.d59ec8","type":"debug","z":"ed6f6725.129098","name":"","active":true,"console":"false","complete":"false","x":776,"y":488,"wires":[]},{"id":"c77c3b6.f3883c8","type":"function","z":"ed6f6725.129098","name":"Format request","func":"//Create Eagle command XML fragment\nvar command = \"<Command>\\n\";\ncommand += \" <Name>set_schedule</Name>\\n\";\ncommand += \" <MacId>0xabcdef0000001234</MacId>\\n\";\ncommand += \" <Event>demand</Event>\\n\";\ncommand += \" <Frequency>5</Frequency>\\n\";\ncommand += \" <Enabled>Y</Enabled>\\n\";\ncommand += \"</Command>\\n\";\n\nmsg.payload = command;\n\nreturn msg;","outputs":1,"noerr":0,"x":546,"y":573,"wires":[["419713d1.be68ec"]]},{"id":"1ccf84e0.e3307b","type":"inject","z":"ed6f6725.129098","name":"Set Demand Poll Schedule to 5 seconds","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":273,"y":573,"wires":[["c77c3b6.f3883c8"]]},{"id":"419713d1.be68ec","type":"http request","z":"ed6f6725.129098","name":"","method":"POST","ret":"txt","url":"http://192.168.2.4/cgi-bin/post_manager","x":734,"y":573,"wires":[["cf2748.ff30d8b8"]]},{"id":"cf2748.ff30d8b8","type":"debug","z":"ed6f6725.129098","name":"","active":true,"console":"false","complete":"false","x":906,"y":573,"wires":[]},{"id":"fc2fc396.03d04","type":"inject","z":"ed6f6725.129098","name":"Get Schedule","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":184,"y":650,"wires":[["4b3d7014.b4c29"]]},{"id":"4b3d7014.b4c29","type":"function","z":"ed6f6725.129098","name":"Format request","func":"//Create Eagle command XML fragment\nvar command = \"<Command>\\n\";\ncommand += \" <Name>get_schedule</Name>\\n\";\ncommand += \" <MacId>0xabcdef0000001234</MacId>\\n\";\ncommand += \" <Event>demand</Event>\\n\";\ncommand += \"</Command>\\n\";\n\nmsg.payload = command;\n\nreturn msg;","outputs":1,"noerr":0,"x":397,"y":650,"wires":[["a46062b7.5b9fa"]]},{"id":"a46062b7.5b9fa","type":"http request","z":"ed6f6725.129098","name":"","method":"POST","ret":"txt","url":"http://192.168.2.4/cgi-bin/post_manager","x":600,"y":650,"wires":[["8aa8f888.755708"]]},{"id":"3ec0e726.c13f18","type":"debug","z":"ed6f6725.129098","name":"","active":true,"console":"false","complete":"false","x":1108,"y":650,"wires":[]},{"id":"1554745b.eaab8c","type":"function","z":"ed6f6725.129098","name":"Calculate Demand Value","func":"//ignore bad data\nif (!msg.payload.InstantaneousDemand) \n{\n return;\n}\n\n//parse response\nstrDemand=msg.payload.InstantaneousDemand.Demand[0];\nintDemand=parseInt(strDemand,16);\n\nstrMultiplier=msg.payload.InstantaneousDemand.Multiplier[0];\nintMultiplier=parseInt(strMultiplier,16);\n\nstrDivisor=msg.payload.InstantaneousDemand.Divisor[0];\nintDivisor=parseInt(strDivisor,16);\n\nif (intDemand>2147483647) {\n intDemand = 0;\n}\n\nif (intMultiplier===0) {\n intMultiplier = 1;\n} \n\nif (intDivisor===0) {\n intDivisor = 1;\n}\n\nmsg.payload = (intDemand * intMultiplier) / intDivisor;\n\nreturn msg;","outputs":"1","noerr":0,"x":949,"y":395,"wires":[["175b90f0.e8a46f"]]},{"id":"175b90f0.e8a46f","type":"debug","z":"ed6f6725.129098","name":"","active":true,"console":"false","complete":"false","x":1088,"y":317,"wires":[]},{"id":"14fb55e8.eb04aa","type":"function","z":"ed6f6725.129098","name":"Ignore bad data","func":"//ignore bad data\nif (!msg.payload || msg.payload === null || msg.payload === '') \n{\n return;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":864,"y":234,"wires":[["38f42697.c70bda"]]},{"id":"8aa8f888.755708","type":"xml","z":"ed6f6725.129098","name":"","attr":"","chr":"","x":759,"y":650,"wires":[["5c8316ee.a37ce8"]]},{"id":"5c8316ee.a37ce8","type":"function","z":"ed6f6725.129098","name":"Extract Value","func":"msg.payload = \"Demand Polling set for: \" + msg.payload.ScheduleList.ScheduleInfo[0].Frequency[0] + \" secs\"\nreturn msg;","outputs":1,"noerr":0,"x":925,"y":650,"wires":[["3ec0e726.c13f18"]]},{"id":"e4e95591.1b16a8","type":"comment","z":"ed6f6725.129098","name":"Read Me: Notes (please retain these notes if distributing the flows)","info":"Author: Mike Thompson, GitHub: mike-linus\nDate: 24/2/2016\n\nThese examples show how to extract data and control the Rainforest Eagle using the recommended HTTP Rest API both locally and via the Internet Gateway.\n\nFor those of you trying to get the most out of the Rainforest Eagle, these example Node-Red flows should get you going. Having the flows in Node-Red opens up a huge range of automation possibilities. Enjoy :)\n\nTo use the flows:\n1. Modify the 'Format Request' function nodes to your specific credentials. For local requests, you need to add your own MAC address. For the Relay Gateway, the message headers need to be altered to your Gateway account.\n2. For all flows except the Gateway flow, modify the 'http request' nodes, tick 'use basic authentication?', add your 'Cloud ID' as the username, your 'Installation Code' as the password and your Eagle's IP address.\n3. For the Gateway flow, basic authentication is not used as the credentials are passed in the message header.\n4. To automate the flows, simply modify the 'inject node' to repeat at the required interval.\n5. To publish the data on a MQTT topic, just replace the debug node with an MQTT node.\n\nCreating your own commands simply requires creating the appropriate command string in the 'Format request' node. Refer to the Eagle Rest API documentation for more information.","x":308,"y":82,"wires":[]}]
@tocool24

This comment has been minimized.

Copy link

commented Oct 22, 2017

i am getting an error in the XML block, not sure what i am doing wrong

Error: Inappropriately located doctype declaration
Line: 1
Column: 9
Char: E

@geelongdman

This comment has been minimized.

Copy link

commented May 22, 2019

Just found this - just what I needed - thanks! Just one point, negative usage (if you have solar) comes in as zero. To fix, edit the Calculate Demand Vale node and add this:
if (intDemand>2147483647) {
//Negative - do 2's complement by inverting
intDemand = ~intDemand * -1;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.