Node-RED Current Cost XML Parser

Simple xml to json parser with two data functions - one just creates Watts and the other temperature.

How-to

  • Import the flow.json to Node-RED.
  • Reconfigure serial port and baud rate to suit your currentcost device.
  • Deploy.
[{"id":"2024a60c.dfdb5a","type":"serial-port","serialport":"/dev/ttyUSB0","serialbaud":"57600","databits":"8","parity":"none","stopbits":"1","newline":"\\n","bin":"false","out":"char","addchar":"false"},{"id":"88ebe692.771418","type":"function","z":"9e538f88.61ac7","name":"CCost W only","func":"\nvar result = msg.payload;\nmsg.topic=\"ccost/w\";\nif (result.msg.ch1) {\n\tmsg.payload = (result.msg.ch1[0].watts[0])*1;\n\treturn msg;\n}\nelse return null;","outputs":1,"noerr":0,"x":434.96429443359375,"y":1070.75,"wires":[[]]},{"id":"342bcbbd.cbd434","type":"function","z":"9e538f88.61ac7","name":"CCost Temp only","func":"\nvar result = msg.payload;\n\nmsg.topic=\"temp\";\nmsg.payload = (result.msg.tmpr[0])*1 -2;\n\nif (msg.payload  != context.oldt) {\n\treturn msg;\n}\nreturn null;","outputs":1,"noerr":0,"x":425.32720947265625,"y":1030.5296630859375,"wires":[[]]},{"id":"e6fe2f39.1901d","type":"function","z":"9e538f88.61ac7","name":"take out history","func":"\nif (msg.payload == null) return null;\nif (msg.payload.msg == null) return null;\nif (msg.payload.msg.hist != null) return null;\nif (msg.payload.msg.id[0] !== \"03010\") return null;\n\nreturn msg;","outputs":1,"x":214.36902618408203,"y":1184.321361541748,"wires":[["88ebe692.771418","342bcbbd.cbd434"]]},{"id":"c7a39bd5.385c68","type":"comment","z":"9e538f88.61ac7","name":"Handle CurrentCost data","info":"","x":157.53565216064453,"y":989.2262573242188,"wires":[]},{"id":"9996d500.666928","type":"function","z":"9e538f88.61ac7","name":"check it's xml","func":"if (msg.payload.slice(0,4) != \"<msg\") return null;\n//console.log(msg.payload.slice(-6,-3));\nif (msg.payload.slice(-6,-3) != \"msg\") return null;\n\nreturn msg;","outputs":1,"x":159.03565216064453,"y":1079.8214836120605,"wires":[["11819ae6.ee7e65"]]},{"id":"3960b4e7.c69f4c","type":"serial in","z":"9e538f88.61ac7","name":"","serial":"2024a60c.dfdb5a","x":121.11654663085938,"y":1035.035813331604,"wires":[["9996d500.666928"]]},{"id":"11819ae6.ee7e65","type":"xml","z":"9e538f88.61ac7","name":"","x":181.23556518554688,"y":1130.1549072265625,"wires":[["e6fe2f39.1901d"]]}]

Flow Info

Created 11 years, 5 months ago
Updated 8 years, 11 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • comment (x1)
  • function (x4)
  • xml (x1)
Other
  • serial in (x1)
  • serial-port (x1)

Tags

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