Parsing Open Energy Monitor emonTH sensor

Flow to parse the raw data from an Open Energy Monitor emonTH sensor (http://openenergymonitor.org/emon/modules/emonTH).

As an added bonus the flow also adds the dew point based on the Temperature and Humidity.

[{"id":"ba386057.845d3","type":"mqtt-broker","broker":"localhost","port":"1883"},{"id":"407cfedc.785068","type":"mqtt in","name":"Bedroom node Raw","topic":"home/bedroom/node/raw","broker":"ba386057.845d3","x":91,"y":487,"z":"ae4469c6.312038","wires":[["afe43196.f6f178"]]},{"id":"afe43196.f6f178","type":"function","name":"Parse emonTH ","func":"// console.log(msg.topic, msg.payload, msg.qos, msg.retain);\n// context = {};\n//retrieve byte data from array\nvar raw= JSON.parse(msg.payload);\nbuf = new Buffer(raw);\n\nmsg.environment = new Object();\n\n//data is sent through *10 to avoid floating points - so divide\n//to get the real value back\nmsg.environment.Temperature= (buf.readInt16LE(0))/10;\nmsg.environment.Humidity = (buf.readInt16LE(4))/10;\nmsg.environment.Voltage = (buf.readInt16LE(6))/10;\n\n\nreturn msg;","outputs":"1","x":261,"y":487,"z":"ae4469c6.312038","wires":[["f8ba4588.a61f8"]]},{"id":"8edff8be.67d318","type":"mqtt out","name":"BedroomTemp","topic":"home/bedroom/temp","broker":"ba386057.845d3","x":798,"y":449.9999694824219,"z":"ae4469c6.312038","wires":[]},{"id":"f7dd8271.8ecca","type":"mqtt out","name":"Bedroom Voltage","topic":"home/bedroom/voltage","broker":"ba386057.845d3","x":810,"y":558.9999389648438,"z":"ae4469c6.312038","wires":[]},{"id":"d7a1e116.53f158","type":"mqtt out","name":"Bedroom Humidity","topic":"home/bedroom/humidity","broker":"ba386057.845d3","x":809,"y":485.9999694824219,"z":"ae4469c6.312038","wires":[]},{"id":"f8ba4588.a61f8","type":"function","name":"Add Dew Point","func":"// The received message is stored in 'msg'\n// It will have at least a 'payload' property:\n//   console.log(msg.payload);\n// The 'context' object is available to store state\n// between invocations of the function\n//   context = {};\n\n// expects environment.temp && environment.humidity \nif(msg.environment != null)\n\t{\n\t\tvar temp2 = msg.environment.Temperature;\n\t\tvar r = msg.environment.Humidity;\n\t  \n\t\tif(temp2 !=null && !isNaN(temp2)  && r !=null && !isNaN(r))\n\t   \t{\n\t\t    \n\t\t    var temp = -1.0*temp2;\n\t\t    es = 6.112*Math.exp(-1.0*17.67*temp/(243.5 - temp));\n\t\t    ed = r/100.0*es;\n\t\t    eln = Math.log(ed/6.112);\n\t\t    td = -243.5*eln/(eln - 17.67 );\n\t\t    msg.environment.Dewpoint = td.toFixed(2);\n\t\t}\n\t}\nreturn msg;","outputs":1,"x":424,"y":487.00006103515625,"z":"ae4469c6.312038","wires":[["48de5d6.4f81324"]]},{"id":"48de5d6.4f81324","type":"function","name":"Route Messages","func":"// The received message is stored in 'msg'\n// It will have at least a 'payload' property:\n//   console.log(msg.payload);\n// The 'context' object is available to store state\n// between invocations of the function\n//   context = {};\n//create json text\n\nif(msg.environment == null)\n{\n\t//no data - stop here\n\treturn null;\n}\n\njsonText = JSON.stringify(msg.environment);\n \nvar msg1 = {payload:JSON.stringify(msg.environment)};\nvar msg2 = {payload:msg.environment.Temperature};\nvar msg3 = {payload:msg.environment.Humidity};\nvar msg4 = {payload:msg.environment.Dewpoint};\nvar msg5 = {payload:msg.environment.Voltage};\n\n\nreturn [msg1,msg2,msg3,msg4,msg5];","outputs":"5","x":583,"y":487.00006103515625,"z":"ae4469c6.312038","wires":[["c1655cf2.b1ff58","7cec7c1.f70de84"],["8edff8be.67d318"],["d7a1e116.53f158"],["80cfab38.cb242"],["f7dd8271.8ecca"]]},{"id":"80cfab38.cb242","type":"mqtt out","name":"Bedroom Dew Point","topic":"home/bedroom/dewpoint","broker":"ba386057.845d3","x":814,"y":523.0000305175781,"z":"ae4469c6.312038","wires":[]},{"id":"c1655cf2.b1ff58","type":"mqtt out","name":"Bedroom Json","topic":"home/bedroom/json","broker":"ba386057.845d3","x":796,"y":378.00006103515625,"z":"ae4469c6.312038","wires":[]},{"id":"7cec7c1.f70de84","type":"debug","name":"Bedroom Json","active":true,"complete":"false","x":797,"y":413.0000305175781,"z":"ae4469c6.312038","wires":[]}]
bramleyd

Flow Info

created 3 years, 6 months ago

Node Types

Core
  • debug (x1)
  • function (x3)
  • mqtt in (x1)
  • mqtt out (x5)
  • mqtt-broker (x1)

Tags

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