Need to write one function that will return 3 values

Here's a screen-shot of my simple dashboard.

I'm using a PZEM-04 module with a split-ring current transformer feeding into a Wemos D1 Mini flashed with Tasmota that transmits to Node-RED via MQTT (very similar to your system).

Here's a screen-shot of the NR flow.

And here's the flow-code that uses a dynamic band changer for the Power-gauge.

[{"id":"47ec6f8.e8c9b9","type":"ui_gauge","z":"f0f0fcca.cf3ac8","name":"","group":"900b126f.c721c8","order":2,"width":"3","height":"2","gtype":"gage","title":"","label":"units","format":"{{value}}","min":"200","max":"250","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":710,"y":180,"wires":[]},{"id":"ea161a29.89ceb8","type":"function","z":"f0f0fcca.cf3ac8","name":"","func":"msg.payload = msg.payload.ENERGY.Voltage;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":550,"y":180,"wires":[["47ec6f8.e8c9b9"]]},{"id":"5ae7768c.60cf88","type":"ui_gauge","z":"f0f0fcca.cf3ac8","name":"","group":"c18058f9.c02498","order":2,"width":"3","height":"2","gtype":"gage","title":"","label":"units","format":"{{value}}","min":"0","max":"10","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":710,"y":220,"wires":[]},{"id":"1f0c06ab.5660b1","type":"function","z":"f0f0fcca.cf3ac8","name":"","func":"var current = msg.payload.ENERGY.Current;\n\nflow.set(\"current\",current);\nmsg.payload = current.toFixed(2);\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":220,"wires":[["5ae7768c.60cf88"]]},{"id":"82d6bd9.cb8dcc","type":"ui_gauge","z":"f0f0fcca.cf3ac8","name":"","group":"a4a4f685.020db8","order":2,"width":"3","height":"2","gtype":"gage","title":"","label":"units","format":"{{value}}","min":"0","max":"1","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":710,"y":260,"wires":[]},{"id":"97b76b0c.33ebb","type":"function","z":"f0f0fcca.cf3ac8","name":"","func":"msg.payload = msg.payload.ENERGY.Factor;\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":260,"wires":[["82d6bd9.cb8dcc"]]},{"id":"763ebc9b.9285fc","type":"ui_gauge","z":"f0f0fcca.cf3ac8","name":"","group":"9ef7a427.101b48","order":2,"width":"3","height":"2","gtype":"gage","title":"Power","label":"units","format":"{{value}}","min":"200","max":"250","colors":["#c0c0c0","#c0c0c0","#c0c0c0"],"seg1":"","seg2":"","x":990,"y":360,"wires":[]},{"id":"5fdefe64.082328","type":"function","z":"f0f0fcca.cf3ac8","name":"Dynamically alter guage band","func":"var max = 300;\nvar min = 0;\n\nvar voltage = msg.payload.ENERGY.Voltage;\nvar power_factor = msg.payload.ENERGY.Factor;\n\nvar current = flow.get(\"current\") || 1.0;\n\nvar power = voltage * current;\npower = power.toFixed(0);\n\nif (power > 5000) {\n    max = 6000;\n    min = 5000;\n}\nelse if (power > 4000) {\n    max = 5000;\n    min = 4000;\n}\nelse if (power > 3000) {\n    max = 4000;\n    min = 3000;\n}\nelse if (power > 2000) {\n    max = 3000;\n    min = 2000;\n}\nelse if (power > 1000) {\n    max = 2000;\n    min = 1000;\n}\nelse if (power >500) {\n    max=1000;\n    min=500;\n}\nelse {\n    max=500;\n    min=0;\n}\nmsg = {payload:power,ui_control:{min:min,max:max},topic:\"Power_Watts\"};\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":730,"y":360,"wires":[["763ebc9b.9285fc","9480ad7d.79ca18"]]},{"id":"9fc093bb.f4e298","type":"mqtt in","z":"f0f0fcca.cf3ac8","name":"","topic":"tele/energy_sensor/SENSOR/#","qos":"0","datatype":"json","broker":"628037a0.fd0ec8","x":210,"y":180,"wires":[["51a1a04c.4b722","ea161a29.89ceb8","1f0c06ab.5660b1","97b76b0c.33ebb","97591472.5b5308"]]},{"id":"51a1a04c.4b722","type":"debug","z":"f0f0fcca.cf3ac8","name":"","active":false,"console":"false","complete":"false","x":490,"y":100,"wires":[]},{"id":"9480ad7d.79ca18","type":"ui_chart","z":"f0f0fcca.cf3ac8","name":"Watts","group":"bb436026.d3b128","order":0,"width":"12","height":"8","label":"Energy consumption over the last 2-Hrs","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"step","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"2","removeOlderPoints":"520","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":990,"y":440,"wires":[[]]},{"id":"78f8ecf5.0b398c","type":"ui_template","z":"f0f0fcca.cf3ac8","group":"900b126f.c721c8","name":"","order":1,"width":0,"height":0,"format":"<style>\n.masonry-container {\n    width: 800px;\n}\n</style>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","x":720,"y":100,"wires":[[]]},{"id":"2af414b4.3834dc","type":"inject","z":"f0f0fcca.cf3ac8","name":"Clear the graph","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":440,"wires":[["9eeeb91.dd45748"]]},{"id":"9eeeb91.dd45748","type":"function","z":"f0f0fcca.cf3ac8","name":"","func":"msg.payload = [];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":440,"wires":[["9480ad7d.79ca18"]]},{"id":"97591472.5b5308","type":"delay","z":"f0f0fcca.cf3ac8","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":480,"y":360,"wires":[["5fdefe64.082328"]]},{"id":"900b126f.c721c8","type":"ui_group","z":"","name":"Voltage","tab":"6d8b03e2.31316c","order":1,"disp":true,"width":"3","collapse":false},{"id":"c18058f9.c02498","type":"ui_group","z":"","name":"Current","tab":"6d8b03e2.31316c","order":2,"disp":true,"width":"3","collapse":false},{"id":"a4a4f685.020db8","type":"ui_group","z":"","name":"Power_factor","tab":"6d8b03e2.31316c","order":3,"disp":true,"width":"3","collapse":false},{"id":"9ef7a427.101b48","type":"ui_group","z":"","name":"Power","tab":"6d8b03e2.31316c","order":4,"disp":true,"width":"3","collapse":false},{"id":"628037a0.fd0ec8","type":"mqtt-broker","z":"","name":"156 server","broker":"192.168.1.154","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"bb436026.d3b128","type":"ui_group","z":"","name":"Energy Plot","tab":"6d8b03e2.31316c","order":5,"disp":true,"width":"12","collapse":false},{"id":"6d8b03e2.31316c","type":"ui_tab","z":"","name":"Home_Energy_Monitor","icon":"dashboard","order":19,"disabled":false,"hidden":false}]
2 Likes