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 - Guide | OpenEnergyMonitor

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: Node-RED - Guide | OpenEnergyMonitor

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).