NodeRED flow to forward all MQTT data to emoncms.org

Currently all MQTT messages posted to emon/<node-name>/<key-name> MQTT topic in the emonPi appear as local Emoncms Inputs with the sub topic used as the Emoncms node name e.g.

emon/emontx/power1 value

See MQTT — OpenEnergyMonitor 0.0.1 documentation

Data coming in via emonhub can easily be posted to Emoncms.org or any other remote emoncms server.

However, if the MQTT messages are not coming via emonhub (i.e posted directly to emonPi MQTT server by another servie or device like the WiFi MQTT relay thermostat) there is currently no way to forward this data to emoncms.org. I’ve just written a simple nodeRED flow to do just this

This works well since as of this month Emoncms.org now suports alphanumeric nodenames :slight_smile:

NodeRED is ready built into all emonPis, Just browser to http://emonpi:1880

see: https://guide.openenergymonitor.org/integrations/nodered

Here is the nodered flow export:

2 Likes

I tried to use this script, but it seems that it only posts the first item of a group?

I found a solution: (i was mistaken: the solution above will create multiple nodes in the target emoncms based on the nodenome from the mqtt and not group it under one node. I changed it to push multiple values and mqtt nodenames to one “node” in emoncms.

Create a “publish to MQTT” per output you want to share in your emoncms (base).

Change the “nodename from MQTT sub-topic” to:

var topic = msg.topic
var arr = topic.split("/");
var length2 = arr.length;
node = arr[length2-1];
var waarde = msg.payload;
msg.payload = node + ":" + waarde;

return msg; 

And fill in the Node name in “Emoncms” where you want it to show up in the other emoncms.

1 Like

This worked for me sending to emoncms.org.
But i’m trying to send to my local emoncms and didnt work. Aways getting API error.

Are you using the right API key for your local instance?

I think so. See image below. And yes, i’m putting the right API Key.

Ok, i did something different and now are working, posting to my local emoncms.

You should be able to use Valid JSON rather than Legacy Processing.

I am surprised this works as the JSON is not a ‘flat’ JSON (as per the info panel for the node).

You have the same error as your other thread in not just sending the payload.ENERGY portion of the original message.

You should be able to put the time element into a msg.time part of the msg (again as per the info panel on the node).

IIRC, the time format sonoff uses is not parsed correctly by javascript as it is not a valid time format (or I might be remembering that incorrectly). If you check your logs you may see a message about whether a valid time has been used or not (Set log to INFO level).

Evening All,

I know this is old topic. I would like to parse data straigh to the emoncms.org using this flow.

Unfortunately I am rubbish at writing function json expressions.

Using mqtt explorer I want to get my heatpump flow, return temps in.

If I plug in emon/heatpumptemps/# this flow doesnt work for me.

Looks like this.

What do I have to write in the fuction node to get this working?

Any help is much aprreciated :slight_smile:

So as in the post 2 above, write a flow to subscribe to the topic, and use a debug node so you can see how the data appears.

I suspect you can simply subscribe to the individual topics such as emon/heatpumptemps/T3 and send that to emoncms.org using the emoncms flow. This is the simplest route.

5 MQTT subscribe nodes, not pretty, but it should work.

Specific Node-RED questions should go onto the NR Forum as it isn’t specific to emoncms.

1 Like