Thanks for everyones input into this, I recently received an EdiMax Plug and quickly got it working with node-red thanks to this post. The only thing i found i was missing was last state i spent a bit of time and came up with the following flows, in addition to the previous requirements you will need node-re-ping https://www.npmjs.com/package/node-red-node-ping. welcome to suggestions on improvements i would like to verify the plug is set to the last state and then end the flow how ever i’ll do that tomorrow now.
This is the json info to Import into a Node-RED Flow (hamburger menu > Import > Clipboard):
[{"id":"e1fe07d5.bd3648","type":"debug","z":"6102ceb1.69cb","name":"Get Last State","active":true,"console":"false","complete":"payload","x":612.9999847412109,"y":586.0000915527344,"wires":[]},{"id":"3194daa1.9a17b6","type":"debug","z":"6102ceb1.69cb","name":"get state","active":true,"console":"false","complete":"payload","x":537.9999847412109,"y":474,"wires":[]},{"id":"6e8be7bc.f0d1f8","type":"http request","z":"6102ceb1.69cb","name":"Get State","method":"GET","ret":"txt","url":"http://emoncms/emoncms/feed/value.json?id=33&apikey=","tls":"","x":383.99998474121094,"y":535.0000305175781,"wires":[["3194daa1.9a17b6","3c6dc7fb.b616f8"]]},{"id":"3c6dc7fb.b616f8","type":"function","z":"6102ceb1.69cb","name":"Get State Data","func":"if (msg.payload === \"\\\"1\\\"\")\n\nmsg.payload = \"laststate:1\";\n\nelse \n\nmsg.payload = \"laststate:0\"\n\nreturn msg;","outputs":1,"noerr":0,"x":569.9999847412109,"y":535.0000305175781,"wires":[["75a1e5a8.571e6c","ebf3f86c.490ee8"]]},{"id":"75a1e5a8.571e6c","type":"debug","z":"6102ceb1.69cb","name":"retrieved state","active":false,"console":"false","complete":"payload","x":763,"y":489,"wires":[]},{"id":"600361e7.d5863","type":"switch","z":"6102ceb1.69cb","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"","vt":"prev"},{"t":"false"},{"t":"true"}],"checkall":"false","outputs":3,"x":221,"y":538.0000305175781,"wires":[["c9d0923b.d19c2"],["6e053223.f68ecc","6e8be7bc.f0d1f8"],["e233f8d9.da68e8","3b099aee.1435c6"]]},{"id":"ebf3f86c.490ee8","type":"emoncms","z":"6102ceb1.69cb","name":"emoncms","emonServer":"c228ebaa.f505f8","nodegroup":"18","x":749.9999847412109,"y":535.0000915527344,"wires":[]},{"id":"f2d9e76d.d2f9f8","type":"function","z":"6102ceb1.69cb","name":"Convert to boolean","func":"if (msg.payload === \"\\\"1\\\"\")\n\nmsg.payload = \"true\";\n\nelse \n\nmsg.payload = \"false\";\n\nreturn msg;","outputs":1,"noerr":0,"x":682.0001068115234,"y":627.0000305175781,"wires":[["8a87ab1a.431058","389b4fd6.9e893"]]},{"id":"2c45481b.8afe58","type":"smartplug-out","z":"6102ceb1.69cb","name":"EdiPlug-1 Output","topic":"","device":"6eed92.db77a27","response":true,"x":1084.3723602294922,"y":627.3636779785156,"wires":[["5802f2a4.723d4c"]]},{"id":"5802f2a4.723d4c","type":"debug","z":"6102ceb1.69cb","name":"Plug now","active":true,"console":"false","complete":"payload","x":1266.3722381591797,"y":584.3636779785156,"wires":[]},{"id":"e233f8d9.da68e8","type":"http request","z":"6102ceb1.69cb","name":"Get Last State","method":"GET","ret":"txt","url":"http://emoncms./emoncms/feed/value.json?id=34&apikey=","tls":"","x":429.37205505371094,"y":626.5455627441406,"wires":[["f2d9e76d.d2f9f8","e1fe07d5.bd3648"]]},{"id":"24a1526e.d5764e","type":"ping","z":"6102ceb1.69cb","name":"Ping Ediplug-1","host":"192.168.123.48","timer":"10","x":122.68464660644531,"y":428.38633728027344,"wires":[["6cc8d03c.19181"]]},{"id":"c9d0923b.d19c2","type":"debug","z":"6102ceb1.69cb","name":"Switch 1","active":false,"console":"false","complete":"payload","x":416.09934997558594,"y":366.727294921875,"wires":[]},{"id":"6e053223.f68ecc","type":"debug","z":"6102ceb1.69cb","name":"Switch 2","active":true,"console":"false","complete":"payload","x":423.0994110107422,"y":412.7273254394531,"wires":[]},{"id":"6cc8d03c.19181","type":"function","z":"6102ceb1.69cb","name":"Convert to boolean","func":"if (msg.payload === false)\n\nmsg.payload = false;\n\nelse \n\nmsg.payload = true;\n\nreturn msg;","outputs":1,"noerr":0,"x":137.1999969482422,"y":620.800048828125,"wires":[["3812925a.369f3e","600361e7.d5863"]]},{"id":"3812925a.369f3e","type":"debug","z":"6102ceb1.69cb","name":"convert","active":false,"console":"false","complete":"payload","x":192.2000274658203,"y":723.8000793457031,"wires":[]},{"id":"3b099aee.1435c6","type":"debug","z":"6102ceb1.69cb","name":"Switch 3","active":true,"console":"false","complete":"payload","x":359.0994110107422,"y":676.0001525878906,"wires":[]},{"id":"8a87ab1a.431058","type":"debug","z":"6102ceb1.69cb","name":"convert 2","active":true,"console":"false","complete":"payload","x":923.2812347412109,"y":565.0000305175781,"wires":[]},{"id":"389b4fd6.9e893","type":"delay","z":"6102ceb1.69cb","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":889.7783050537109,"y":626.8607482910156,"wires":[["2c45481b.8afe58"]]},{"id":"ed3ee68a.31c4c8","type":"comment","z":"6102ceb1.69cb","name":"Edimax Smart Plug Last State Restore","info":"","x":170.84027099609375,"y":360.4132080078125,"wires":[]},{"id":"c228ebaa.f505f8","type":"emoncms-server","z":"","server":"http://emoncms/emoncms","name":"emoncms"},{"id":"6eed92.db77a27","type":"smartplug-device","z":"","name":"edimax smartplug-1","host":"192.168.123.48","timeout":"10","heartbeat":"5"}]
You’ll need to edit a few bits to get it working such as the http Requests to include your emoncms read api key as well as the ediplug ip. password etc