EMC from Temperature and Humidity

Listens to an MQTT broker for temperature and humidity. Then calculates the EMC (equilibrium moisture content) and posts the calculated value to an MQTT broker. Designed for use with an EmonCMS.

Written by Berkeley Fergusson in August 2016.

[{"id":"83cf3f33.85205","type":"mqtt-broker","z":"","broker":"10.1.10.200","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willRetain":null,"willPayload":"","birthTopic":"","birthQos":"0","birthRetain":null,"birthPayload":""},{"id":"68c3c93f.51d4b8","type":"mqtt in","z":"5ab7703b.4b958","name":"Bench Temperature","topic":"emon/EmonTH1/temperature","broker":"83cf3f33.85205","x":141,"y":118,"wires":[["fef4f107.56746"]]},{"id":"7d4ed145.fe8ee","type":"debug","z":"5ab7703b.4b958","name":"","active":false,"console":"false","complete":"true","x":919,"y":261,"wires":[]},{"id":"fef4f107.56746","type":"function","z":"5ab7703b.4b958","name":"str to float","func":"var temp = parseFloat(msg.payload)\nnewMsg = msg\nnewMsg.payload = temp\nreturn newMsg;","outputs":1,"noerr":0,"x":166,"y":176,"wires":[["a19bc9bf.b48de8"]]},{"id":"d8f27098.71576","type":"function","z":"5ab7703b.4b958","name":"All Values in one Msg","func":"context.data = context.data || {};\nif(msg.payload < 0){\n    var hum = msg.payload + 101;\n    context.data.humidity = hum;\n    msg = null;\n} else if (msg.payload >= 0) {\n    var temp = msg.payload - 100;\n    context.data.tempF = temp;\n    msg = null;\n} else msg = null;\n\nif(context.data.humidity != null && context.data.tempF != null){\n    var hum = context.data.humidity;\n    var temp = context.data.tempF;\n    context.data = null;\n    return {humidity: hum, tempF: temp};\n    //return {humidity: context.data.humidity, temp: context.data.tempF};\n} else return msg;","outputs":"1","noerr":0,"x":449,"y":365,"wires":[["f0a17ab5.0a8f58"]]},{"id":"c3cb9f42.f89e1","type":"mqtt in","z":"5ab7703b.4b958","name":"Bench Humidity","topic":"emon/EmonTH1/humidity","broker":"83cf3f33.85205","x":141,"y":429,"wires":[["edb06f6a.47437"]]},{"id":"edb06f6a.47437","type":"function","z":"5ab7703b.4b958","name":"str to float","func":"var temp = parseFloat(msg.payload)\nnewMsg = msg\nnewMsg.payload = temp\nreturn newMsg;","outputs":1,"noerr":0,"x":140,"y":480,"wires":[["6da21578.b689ec"]]},{"id":"6da21578.b689ec","type":"function","z":"5ab7703b.4b958","name":"Make Negative","func":"var hum = msg.payload\nhum -= 101\nmsg.payload = hum\nreturn msg;","outputs":1,"noerr":0,"x":142,"y":545,"wires":[["d8f27098.71576"]]},{"id":"a19bc9bf.b48de8","type":"function","z":"5ab7703b.4b958","name":"C to F","func":"var temp = msg.payload;\ntemp = temp * 1.8 + 32;\nmsg.payload = temp;\n\nreturn msg;","outputs":1,"noerr":0,"x":160,"y":238,"wires":[["3136cdf9.5c67d2"]]},{"id":"3136cdf9.5c67d2","type":"function","z":"5ab7703b.4b958","name":"Make Positive","func":"var temp = msg.payload;\ntemp += 100;\nmsg.payload = temp;\nreturn msg;","outputs":1,"noerr":0,"x":152,"y":304,"wires":[["d8f27098.71576"]]},{"id":"f0a17ab5.0a8f58","type":"function","z":"5ab7703b.4b958","name":"EMC calculation","func":"var tf = msg.tempF\nvar h = msg.humidity\nh /= 100;\nvar t2 = tf * tf;\nvar w = 330 + 0.452 * tf + 0.00415 * t2;\nvar k = 0.791 + 0.000463 * tf - 0.000000844 * t2;\nvar ka = 6.34 + 0.000775 * tf - 0.0000935 * t2;\nvar kb = 1.09 + 0.0284 * tf - 0.0000904 * t2;\nvar m = 1800 / w * ( k * h / (1 - k * h)+ (ka * k * h + 2 * ka * kb * k * k * h * h)/ (1 + ka * k * h + ka * kb * k * k * h * h));\nreturn {\"payload\": m};","outputs":1,"noerr":0,"x":670,"y":366,"wires":[["7d4ed145.fe8ee","5f8222bd.4b86ec"]]},{"id":"5f8222bd.4b86ec","type":"mqtt out","z":"5ab7703b.4b958","name":"","topic":"emon/EmonTH1/EMC2_Bench","qos":"","retain":"","broker":"83cf3f33.85205","x":941,"y":366,"wires":[]}]

Flow Info

Created 9 years ago
Updated 8 years, 10 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x1)
  • function (x7)
  • mqtt in (x2)
  • mqtt out (x1)
  • mqtt-broker (x1)

Tags

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