Monitoring shelly plug s

After running my shelly plug s monitoring for a while, I found that due to the join node the UI was not reactive enough. Therefore, I rewrote the node. Responsiveness is now ok, especially for on and off status. The way how I handle multiple outputs of the node is also much easier now and better to read. As the inputs and the UI have not changed, it is possible to just replace the code in your node. But then don’t forget to copy Tab “On Start” as well and remove the join node.

[{"id":"d6ff683a9330f8e5","type":"ui_gauge","z":"8ac5ac42307c5911","name":"VPN-power","group":"d5178392f725ae47","order":4,"width":"6","height":"3","gtype":"gage","title":"","label":"Watt","format":"{{value | number:2}}","min":0,"max":"20","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","diff":false,"className":"","x":1290,"y":500,"wires":[]},{"id":"126702277bb45ff3","type":"ui_text","z":"8ac5ac42307c5911","group":"d5178392f725ae47","order":8,"width":"3","height":"1","name":"VPN-temperature","label":"","format":"{{msg.payload}}&nbsp;&deg;C","layout":"row-center","className":"","x":1310,"y":700,"wires":[]},{"id":"5a11eb44ee184b34","type":"ui_text","z":"8ac5ac42307c5911","group":"d5178392f725ae47","order":7,"width":"3","height":"1","name":"VPN-stat","label":"","format":"{{msg.payload}}","layout":"row-center","className":"","x":1280,"y":660,"wires":[]},{"id":"62b509263e8777b9","type":"ui_chart","z":"8ac5ac42307c5911","name":"VPN-12h-Verlauf","group":"d5178392f725ae47","order":9,"width":"6","height":"6","label":"12h Verlauf","chartType":"line","legend":"false","xformat":"HH:mm","interpolate":"linear","nodata":"warte auf Daten","dot":false,"ymin":"0","ymax":"20","removeOlder":"12","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#fa9c19","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":1310,"y":540,"wires":[[]]},{"id":"36555df3eb8a5eb2","type":"ui_text","z":"8ac5ac42307c5911","group":"d5178392f725ae47","order":2,"width":"4","height":"1","name":"VPN-time","label":"","format":"{{msg.payload}}","layout":"row-center","className":"","x":1280,"y":460,"wires":[]},{"id":"639948b701b222f5","type":"ui_text","z":"8ac5ac42307c5911","group":"d5178392f725ae47","order":6,"width":"6","height":"1","name":" VPN-energy-total","label":"Gesamt:","format":"{{msg.payload}}&nbsp;kWh","layout":"row-center","className":"","x":1310,"y":580,"wires":[]},{"id":"0897a4e505cd6f76","type":"mqtt in","z":"8ac5ac42307c5911","name":"","topic":"shellies/shellyplug-s-040DEB/#","qos":"0","datatype":"utf8","broker":"99603ece.52e2a","nl":false,"rap":false,"inputs":0,"x":170,"y":700,"wires":[["01359424be369378","cd22249708dd2da4"]]},{"id":"01359424be369378","type":"trigger","z":"8ac5ac42307c5911","name":"","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"10","extend":true,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":550,"y":820,"wires":[["a0024f034b91efe5"]]},{"id":"a0024f034b91efe5","type":"change","z":"8ac5ac42307c5911","name":"watchdog Alarm","rules":[{"t":"set","p":"payload","pt":"msg","to":"shelly plug s VPN länger als 10 min offline!","tot":"str"},{"t":"set","p":"WD_VPN","pt":"global","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1420,"y":820,"wires":[["91037bd9f6621d25"]]},{"id":"5c3f5bdcc686a06f","type":"function","z":"8ac5ac42307c5911","name":"midnight","func":"let midnight = parseFloat(msg.payload.meters[0].total) || 0;\nnode.status({text: midnight});\nreturn { topic: \"midnight\", payload:midnight};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":580,"wires":[["c47a3e9fa4d3be92"]]},{"id":"c69d330bc001c5d4","type":"ui_text","z":"8ac5ac42307c5911","group":"d5178392f725ae47","order":5,"width":"6","height":"1","name":"VPN-energy-tag","label":"Tag:","format":"{{msg.payload}}&nbsp;kWh","layout":"row-center","className":"","x":1300,"y":620,"wires":[]},{"id":"ed35e659ffc32152","type":"ui_template","z":"8ac5ac42307c5911","group":"d5178392f725ae47","name":"VPN-wifi","order":3,"width":"1","height":"1","format":"<div style=\"color:{{msg.payload}}; margin:auto;\" <i class=\"fa fa-wifi fa-1x\" aria-hidden=\"true\"> </i></div>\n<div>\n    <center>\n        <small><small><small>{{msg.topic}}</small></small></small>\n    </center>\n</div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":1280,"y":420,"wires":[[]]},{"id":"ba1afd43bf0e2e1f","type":"link in","z":"8ac5ac42307c5911","name":"telegram out","links":["dbd434df290c7ccc","7011c80c99109772","b41418dd7e757344"],"x":1485,"y":700,"wires":[["91037bd9f6621d25"]]},{"id":"a8d689251431bbf0","type":"function","z":"8ac5ac42307c5911","name":"overtemperature","func":"if (msg.payload != \"0\"){\n    msg.payload = \"shelly pulg s VPN Overtemperature Alarm!\"\n    return msg;\n}\nelse {\n    return { reset: 0 };\n} \n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1300,"y":780,"wires":[["9b9b68a2ca670c73"]]},{"id":"014dec58372a9ad3","type":"function","z":"8ac5ac42307c5911","name":"temp > 60","func":"if (msg.payload > 60){\n    msg.payload = \"shelly plug s VPN über 60 Grad!\"\n    return msg;\n}\nelse{\n    return{reset:0};\n}   \n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1280,"y":740,"wires":[["f3533e8bfad8e0a2"]]},{"id":"f3533e8bfad8e0a2","type":"rbe","z":"8ac5ac42307c5911","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":1450,"y":740,"wires":[["91037bd9f6621d25"]]},{"id":"70d06acf0b2cf05f","type":"debug","z":"8ac5ac42307c5911","name":"debug 40","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1680,"y":740,"wires":[]},{"id":"9b9b68a2ca670c73","type":"rbe","z":"8ac5ac42307c5911","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":1450,"y":780,"wires":[["91037bd9f6621d25"]]},{"id":"5f2bfa8d2ab7545a","type":"function","z":"8ac5ac42307c5911","name":"wifi","func":"node.status({ text: msg.payload.wifi_sta.rssi});\nreturn { topic: 'wifi', payload: msg.payload.wifi_sta.rssi};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":520,"wires":[["c47a3e9fa4d3be92"]]},{"id":"9a3dd5a5d10e21db","type":"inject","z":"8ac5ac42307c5911","name":"ervery midnight","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 00 * * *","once":true,"onceDelay":"2","topic":"mid_night","payload":"","payloadType":"date","x":130,"y":460,"wires":[["fd532125656d8500"]]},{"id":"6f569b7cc8777391","type":"inject","z":"8ac5ac42307c5911","name":"every 5 min","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"300","crontab":"","once":true,"onceDelay":"1","topic":"5min","payload":"","payloadType":"date","x":150,"y":420,"wires":[["fd532125656d8500"]]},{"id":"9e452fd0f7c9a5d6","type":"switch","z":"8ac5ac42307c5911","name":"200","property":"statusCode","propertyType":"msg","rules":[{"t":"neq","v":"200","vt":"str"},{"t":"eq","v":"200","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":930,"y":460,"wires":[["b41418dd7e757344"],["134bf4c37eb35cf0"]]},{"id":"2bfeaecc7302f21e","type":"change","z":"8ac5ac42307c5911","name":"url 163","rules":[{"t":"set","p":"url","pt":"msg","to":"http://10.0.0.163/status","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":460,"wires":[["397ec9a0afb01b76"]]},{"id":"cbdab224bdd6cde0","type":"switch","z":"8ac5ac42307c5911","name":"Topic","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"5min","vt":"str"},{"t":"eq","v":"mid_night","vt":"str"},{"t":"eq","v":"firmware","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":490,"y":580,"wires":[["5f2bfa8d2ab7545a"],["5c3f5bdcc686a06f"],["fd5363e43298ac2d"]]},{"id":"b41418dd7e757344","type":"link out","z":"8ac5ac42307c5911","name":"link out 22","mode":"link","links":["ba1afd43bf0e2e1f"],"x":1085,"y":460,"wires":[]},{"id":"d154d3841a1ce9f4","type":"link out","z":"8ac5ac42307c5911","name":"link out 35","mode":"link","links":["f633e61698bc93f8"],"x":1635,"y":780,"wires":[]},{"id":"c67d57a6146516f2","type":"ui_template","z":"8ac5ac42307c5911","group":"d5178392f725ae47","name":"VPN-Firmware","order":1,"width":"1","height":"1","format":"<div style=\"color:{{msg.color}}; margin:auto;\" <i class=\"{{msg.icon}}\" aria-hidden=\"true\"></i> </div>\n<div>\n    <center> <small><small><small>fw</small></small></small> </center>\n</div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":1300,"y":380,"wires":[[]]},{"id":"fd5363e43298ac2d","type":"function","z":"8ac5ac42307c5911","name":"firmware","func":"node.status({ text: msg.payload.update.has_update });\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":640,"wires":[["c47a3e9fa4d3be92"]]},{"id":"290882ea483ecb79","type":"inject","z":"8ac5ac42307c5911","name":"firmware 01:00","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 01 * * *","once":true,"onceDelay":"3","topic":"firmware","payload":"","payloadType":"date","x":140,"y":500,"wires":[["fd532125656d8500"]]},{"id":"59a5aa09eee2f884","type":"inject","z":"8ac5ac42307c5911","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":360,"wires":[["ae2af3f934efd0d3"]]},{"id":"ae2af3f934efd0d3","type":"change","z":"8ac5ac42307c5911","name":"","rules":[{"t":"set","p":"VPN_Stat","pt":"global","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":360,"wires":[[]]},{"id":"397ec9a0afb01b76","type":"http request","z":"8ac5ac42307c5911","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":790,"y":460,"wires":[["9e452fd0f7c9a5d6"]]},{"id":"25f7c9ce5dc00b34","type":"comment","z":"8ac5ac42307c5911","name":"to Telegram","info":"","x":1730,"y":780,"wires":[]},{"id":"5864751f3fb43d4b","type":"inject","z":"8ac5ac42307c5911","name":"reset","props":[{"p":"reset","v":"0","vt":"num"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","x":550,"y":760,"wires":[["01359424be369378","d6b3e5edef5b55b4"]]},{"id":"d6b3e5edef5b55b4","type":"change","z":"8ac5ac42307c5911","name":"WD_VPN on","rules":[{"t":"set","p":"WD_VPN","pt":"global","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":760,"wires":[[]]},{"id":"c47a3e9fa4d3be92","type":"function","z":"8ac5ac42307c5911","name":"shelly plugs VPN 2.0","func":"//=================================================================\nconst id = \"shellyplug-s-040DEB\";    // change id to your shelly id\n//=================================================================\n\nconst timestamp = date_time_string();\nnode_send({ payload: timestamp }, context.get('timestamp'));\nnode.status({ text: timestamp });\nlet wifiout = {};\n\nswitch (msg.topic) {\n    case \"shellies/\" + id + \"/relay/0\":\n        display_status();\n        break;        \n\n    case \"shellies/\" + id + \"/relay/0/power\":\n        display_power();\n        break;        \n\n    case \"shellies/\" + id + \"/relay/0/energy\":\n        display_energy();\n        break;        \n\n    case \"shellies/\" + id + \"/temperature\":\n        display_temperature();\n        break;        \n\n    case \"shellies/\" + id + \"/overtemperature\":\n        display_overtemperature();\n        break;        \n\n    case \"wifi\":\n        let wifiin = msg.payload;\n        wifiout = wifi_out(wifiin);\n        node_send(wifiout, context.get('wifi')); \n        break;       \n        \n    case \"midnight\":\n        context.set('midnight', msg.payload);\n        break;\n\n    case \"firmware\":\n        let update = msg.payload.update.has_update;\n        delete msg.payload;\n        if (update === true) {\n                         \n            node_send({ color: \"red\", icon: \"fa fa-cloud-download\" }, context.get('firmware'));\n        }\n        else {\n            node_send({ payload: timestamp }, context.get('timestamp'));\n            node_send({ color: \"green\", icon: \"fa fa-thumbs-up\" }, context.get('firmware'));\n        }\n        break;\n}\n\nreturn null;\n\n\n//========================================================================\n\nfunction display_status() {\n    let status = msg.payload;\n    status = status === 'off' ? '<font color=\"#000000\">off</font>' : '<font color=\"#ff0000\">on</font>';\n\n    node_send({ payload: status }, context.get('status'));\n}\n\n//--------------------------------------------------------------------\n\nfunction display_power() {\n    let power = msg.payload;\n\n    node_send({ payload: power }, context.get('power'));\n    node_send({ payload: power }, context.get('verlauf'));    \n}\n\n//--------------------------------------------------------------------\n\nfunction display_energy() {\n    let totalenergy = parseFloat(msg.payload);\n    totalenergy = check_energy(totalenergy);\n    let dayenergy = (totalenergy - context.get('midnight'));\n    totalenergy = parseFloat((totalenergy / 60 / 1000).toFixed(3));\n    dayenergy = parseFloat((dayenergy / 60 / 1000).toFixed(3));\n\n    node_send({ payload: totalenergy }, context.get('totalenergy'));\n    node_send({ payload: dayenergy }, context.get('dayenergy')); \n}\n\n//--------------------------------------------------------------------\n\nfunction display_temperature() {\n    let temperature = parseFloat(msg.payload) || 0;\n    let temperaturealarm = temperature;\n    if (temperature < 60) {\n        temperature = '<font color=\"green\">' + temperature + '</font>';\n    }\n    else {\n        temperature = '<font color=\"red\">' + temperature + '</font>';\n    }\n    node_send({ payload: temperature }, context.get('temperature'));\n    node_send({ payload: temperaturealarm }, context.get('temperaturealarm')); \n}\n\n//--------------------------------------------------------------------\n\nfunction display_overtemperature() {\n    let overtemperature = msg.payload || 0;\n    node_send({ payload: overtemperature }, context.get('overtemperature'));\n}\n\n//====================================================================\n\nfunction node_send(value, port) {\n    const messages = new Array(node.outputCount);\n    messages[port] = value;\n    node.send(messages);\n}\n\n//====================================================================\n\nfunction check_energy(data) {\n    let new_energy = data;\n    if (new_energy < context.get('last_energy')) {\n        new_energy = new_energy + context.get('last_energy');\n    }\n    context.set('last_energy', new_energy);\n    return new_energy;\n}\n\n/*\n\n// persisting energy data --> need to change config.js\n\nfunction check_energy(data) {\n    let new_energy = data;\n    if (new_energy < context.get('last_energy,file')) {\n        new_energy = new_energy + context.get('last_energy,file');\n    }\n    context.set('last_energy,file', new_energy);\n    //node.warn(new_energy);\n    return new_energy;\n}\n\n*/\n\n//--------------------------------------------------------------------\n\nfunction wifi_out(wifiin) {\n    let rssi = wifiin;\n    let color;\n    if (rssi < -80) {\n        color = 'red';\n    }\n    else if (rssi < -70) {\n        color = '#FFC300';\n    }\n    else {\n        color = 'green';\n    }\n    rssi = rssi.toString();\n    return ({ \"topic\": rssi, \"payload\": color });\n}\n\n//--------------------------------------------------------------------\n\nfunction date_time_string() {\n    const date = new Date(Date.now());\n    const year = date.getFullYear();\n    const month = (\"0\" + (date.getMonth() + 1)).slice(-2);\n    const day = (\"0\" + date.getDate()).slice(-2);\n    const hours = (\"0\" + date.getHours()).slice(-2);\n    const minutes = (\"0\" + date.getMinutes()).slice(-2);\n    const seconds = (\"0\" + date.getSeconds()).slice(-2);\n    let datetimestring = day + \"-\" + month + \"-\" + year + \" \" + hours + ':' + minutes + ':' + seconds;\n    return datetimestring;\n}\n\n//--------------------------------------------------------------------","outputs":10,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\ncontext.set('firmware',0);\ncontext.set('wifi', 1);\ncontext.set('timestamp', 2);\ncontext.set('power', 3);\ncontext.set('verlauf', 3);\ncontext.set('totalenergy', 4);\ncontext.set('dayenergy', 5);\ncontext.set('status', 6);\ncontext.set('temperature', 7);\ncontext.set('temperaturealarm', 8);\ncontext.set('overtemperature', 9);\n\ncontext.set('last_energy', 0.0);","finalize":"","libs":[],"x":1000,"y":580,"wires":[["c67d57a6146516f2"],["ed35e659ffc32152"],["36555df3eb8a5eb2"],["d6ff683a9330f8e5","62b509263e8777b9"],["639948b701b222f5"],["c69d330bc001c5d4"],["5a11eb44ee184b34"],["126702277bb45ff3"],["014dec58372a9ad3"],["a8d689251431bbf0"]]},{"id":"ed8dd632559d2a94","type":"switch","z":"8ac5ac42307c5911","name":"WD_VPN on","property":"WD_VPN","propertyType":"global","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":510,"y":460,"wires":[["2bfeaecc7302f21e"]]},{"id":"fd532125656d8500","type":"switch","z":"8ac5ac42307c5911","name":"VPN_Stat on","property":"VPN_Stat","propertyType":"global","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":350,"y":460,"wires":[["ed8dd632559d2a94"]]},{"id":"67f38a6ed90b27c7","type":"junction","z":"8ac5ac42307c5911","x":1220,"y":420,"wires":[[]]},{"id":"91037bd9f6621d25","type":"junction","z":"8ac5ac42307c5911","x":1560,"y":760,"wires":[["70d06acf0b2cf05f","d154d3841a1ce9f4"]]},{"id":"134bf4c37eb35cf0","type":"junction","z":"8ac5ac42307c5911","x":340,"y":520,"wires":[["cbdab224bdd6cde0"]]},{"id":"cd22249708dd2da4","type":"junction","z":"8ac5ac42307c5911","x":780,"y":700,"wires":[["c47a3e9fa4d3be92"]]},{"id":"d5178392f725ae47","type":"ui_group","name":"Group 1","tab":"743fd75e.f52cb8","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"99603ece.52e2a","type":"mqtt-broker","broker":"10.0.0.43","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":4,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"743fd75e.f52cb8","type":"ui_tab","name":"Meßsteckdosen","icon":"dashboard","order":1,"disabled":false,"hidden":false}]