Hi guys,
So I have the following flows to get voltage, power and current sensors added into HA :
[{"id":"6047f37e.79fcdc","type":"tuya-local","z":"390f3759.482b68","devName":"switch_1","devIp":"192.168.0.112","devId":"10470280dc4f22ed6311","devKey":"aa33d4b63d2xxxxx","protocolVer":"3.3","renameSchema":"","filterCB":"","x":320,"y":660,"wires":[["e7a19580.d61c48"]]},{"id":"11300381.5e29bc","type":"tuya-local","z":"390f3759.482b68","devName":"switch_2","devIp":"192.168.0.110","devId":"82141708dc4f22edb4d8","devKey":"2f86e9fc8cf4xxxxx","protocolVer":"3.3","renameSchema":"","filterCB":"","x":340,"y":860,"wires":[["b64ef5fa.405dd8"]]},{"id":"e7a19580.d61c48","type":"function","z":"390f3759.482b68","name":"","func":"if (\"payload\" in msg) {\n return [msg,msg];\n} else {\n return [null,msg];\n}","outputs":2,"noerr":0,"x":510,"y":660,"wires":[["16c52854.cde858"],[]]},{"id":"16c52854.cde858","type":"function","z":"390f3759.482b68","name":"","func":"const dps = msg.payload.dps;\nlet current = { payload: \"0 mA\"};\nlet power = { payload: \"0 W\"};\nlet voltage = { payload: \"0 V\"};\n\n\nif (\"18\" in dps) {\n current.payload = `${dps['18']} mA`;\n}\n\nif (\"19\" in dps) {\n power.payload = `${dps['19']/10} `;\n}\n\nif (\"20\" in dps) {\n voltage.payload = `${dps['20'] /10} V`;\n}\n\nreturn [current, power, voltage];","outputs":3,"noerr":0,"x":690,"y":660,"wires":[["bfe2424c.9e347"],["696c4381.2d8dfc","b333122c.19b3a"],["ad7770f8.44bd5"]]},{"id":"bfe2424c.9e347","type":"ha-entity","z":"390f3759.482b68","name":"current","server":"f4fba9ec.51b128","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"mA"}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","x":900,"y":600,"wires":[[]]},{"id":"696c4381.2d8dfc","type":"ha-entity","z":"390f3759.482b68","name":"power","server":"f4fba9ec.51b128","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","x":890,"y":660,"wires":[[]]},{"id":"ad7770f8.44bd5","type":"ha-entity","z":"390f3759.482b68","name":"voltage","server":"f4fba9ec.51b128","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"V"}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","x":900,"y":720,"wires":[[]]},{"id":"91e6cf.0a51f93","type":"inject","z":"390f3759.482b68","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":130,"y":660,"wires":[["6047f37e.79fcdc"]]},{"id":"b64ef5fa.405dd8","type":"function","z":"390f3759.482b68","name":"","func":"if (\"payload\" in msg) {\n return [msg,msg];\n} else {\n return [null,msg];\n}","outputs":2,"noerr":0,"x":530,"y":860,"wires":[["fac2c30e.21554"],[]]},{"id":"fac2c30e.21554","type":"function","z":"390f3759.482b68","name":"","func":"const dps = msg.payload.dps;\nlet current = { payload: \"0 mA\"};\nlet power = { payload: \"0 W\"};\nlet voltage = { payload: \"0 V\"};\n\n\nif (\"18\" in dps) {\n current.payload = `${dps['18']} mA`;\n}\n\nif (\"19\" in dps) {\n power.payload = `${dps['19']/10} `;\n}\n\nif (\"20\" in dps) {\n voltage.payload = `${dps['20'] /10} V`;\n}\n\nreturn [current, power, voltage];","outputs":3,"noerr":0,"x":710,"y":860,"wires":[["e65b7155.c8684"],["2ef1b465.a11edc"],["304e598.59850a6"]]},{"id":"e65b7155.c8684","type":"ha-entity","z":"390f3759.482b68","name":"current","server":"f4fba9ec.51b128","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"mA"}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","x":920,"y":800,"wires":[[]]},{"id":"2ef1b465.a11edc","type":"ha-entity","z":"390f3759.482b68","name":"power","server":"f4fba9ec.51b128","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","x":910,"y":860,"wires":[[]]},{"id":"304e598.59850a6","type":"ha-entity","z":"390f3759.482b68","name":"volate","server":"f4fba9ec.51b128","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"V"}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","x":910,"y":920,"wires":[[]]},{"id":"94c15572.d36398","type":"inject","z":"390f3759.482b68","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":150,"y":860,"wires":[["11300381.5e29bc"]]},{"id":"b333122c.19b3a","type":"debug","z":"390f3759.482b68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1120,"y":520,"wires":[]},{"id":"f4fba9ec.51b128","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
The way it’s setup will need a different flow for each different power plug but I’m pretty sure that by passwing each plug name as a variable you could optimize this a lot and make it so that all plugs are in the same flow, something like this :
My knowledge with Node Red is very limited so I don’t know how I can make this work the way I descbribed, would really appreciate some help with it !
Thanks