Tasmota powerplug with HTTP

This node provides a complete handling of a TASMOTA power-plug on basis of HTTP communication.


Although MQTT communication might be a better way of communicating, the way this HTTP communication is setup has the advantage that the power plug itself doesn't have to be changed in any way, and also is not dependent of an MQTT broker inside or outside node-red. Just fill in the settings function outside this subflow, and the power-plug will start operating.

Pre-condition is that the MAC-address of the power plug is determined, and necessary libraries are installed.

Following dependencies exist:

node-red-contrib-arp
node-red-contrib-ui-multistate-switch (outside this subflow)
node-red-contrib-ui-led

These libraries need to be installed in order to make this (sub)flow work.


This subflow node works well with the flow provided with it. Following actions need to be taken to install the plug:

  1. Determine the mac address of the TASMOTA power-plug. This can be done with many network apps ( for instance: Network Analyzer Lite ) or any other program that can do the job. The subflow will automatically determine what the IP-address is of the plug.
  2. Fill in the settings block outside of this subflow.
    • MAC address, that has been determined.
    • Provide a long and a short (max. 10 char.) name for this plug.
    • There are correction factors to correct the values of power/voltage and current, as it turns out that the measurement of the plug is not so precise as the manufacturer claims. If no correction are to be made these factors should be 1.
    • Finally enable or disable the ON/OFF switch of the power-plug, in case you don't want it to be switched by the user. (You can always make this conditional by controlling the respective parameter).
  3. Click on the subflow in the flow and fill in the PP-number of the power-plug, this number will be used as an index variable for the array of objects.

On the dashboard there is a connect-button, if no connection, then the button is red. If connected then the button is green. By pushing the button, a connection will be made with the plug, with the parameters that are provided.

The (sub)flow can be copied as many times as you want with different index numbers.

[{"id":"c558c6433162446c","type":"group","z":"cfd6ed84a742a9a1","name":"Powerplug -PP01-","style":{"fill":"#ffffbf","label":true,"color":"#001f60"},"nodes":["aacf5b38cda2e8f0","a7c59ba69b73d202","8a380e2cf4cce4ac","97d23483eca6af35","f8322a2b6e852a3c","e65a393810cf5bc8","99c7734b879b5cbb","2c3448191ba29b1f","a610ed661f5a53dd","9bf5879865af15df","a90ff472457dceee","12f5c1d61983c9c3","6b4cc7da8f999247","86695af1db7c8450","cc4858cf45cfd77b"],"x":124,"y":19,"w":862,"h":382},{"id":"80672c528f5e6d3d","type":"subflow","name":"Powerplug","info":"This node provides a complete handling of a TASMOTA power-plug on basis of HTTP communication.\r\n\r\n---\r\n\r\nAlthough MQTT communication might be a better way of communicating, \r\nthe way this HTTP communication is setup has the advantage that the power plug itself doesn't have to be changed in any way, \r\nand also is not dependent of an MQTT broker inside or outside node-red. \r\nJust fill in the settings function outside this subflow, and the power-plug will start operating.\r\n\r\nPre-condition is that the MAC-address of the power plug is determined, and necessary libraries are installed.\r\n\r\nFollowing dependencies exist:\r\n\r\n    node-red-contrib-arp\r\n    node-red-contrib-ui-multistate-switch (outside this subflow)\r\n    node-red-contrib-ui-led\r\n\r\nThese libraries need to be installed in order to make this (sub)flow work.\r\n\r\n---\r\n\r\nThis subflow node works well with the flow provided with it. Following actions need to be taken to install the plug:\r\n\r\n 1. Determine the mac address of the TASMOTA power-plug. \r\n    This can be done with many network apps ( for instance: Network Analyzer Lite ) or any other program that can do the job. \r\n    The subflow will automatically determine what the IP-address is of the plug.\r\n 2. Fill in the settings block outside of this subflow.\r\n    - MAC address, that has been determined.\r\n    - Provide a long and a short (max. 10 char.) name for this plug.\r\n    - There are correction factors to correct the values of power/voltage and current, \r\n      as it turns out that the measurement of the plug is not so precise as the manufacturer claims. \r\n      If no correction are to be made these factors should be 1.\r\n    - Finally enable or disable the ON/OFF switch of the power-plug, in case you don't want it to be switched by the user. (You can always make this conditional by controlling the respective parameter).\r\n 3. Click on the subflow in the flow and fill in the PP-number of the power-plug, this number will be used as an index variable for the array of objects.\r\n\r\nOn the dashboard there is a connect-button, if no connection, then the button is red. If connected then the button is green.\r\nBy pushing the button, a connection will be made with the plug, with the parameters that are provided.\r\n\r\nThe (sub)flow can be copied as many times as you want with different index numbers.\r\n","category":"","in":[{"x":100,"y":160,"wires":[{"id":"a526ed73631fb561"}]}],"out":[{"x":1430,"y":400,"wires":[{"id":"9481b6433c0dfdc0","port":0}]},{"x":1450,"y":460,"wires":[{"id":"610b11aa1c9857ea","port":0}]},{"x":1430,"y":520,"wires":[{"id":"610b11aa1c9857ea","port":1}]},{"x":1440,"y":580,"wires":[{"id":"610b11aa1c9857ea","port":2}]},{"x":1440,"y":640,"wires":[{"id":"610b11aa1c9857ea","port":3}]},{"x":1440,"y":700,"wires":[{"id":"610b11aa1c9857ea","port":4}]},{"x":1460,"y":760,"wires":[{"id":"687099927af9817b","port":0}]},{"x":1450,"y":820,"wires":[{"id":"04246b78b2254ae1","port":0}]},{"x":1430,"y":880,"wires":[{"id":"cdb29c6c10f4e7c4","port":0}]}],"env":[{"name":"index","type":"num","value":"0","ui":{"label":{"en-US":"PP"},"type":"input","opts":{"types":["num"]}}}],"meta":{"module":"Powerplug","version":"1.1","author":"Henkkas","desc":"Tasmota power plug via HTTP","keywords":"powerplug, tasmota"},"color":"#bbff33","inputLabels":["Command input"],"outputLabels":["Name","DeviceStatus","Power","Voltage","Current","ON/OFF","Energy today","LinkStatus","Debug"],"icon":"font-awesome/fa-plug","status":{"x":1040,"y":940,"wires":[{"id":"3ddaec56d36cd2c4","port":0}]}},{"id":"e43b3ccc62dfeafc","type":"function","z":"80672c528f5e6d3d","name":"GET mac address","func":"let index = env.get('index');\nlet topic = msg.topic;\nlet pp_mac = global.get('powerplug.pp[' + index + '].comm.mac');\nlet obj = { macs: pp_mac};\n\nmsg = {payload: obj}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":60,"wires":[["1d9ef7624db48abb"]]},{"id":"1d9ef7624db48abb","type":"arp","z":"80672c528f5e6d3d","name":"ARP","macs":"","x":850,"y":60,"wires":[["71da38ef4f5df144"]]},{"id":"71da38ef4f5df144","type":"function","z":"80672c528f5e6d3d","name":"SET IP address","func":"let index = env.get('index');\n\nglobal.set('powerplug.pp[' + index + '].comm.ip', msg.payload[0].ip);\n\nmsg = {};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1000,"y":60,"wires":[["b350fde2f67f8538"]]},{"id":"435eaaa40c98103f","type":"function","z":"80672c528f5e6d3d","name":"Init","func":"let index = env.get('index');\n \n    // Init status, power and energy\n    global.set('powerplug.pp[' + index + '].data.status', \"\");\n    global.set('powerplug.pp[' + index + '].data.voltage', 0);\n    global.set('powerplug.pp[' + index + '].data.current', 0);\n    global.set('powerplug.pp[' + index + '].data.power', 0);\n    global.set('powerplug.pp[' + index + '].data.energy', {});\n\nreturn;","outputs":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":250,"y":80,"wires":[]},{"id":"bcae9cd72fd8ed9c","type":"inject","z":"80672c528f5e6d3d","name":"5 sec - status","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"status","payload":"status 0","payloadType":"str","x":240,"y":240,"wires":[["1d867caaa568fa26"]]},{"id":"1d867caaa568fa26","type":"function","z":"80672c528f5e6d3d","name":"URL Encoder","func":"let str = msg.payload;\n\n// Spaces replaced by %20\n// \";\" replaced by %3B\nstr = str.replace(\" \", \"%20\");\nstr = str.replace(\";\", \"%3B\");\n\nmsg.payload = str;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":240,"wires":[["58b1f999ab17236f","3ddaec56d36cd2c4"]]},{"id":"a526ed73631fb561","type":"function","z":"80672c528f5e6d3d","name":"Topic splitter","func":"let index = Number(env.get('index'));\n\nif ((index < 0) || (index == NaN)) {\n    return;\n}\n\n\nlet msg1 = null;\nlet msg2 = null;\nlet msg3 = null;\nlet msg4 = null;\n\nlet topic = msg.topic;\n\nswitch (topic) {\n    case \"init\":\n        msg1 = msg;         // Goto INIT\n        break;\n    case \"connect\":         // Determine IP address from MAC address\n        msg2 = msg;\n        break;\n    case \"reset\":     // Reset daily energy value\n        msg3 = msg;\n        break;\n    case \"power\":           // Request power on/off\n        msg4 = msg;\n        break;\n    case \"status\":           // Request status\n        msg4 = msg;\n        break;\n    default:\n    // code block\n} \n\n\nreturn [msg1, msg2, msg3, msg4];","outputs":4,"noerr":0,"initialize":"","finalize":"","libs":[],"x":250,"y":160,"wires":[["435eaaa40c98103f"],["2414b4088c46f03b"],["1d867caaa568fa26"],["1d867caaa568fa26"]]},{"id":"58b1f999ab17236f","type":"delay","z":"80672c528f5e6d3d","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":680,"y":240,"wires":[["33f5d68463dcfa9a"]]},{"id":"33f5d68463dcfa9a","type":"function","z":"80672c528f5e6d3d","name":"SET request data","func":"let index = env.get('index');\n\nlet ip = global.get('powerplug.pp[' + index + '].comm.ip') || 0;\nlet topic = msg.topic;\nlet cmnd = msg.payload;\n\n//http://<ip>/cm?cmnd=Power%20On\nlet url_txt = \"http://\"+ ip + \"/cm?cmnd=\" + cmnd;\n\nmsg = { topic: topic, payload: cmnd, url: url_txt }\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":850,"y":240,"wires":[["2951bf53ba257eae"]]},{"id":"2951bf53ba257eae","type":"http request","z":"80672c528f5e6d3d","name":"HTTP request to power plug","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":true,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":true,"headers":[],"x":1080,"y":240,"wires":[["e3e46cedd1def866"]]},{"id":"e3e46cedd1def866","type":"function","z":"80672c528f5e6d3d","name":"SET to global","func":"//node.warn(msg);\nlet index = env.get('index');\nlet test = msg.payload.hasOwnProperty(\"StatusSNS\");\nlet topic = msg.topic;\nlet errorCode = msg.statusCode || 0;\n\n// Reset communication error\nif (errorCode == 200) {\n    global.set('powerplug.pp[' + index + '].comm.error', false);\n} \n\nif (test && (topic == \"status\")) {\n    let status_str = \"\";\n    let status = msg.payload.Status.Power;\n    if (status == 1) {status_str = \"ON\"}\n    if (status == 0) {status_str = \"OFF\" }\n    let power = msg.payload.StatusSNS.ENERGY.Power;\n    let voltage = msg.payload.StatusSNS.ENERGY.Voltage;\n    let current = msg.payload.StatusSNS.ENERGY.Current;\n    let energy_today = msg.payload.StatusSNS.ENERGY.Today;\n    let energy_total = msg.payload.StatusSNS.ENERGY.Total;\n\n    power = power * global.get('powerplug.pp[' + index + '].settings.powerCorrFactor');\n    voltage = voltage * global.get('powerplug.pp[' + index + '].settings.voltageCorrFactor');\n    current = current * global.get('powerplug.pp[' + index + '].settings.currentCorrFactor');\n\n    global.set('powerplug.pp[' + index + '].data.status', status_str);\n    global.set('powerplug.pp[' + index + '].data.voltage', voltage);\n    global.set('powerplug.pp[' + index + '].data.current', current);\n    global.set('powerplug.pp[' + index + '].data.power', power);\n    global.set('powerplug.pp[' + index + '].data.energy.today', energy_today);\n    global.set('powerplug.pp[' + index + '].data.energy.total', energy_total);\n}\n\n// This is the ON/OFF command/status of powerplug\ntest = (msg.payload.hasOwnProperty(\"POWER\"))\nif (test && (topic == \"power\")) {\n    let status = msg.payload.POWER;\n    global.set('powerplug.pp[' + index + '].data.status', status);\n}\n\n// This is reset, no further action needed\nif (topic == \"reset\") {\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1300,"y":240,"wires":[["202342e8f9366bbd"]]},{"id":"f5c2a4ec398f476f","type":"inject","z":"80672c528f5e6d3d","name":"10 sec","props":[],"repeat":"10","crontab":"","once":true,"onceDelay":"1","topic":"","x":940,"y":760,"wires":[["687099927af9817b","04246b78b2254ae1"]]},{"id":"687099927af9817b","type":"function","z":"80672c528f5e6d3d","name":"GET global data","func":"let index = env.get('index');\n\nlet energy_today = global.get('powerplug.pp[' + index + '].data.energy.today') || 0;\nmsg = { payload: energy_today.toFixed(1), text: \"Vandaag\", unit: \"kWh\"} \n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1140,"y":760,"wires":[[]]},{"id":"610b11aa1c9857ea","type":"function","z":"80672c528f5e6d3d","name":"GET global data","func":"let index = env.get('index');\n\nlet status_str = global.get('powerplug.pp[' + index + '].data.status');\n\nlet status_on = (status_str == \"ON\") || false;\nlet sw_enabled = global.get('powerplug.pp[' + index + '].settings.switch_enable') || false;\nlet power = global.get('powerplug.pp[' + index + '].data.power') || 0;\nlet voltage = global.get('powerplug.pp[' + index + '].data.voltage') || 0;\nlet current = global.get('powerplug.pp[' + index + '].data.current') || 0;\nif (current < 0.05) { current = 0.0; }\nif (current > 9.99) { current = current.toFixed(1); }\nelse { current = current.toFixed(2);}\n\nlet msg1 = { payload: status_on} \nlet msg2 = { payload: Math.round(power), label: \"Vermogen\"};\nlet msg3 = { payload: Math.round(voltage), label: \"Spanning\"};\nlet msg4 = { payload: current, label: \"Stroom\"};\n\n// Check status of power switch\nlet msg5 = { enable: sw_enabled, payload: \"Power \" + status_str };\n\n// If power switch is disabled, force Power = ON\nlet msg6 = null;\nif (!sw_enabled && !status_on) {\n   msg6 = { topic: power, payload: \"Power ON\"}\n}\n\nreturn [msg1, msg2, msg3, msg4, msg5, msg6];","outputs":6,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1140,"y":520,"wires":[[],[],[],[],[],["b538a670723826cf"]],"inputLabels":["Trigger"],"outputLabels":["DeviceStatus","Power","Voltage","Current","On/Off","ForcePowerOn"]},{"id":"daf5d8c6e13b73b1","type":"inject","z":"80672c528f5e6d3d","name":"1 sec","props":[{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":true,"onceDelay":"1","topic":"update","x":950,"y":520,"wires":[["610b11aa1c9857ea"]]},{"id":"9481b6433c0dfdc0","type":"function","z":"80672c528f5e6d3d","name":"GET global","func":"let index = env.get('index');\nlet pp_code = global.get('powerplug.pp[' + index + '].code');\nlet pp_name = global.get('powerplug.pp[' + index + '].longName');\n\nmsg = {text: pp_code + \" - \" + pp_name, payload: \"\", unit: \"\"}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1130,"y":400,"wires":[[]]},{"id":"3ddaec56d36cd2c4","type":"function","z":"80672c528f5e6d3d","name":"Prepare status line","func":"let index = env.get('index');\nlet ip = global.get('powerplug.pp[' + index + '].comm.ip');\nlet ip_str = \"[\" + ip + \"] \";\n\nlet msg1 = { payload: ip_str + \",cmd = \" + msg.payload}\n\nreturn msg1;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":850,"y":940,"wires":[[]]},{"id":"c117ffcd577b55b9","type":"link in","z":"80672c528f5e6d3d","name":"PP_request","links":["b538a670723826cf","bfae4540d13afab9","3a4c0ae7a8b2287e","cd930bd102d8ae88"],"x":285,"y":300,"wires":[["1d867caaa568fa26"]]},{"id":"b538a670723826cf","type":"link out","z":"80672c528f5e6d3d","name":"link out 4","mode":"link","links":["c117ffcd577b55b9"],"x":1295,"y":700,"wires":[]},{"id":"b350fde2f67f8538","type":"function","z":"80672c528f5e6d3d","name":"Cmd: Host Name","func":"// Host name will be send to device\nlet index = env.get('index');\nlet hostname = global.get('powerplug.pp[' + index + '].code');\nlet cmnd = \"Hostname \" + hostname;\n\nmsg = {topic: \"HostName\", payload: cmnd }\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":120,"wires":[["bfae4540d13afab9","9a35d8e53abd5b77"]]},{"id":"b30fe0b6cef9eb57","type":"function","z":"80672c528f5e6d3d","name":"Cmd: Device Name","func":"// Device name will be send to device\nlet index = env.get('index');\nlet devName = global.get('powerplug.pp[' + index + '].shortName');\nlet cmnd = \"DeviceName \" + devName;\n\nmsg = { topic: \"DeviceName\", payload: cmnd }\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":910,"y":120,"wires":[["d9334e14fed68b53","cd930bd102d8ae88"]]},{"id":"9a35d8e53abd5b77","type":"delay","z":"80672c528f5e6d3d","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":720,"y":120,"wires":[["b30fe0b6cef9eb57"]]},{"id":"bfae4540d13afab9","type":"link out","z":"80672c528f5e6d3d","name":"link out 5","mode":"link","links":["c117ffcd577b55b9"],"x":645,"y":160,"wires":[]},{"id":"3a4c0ae7a8b2287e","type":"link out","z":"80672c528f5e6d3d","name":"link out 6","mode":"link","links":["c117ffcd577b55b9"],"x":1465,"y":120,"wires":[]},{"id":"cdb29c6c10f4e7c4","type":"link in","z":"80672c528f5e6d3d","name":"Debug_out","links":["202342e8f9366bbd","a9b5de3110e7c9a5"],"x":1315,"y":880,"wires":[[]]},{"id":"202342e8f9366bbd","type":"link out","z":"80672c528f5e6d3d","name":"link out 7","mode":"link","links":["cdb29c6c10f4e7c4"],"x":1465,"y":240,"wires":[]},{"id":"d9334e14fed68b53","type":"delay","z":"80672c528f5e6d3d","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1120,"y":120,"wires":[["5226bce9a4f123d2"]]},{"id":"5226bce9a4f123d2","type":"function","z":"80672c528f5e6d3d","name":"Cmd: Friendly Name","func":"// Friendly name will be send to device\nlet index = env.get('index');\nlet friendlyName = global.get('powerplug.pp[' + index + '].longName');\nlet cmnd = \"FriendlyName1 \" + friendlyName;\n\nmsg = { topic: \"FriendlyName\", payload: cmnd }\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1320,"y":120,"wires":[["3a4c0ae7a8b2287e"]]},{"id":"cd930bd102d8ae88","type":"link out","z":"80672c528f5e6d3d","name":"link out 9","mode":"link","links":["c117ffcd577b55b9"],"x":1045,"y":160,"wires":[]},{"id":"45660992bfe03a95","type":"inject","z":"80672c528f5e6d3d","name":"10 sec","props":[],"repeat":"10","crontab":"","once":true,"onceDelay":"1","topic":"","x":940,"y":400,"wires":[["9481b6433c0dfdc0"]]},{"id":"6d78a5d2c5e7e45a","type":"function","z":"80672c528f5e6d3d","name":"Error detection","func":"let index = env.get('index');\nglobal.set('powerplug.pp[' + index + '].comm.error', true);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1300,"y":280,"wires":[["202342e8f9366bbd"]]},{"id":"bd77fd9f8228afeb","type":"catch","z":"80672c528f5e6d3d","name":"Catch HTTP errors","scope":["2951bf53ba257eae"],"uncaught":false,"x":1070,"y":280,"wires":[["6d78a5d2c5e7e45a"]]},{"id":"04246b78b2254ae1","type":"function","z":"80672c528f5e6d3d","name":"GET global data","func":"let index = env.get('index');\n\nlet green = \"#008040\";\nlet red = \"red\";\nlet white = \"white\";\n\n// Change the color of the link button and reset actual values power/voltage/current\nlet commError = true;\ncommError = global.get('powerplug.pp[' + index + '].comm.error');\nmsg = null;\nif (commError) {\n    msg = { enable: true, f_color: white, b_color: red }\n    global.set('powerplug.pp[' + index + '].data.power', 0);\n    global.set('powerplug.pp[' + index + '].data.voltage', 0);\n    global.set('powerplug.pp[' + index + '].data.current', 0);\n}\nelse {\n    msg = { enable: true, f_color: white, b_color: green }\n}\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1140,"y":820,"wires":[[]]},{"id":"2414b4088c46f03b","type":"function","z":"80672c528f5e6d3d","name":"User settings","func":"// Set or update user settings\nlet index = env.get('index');\n\nlet mac = msg.mac;\nlet pp_shortName = msg.pp_shortName;\nlet pp_longName = msg.pp_longName;\nlet powerCorrFactor = msg.powerCorrFactor;\nlet voltageCorrFactor = msg.voltageCorrFactor;\nlet currentCorrFactor = msg.currentCorrFactor;\nlet switch_enable = msg.switch_enable;\n\n// Determine hostname\nlet pp_code = \"PP\" + (index).toString().padStart(2, \"0\");  // Host Name\n\nglobal.set('powerplug.pp[' + index + '].comm.mac', mac);\nglobal.set('powerplug.pp[' + index + '].comm.port', 80);\nglobal.set('powerplug.pp[' + index + '].comm.protocol', \"HTTP\");\nglobal.set('powerplug.pp[' + index + '].code', pp_code);\nglobal.set('powerplug.pp[' + index + '].shortName', pp_shortName);\nglobal.set('powerplug.pp[' + index + '].longName', pp_longName);\n\nglobal.set('powerplug.pp[' + index + '].settings.powerCorrFactor', powerCorrFactor);\nglobal.set('powerplug.pp[' + index + '].settings.voltageCorrFactor', voltageCorrFactor);\nglobal.set('powerplug.pp[' + index + '].settings.currentCorrFactor', currentCorrFactor);\nglobal.set('powerplug.pp[' + index + '].settings.switch_enable', switch_enable);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":60,"wires":[["e43b3ccc62dfeafc"]]},{"id":"aacf5b38cda2e8f0","type":"ui_multistate_switch","z":"cfd6ed84a742a9a1","g":"c558c6433162446c","name":"PP01 ON/OFF","group":"9845f816731575f0","order":7,"width":5,"height":1,"label":"Power","stateField":"payload","enableField":"enable","passthroughField":"passthrough","inputMsgField":"inputmsg","rounded":true,"useThemeColors":true,"hideSelectedLabel":false,"multilineLabel":false,"passThrough":"never","inputMsg":"all","userInput":"enabled_show","options":[{"label":"Uit","value":"Power OFF","valueType":"str","color":"#999999"},{"label":"Aan","value":"Power ON","valueType":"str","color":"#009933"}],"topic":"power","x":820,"y":260,"wires":[["e65a393810cf5bc8"]]},{"id":"a7c59ba69b73d202","type":"ui_gauge","z":"cfd6ed84a742a9a1","g":"c558c6433162446c","name":"PP01 Power","group":"9845f816731575f0","order":2,"width":4,"height":3,"gtype":"gage","title":"{{label}}","label":"WATT","format":"{{value}}","min":0,"max":"3000","colors":["#808040","#808040","#808040"],"seg1":"","seg2":"","className":"","x":810,"y":140,"wires":[]},{"id":"8a380e2cf4cce4ac","type":"ui_gauge","z":"cfd6ed84a742a9a1","g":"c558c6433162446c","name":"PP01 Voltage","group":"9845f816731575f0","order":3,"width":2,"height":2,"gtype":"gage","title":"Spanning","label":"VOLT","format":"{{value}}","min":0,"max":"400","colors":["#808040","#808040","#808040"],"seg1":"","seg2":"","className":"","x":820,"y":180,"wires":[]},{"id":"97d23483eca6af35","type":"ui_led","z":"cfd6ed84a742a9a1","g":"c558c6433162446c","order":6,"group":"9845f816731575f0","width":1,"height":1,"label":"","labelPlacement":"right","labelAlignment":"left","colorForValue":[{"color":"#400040","value":"false","valueType":"bool"},{"color":"#00b33c","value":"true","valueType":"bool"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":false,"name":"PP01 Status","x":810,"y":100,"wires":[]},{"id":"f8322a2b6e852a3c","type":"ui_template","z":"cfd6ed84a742a9a1","g":"c558c6433162446c","group":"9845f816731575f0","name":"PP01 Energy today","order":5,"width":4,"height":1,"format":"<div class=\"allitems\"> \n<!-- This is comment -->\n    <p> \n        <span class=\"text\">{{msg.text}}</span>\n        <span class=\"unit\">&nbsp;&nbsp;{{msg.unit}}</span>\n        <span class=\"payload\">{{msg.payload}}</span>\n    </p>\n</div>\n","storeOutMessages":false,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":830,"y":360,"wires":[[]]},{"id":"e65a393810cf5bc8","type":"subflow:80672c528f5e6d3d","z":"cfd6ed84a742a9a1","g":"c558c6433162446c","name":"Powerplug PP01","env":[{"name":"index","value":"1","type":"num"}],"x":550,"y":220,"wires":[["cc4858cf45cfd77b"],["97d23483eca6af35"],["a7c59ba69b73d202"],["8a380e2cf4cce4ac"],["12f5c1d61983c9c3"],["aacf5b38cda2e8f0"],["f8322a2b6e852a3c"],["99c7734b879b5cbb"],["86695af1db7c8450"]]},{"id":"99c7734b879b5cbb","type":"ui_button","z":"cfd6ed84a742a9a1","g":"c558c6433162446c","name":"Connect","group":"9845f816731575f0","order":9,"width":1,"height":1,"passthru":false,"label":"","tooltip":"Connect with powerplug","color":"{{msg.f_color}}","bgcolor":"{{msg.b_color}}","className":"","icon":"fa-link normalIcon","payload":"","payloadType":"str","topic":"connect","topicType":"str","x":540,"y":80,"wires":[["a610ed661f5a53dd"]]},{"id":"2c3448191ba29b1f","type":"inject","z":"cfd6ed84a742a9a1","g":"c558c6433162446c","name":"Inject settings","props":[],"repeat":"","crontab":"","once":false,"onceDelay":"1","topic":"","x":290,"y":80,"wires":[["a610ed661f5a53dd"]]},{"id":"a610ed661f5a53dd","type":"function","z":"cfd6ed84a742a9a1","g":"c558c6433162446c","name":"SETTINGS","func":"\n// Make your settings for this powerplug\nlet mac = \"4C:EB:D6:02:4C:51\";      // MAC address\nlet pp_shortName = \"Wasmach.\";      // Device Name short, max 8 char.\nlet pp_longName = \"Wasmachine\";     // Device Name + Friendly Name\nlet powerCorrFactor = 1.073;        // If no corrections, then correction = 1 \nlet voltageCorrFactor = 1.01;       // If no corrections, then correction = 1\nlet currentCorrFactor = 1.0;        // If no corrections, then correction = 1\nlet switch_enable = false;          // Should the power switch be enabled, or only monitoring?  \n\n\n\n// Preparing message\nmsg = {};\nmsg.mac = mac;\nmsg.pp_shortName = pp_shortName;\nmsg.pp_longName = pp_longName;\nmsg.powerCorrFactor = powerCorrFactor;\nmsg.voltageCorrFactor = voltageCorrFactor;\nmsg.currentCorrFactor = currentCorrFactor;\nmsg.switch_enable = switch_enable;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":200,"wires":[["e65a393810cf5bc8"]]},{"id":"9bf5879865af15df","type":"link in","z":"cfd6ed84a742a9a1","g":"c558c6433162446c","name":"link in 12","links":["cb107579c5525f91"],"x":165,"y":260,"wires":[["a90ff472457dceee"]]},{"id":"a90ff472457dceee","type":"function","z":"cfd6ed84a742a9a1","g":"c558c6433162446c","name":"Reset daily value","func":"msg = { topic: \"reset\", payload: \"EnergyToday 0\"};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":310,"y":260,"wires":[["e65a393810cf5bc8"]]},{"id":"12f5c1d61983c9c3","type":"ui_gauge","z":"cfd6ed84a742a9a1","g":"c558c6433162446c","name":"PP01 Current","group":"9845f816731575f0","order":4,"width":2,"height":2,"gtype":"gage","title":"{{label}}","label":"AMP","format":"{{value}}","min":0,"max":"16","colors":["#808040","#ff8000","#ff0000"],"seg1":"10","seg2":"12","className":"","x":820,"y":220,"wires":[]},{"id":"6b4cc7da8f999247","type":"ui_template","z":"cfd6ed84a742a9a1","g":"c558c6433162446c","group":"9845f816731575f0","name":"Style","order":8,"width":1,"height":1,"format":"<style>\n.allitems {\n        vertical-align: middle;\n        }\n        \nspan.text {\n        float: left;\n        font-size: 100%;\n        font-weight: 400;\n        }\n        \nspan.payload {\n        float: right;\n        font-size: 110%;\n        font-weight: 700;\n}\n\nspan.unit {\n        margin-top: 0.5em;\n        float: right;\n        font-size: 75%;\n        font-weight: 300;\n}\n</style>","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":false,"templateScope":"local","className":"","x":330,"y":340,"wires":[[]]},{"id":"86695af1db7c8450","type":"debug","z":"cfd6ed84a742a9a1","g":"c558c6433162446c","name":"debug msg","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":590,"y":360,"wires":[]},{"id":"cc4858cf45cfd77b","type":"ui_template","z":"cfd6ed84a742a9a1","g":"c558c6433162446c","group":"9845f816731575f0","name":"PP01 Code + (long)Name","order":1,"width":8,"height":1,"format":"<div style=\"font-size: 120%;color:#00cc66\">{{msg.text}}\n</div>\n","storeOutMessages":false,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":850,"y":60,"wires":[[]]},{"id":"9845f816731575f0","type":"ui_group","name":"PP01","tab":"cce679d3.9909c","order":1,"disp":false,"width":"8","collapse":false,"className":""},{"id":"cce679d3.9909c","type":"ui_tab","name":"Powerplug","icon":"fa-plug","order":8,"disabled":false,"hidden":false}]

Flow Info

Created 1 year, 6 months ago
Rating: 1 1

Owner

Actions

Rate:

Node Types

Core
  • catch (x1)
  • debug (x1)
  • delay (x3)
  • function (x19)
  • http request (x1)
  • inject (x5)
  • link in (x3)
  • link out (x5)
Other
  • arp (x1)
  • group (x1)
  • subflow (x1)
  • subflow:80672c528f5e6d3d (x1)
  • ui_button (x1)
  • ui_gauge (x3)
  • ui_group (x1)
  • ui_led (x1)
  • ui_multistate_switch (x1)
  • ui_tab (x1)
  • ui_template (x3)

Tags

  • tasmota
  • power-plug
  • http
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option