Logging to EmonCMS with NodeRED

We have a working NodeRED flow (pictured below) that pulls from two MQTT feeds and calculates a value that we would like to then post to an EmonCMS feed. For now it just posts in the debugger node.

What is the best way to log these values in an EmonCMS feed?

-Berkeley Fergusson
CS Intern SolarMill

not sure if this is a local emoncms and not sure what pops out of the EMC calculation…

For a local emoncms you can install npm install node-red-node-emoncms and then replace the msg EMC debug with emoncms in

This one writes to node 16:

–

–

1 Like

-or-

you can send it right back to mqtt. This writes to emon/RF2/energy_kWh

–

 

The choice depends on your requirements for writing the data.

1 Like

How can you tell what topic a feed is listening to for MQTT?

Also it is on a local emoncms and a floating point number comes out of EMC calculation. For some reason I don’t see my feed updating when using the node-red-node-emoncms node. I’m pretty sure I have the correct Base URL and API key.

Take a look at this section since MQTT is a publisher:
https://guide.openenergymonitor.org/technical/mqtt/#mqtt-publishers

for my example above the [basetopic]/[node]/[keyname] equals this:
[basetopic] = emon
[node] = RF2
  • this is my made up name - you could call it “Intern” or “Berkeley” or anything you want
[keyname] = energy_kWh
  • again this is my made up name - you could call it “EMC_Calc_Out”

and then create your feeds as you normally would.

1 Like

Do you see your output “EMC Calc” on the Input page? (in the menus Setup > Inputs)

For my Node-RED node “emoncms in” this is what I see on the Inputs page:

1 Like

The NodeRED Emoncms node can also be used to post remotly to Emoncms.org

Alternativly you could construct your own HTTP GET request in nodeRED to post to Emoncms usng the Emoncms API: Emoncms - site api

Using MQTT worked. Here is a link to the flow and a screenshot of it for anyone interested in using it.

Thanks for the help Glyn and Jon.

Update: here is a copy of the flow

[{"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":[]}]

And here is a link back to the original project this was needed for:
EMC Monitoring Version 2.0 - Using stock EmonTH firmware

-Berkeley

2 Likes