Community
OpenEnergyMonitor

OpenEnergyMonitor Community

EdiMax SmartPlug Smart plug nodeRED and Emoncms

@Jon
I have received the plugs, installed in the network and configured it in NodeRed. It seems that it there is a problem with autohorization.

Debug: Error: Unauthorized: check username/password

I used the name of the plug as in the app in IOS and the standard password 1234.

the username is admin
(all lower case)
and the password is 1234

You’re right! Thanks.

Next error unfortunatly:

Error: connect EHOSTUNREACH

From my brief experience that error usually happens when the SmartPlug is not power up (meaning plugged into a live power outlet).

Are you able to control the SmartPlug and see the power readings from the Smart Phone app?

I still had to restart and the problem solved. Now all the smartplugs are working.

The voltage calculations turns into strange low values due to the powerfactor. The code should be P = U * I * Powerfactor.

“volts:” + (msg.payload.status.nowPower/msg.payload.status.nowCurrent / POWERFACTOR);

Where can I find the available definitions? msg.payload.status.nowPF or something?

The voltage calculation was me experimenting more than anything else.

The available measurements from the Node-RED SmartPlug node are:
state = msg.payload.status.state
nowPower = msg.payload.status.nowPower
nowCurrent = msg.payload.status.nowCurrent
day = (same pattern as above)
week
month
lastToggleTime

Glyn, were you ever able to regally poll the wemo insight to get usage data? If so, do you have a node red flow you can share? Thanks kindly. Mike.

No, gave up on it. Was too unreliable. I returned the unit.

Mike - I am guessing you already have the node-red node - node-red-node-wemo.

There is an older example available Belkin Wemo Switch Control

And there is even an emulator available for the Amazon Echo Alexa: node-red-contrib-wemo-emulator

maybe one of those will help…

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

Hi,
Based on this thread, I purchased an EdiMax SP-2101W, installed it with the iOS app, upgraded the firmware to v2.08, installed node-red-contrib-smartplug on my EmonPi’s NodeRED (via Hamburger Menu > Manage Palette).
I then created a flow by copying the JSON posted above by Jon (May '16), configured the smartplug-device with the appropriate IP, admin username and password. I also changed the emoncms node to push to node 18 instead of 16.

After deploying, all I get is an error in the debug panel:
“Credential type ‘smartplug-device’ is not registered”

I rebooted the emonPi and logged back into Node-RED, and this time I got notification that smartplug-in and smartplug-out are unrecognised device types…

— (later) —
I re-read Outdoor Temperature Data from Weather Underground to Emoncms & MQTT - Blog | OpenEnergyMonitor which made me think that maybe I shouldn’t install node-red-contrib-smartplug through the web UI, but through command line
I sshed into the emonPi and ran the following:

$ rpi-rw
$ cd ~/data/node-red
$ sudo npm install node-red-contrib-smartplug
$ rpi-ro
$ node-red-stop
$ node-red-start

No luck there either, with the following output:

5 Jul 17:19:28 - [info] Node-RED version: v0.15.2
5 Jul 17:19:28 - [info] Node.js  version: v0.10.29
5 Jul 17:19:28 - [info] Linux 4.4.26-v7+ arm LE
5 Jul 17:19:30 - [info] Loading palette nodes
pi : TTY=unknown ; PWD=/home/pi ; USER=root ; COMMAND=/usr/bin/python -u /usr/lib/node_modules/node-red/nodes/core/hardware/nrgpio.py info
pam_unix(sudo:session): session opened for user root by (uid=0)
pam_unix(sudo:session): session closed for user root
5 Jul 17:19:43 - [warn] ------------------------------------------------------
5 Jul 17:19:43 - [warn] [sensehat] Error: Can't find Sense HAT python libraries. Run sudo apt-get install sense-hat
5 Jul 17:19:43 - [warn] [smartplug] TypeError: Object #<Object> has no method 'on'
5 Jul 17:19:43 - [warn] ------------------------------------------------------
5 Jul 17:19:43 - [info] Settings file  : /home/pi/.node-red/settings.js
5 Jul 17:19:43 - [info] User directory : /home/pi/.node-red
5 Jul 17:19:43 - [info] Flows file     : /home/pi/.node-red/flows_emonpi.json
5 Jul 17:19:43 - [info] Server now running at http://127.0.0.1:1880/
5 Jul 17:19:43 - [info] Waiting for missing types to be registered:
5 Jul 17:19:43 - [info]  - smartplug-device
5 Jul 17:19:43 - [info]  - smartplug-in
5 Jul 17:19:43 - [info]  - smartplug-out

Any idea what could be missing?

Either way should work fine. When installed from the Node-RED web UI via hamburger menu > Manage palette > Install make sure emonPi is in write mode via rpi-rw. After install then rpi-ro to place the emonPi back to read mode.

You can certainly try reinstalling node-red-contrib-smartplug via the command line steps above. You don’t need to uninstall anything first.

Also make sure you are using the correct Username and Password. The Username is admin and the default password is 1234 though the password can be changed.

Also 2, there was a EdiMax SP-2101W firmware change from 2.03 to 2.08. I have not done that update (yet) but I seem to remember it changing something in the node-red-contrib-smartplug code.

Also 3, your Node.js version of v0.10.29 is old and may not function with the node-red-contrib-smartplug code. Please check this first on the node-red-contrib-smartplug GitHub before your try this -->>. If you want to upgrade node.js and node-red you can try the update-nodejs-and-nodered script documented at Redirecting…

PS - I’ll be away from the computer for the next few days so don’t be discouraged if I don’t reply right away.

Thanks, I will re-try some of this on the basis of your comment. I have also added a note on the node-red-contrib-smartplug GitHub.
Note that I ended up uninstalling (npm-uninstall) the whole thing in the end, as this issue prevented all of the node-red flows from working (I have another 2 for weather info extraction from public web services).

Fabre

There is some thing floating around that say you should not npm install locally using sudo. I think that this results in some parts of the installation folders ending up being owned by ‘nobody’.

Do a npm-update to see if any nodes are out of date. update and run npm-update again - I found they simply would not update sometimes.

Installing nodejs and npm seems to be a bit of a black art. I started looking at this but got bogged down.

 
I agree, I always had trouble with upgrade until I tried this command:

bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)

the above command is from:
https://nodered.org/docs/hardware/raspberrypi

Does that install from the repo or direct from nodejs? Last time I looked the raspbian repo was way behind the latest stable nodejs release.

I believe it is a long term stable (LTS) from nodejs. I looked thru the update-nodejs-and-nodered script but it is above my level of understanding. You may want to post a question on the Node-RED forum.

Last time I ran this script it updated Node-RED version to v0.16.2. And updated nodejs and npm to these versions:

[email protected](rw):~$ node -v
v4.7.3
[email protected](rw):~$ npm -v
2.15.11

 

Make sure you make a good backup before running the script. Also be aware Node-RED just had an upgrade from 0.16.2 to 0.17.3.

1 Like

I ran the above update-nodejs-and-nodered script and it is installing:
Node v6.11.0
Npm 3.10.10
Node-RED 0.17.3

EDIT: Install went well. Time to test.

[email protected](rw):~$ bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)

 
This script will remove any pre-installed versions of node.js and Node-RED
and replace them with node.js 6.x LTS (boron) and the latest Node-RED from Npm.
To do this it runs commands as root - please satisfy yourself that this will
not damage your Pi, or otherwise compromise your configuration.
 
Doing this may also be 'a bad thing' if you have installed lots of extra nodes.
Especially if they have any native binary component. Some nodes in your
~/.node-red directory will probably need to be re-installed afterwards, some
may need you to run npm update, and some may require you to run npm rebuild.
 
Are you really sure you want to do this ? (y/N) ? y

Running for user pi at /home/pi

This can take 20-30 minutes on a Pi 1 - please wait.

  Stop Node-RED                       ✔
  Remove old version of Node-RED      ✔
  Remove old version of node.js       ✔
  Update node.js LTS                  ✔   Node v6.11.0   Npm 3.10.10
  Clean npm cache                     ✔
  Install Node-RED core               ✔   0.17.3 
  Install extra nodes                 ✔
  Install serialport node             ✔
  Npm rebuild existing nodes          ✔
  Add menu shortcut                   ✔
  Update systemd script               ✔
  Update update script                ✔

Any errors will be logged to   /var/log/nodered-install.log

All done.
  You can now start Node-RED with the command  node-red-start
  or using the icon under   Menu / Programming / Node-RED
  Then point your browser to localhost:1880 or http://{your_pi_ip-address}:1880

Started  Fri Jul  7 11:23:59 CDT 2017  -  Finished  Fri Jul  7 11:31:18 CDT 2017

Hey Jon,

Would you say it’s safe to use that command, and that you didn’t find it caused problems elsewhere?

Fabre