MQTT translation pattern emoncms - Tasmota SENSOR telemetry

Hi, I have many openenrgymonitor sensor (emontx power, emonth…) and now I have bought a son off power.
It publish messages via mqtt to the embedded emoncms broker.
Through topic emon/sonoff/SENSOR it sends its SENSOR telemetry.

{“Time”:“2018-06-19T22:01:38”,“ENERGY”:{“Total”:0,“Yesterday”:0,“Today”:0,“Period”:0,“Power”:17,“Factor”:0.54,“Voltage”:226,“Current”:0.144}}

in emoncms the value shown is NULL.
How can I “translate” this string to its “default” pattern in order be understandable to emoncms?
I would like to have at least Power value…

Thanks

You will need to use Node-Red as an intermediate step to split out the part of the message you want. How is your EmonCMS system hosted/installed?

You can put a simple Node-Red function between an incoming MQTT node (using a different base topic for the sonoff data) and an outgoing MQTT node using the emon base topic. You are sending the data out of the Sonoff to the MQTT broker as /sonoff/SENSOR and then sending it from node-red to the broker as emon/sonoff/SENSOR.

var newmsg ={};

msg.payload = JSON.parse(msg.payload);
newmsg.payload = msg.payload.ENERGY;

return newmsg;

image

Used ur example and didnt work.
Its posting only SENSOR key with NULL value.

Ok, so put in a debug node on the receiving mqtt node. What is the received message?

Actually looking at those nodes, the red triangle on the mqtt node indicates it is not connecting to the broker or it is not configured correctly (I think). I presume you did deploy the flow?

As u can see. I think its all ok.

My function just pases the ENERGY portion of the message.

Depending on what version/branch of Emoncms you are running you may be able to pass the time as well if you need to but it need to be within a flat and not nested JSON string.

[edit] note javascript is case sensitive.

I’m running emonSD-26Oct17.

if I can help anybody with an example, I had this same isssue yesterday. Got a Tasmota Sonoff firmware (6.13) running on a esp8266 and I want to send the tempsensors DS18B20 to emoncms for recording.

this is how I did it with node-red example flow:

[{"id":"f684eeeb.842cf8","type":"emoncms","z":"75b73f52.a8a828","name":"CV Ketel","emonServer":"6b565123.62a9f8","nodegroup":"3","datatype":"legacy","x":1020,"y":1920,"wires":[]},{"id":"97360f2b.d94308","type":"mqtt in","z":"75b73f52.a8a828","name":"","topic":"tele/temp_sensor1/SENSOR/#","qos":"2","broker":"43ad90ee.18186","x":270,"y":1960,"wires":[["8ca63d65.2aac98","5e6d9035.2988"]]},{"id":"8ca63d65.2aac98","type":"debug","z":"75b73f52.a8a828","name":"tele/temp_sensor1/SENSOR","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":560,"y":1880,"wires":[]},{"id":"81edafe5.62e6a","type":"debug","z":"75b73f52.a8a828","name":"emoncms_temp_wemos","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1070,"y":2000,"wires":[]},{"id":"5e6d9035.2988","type":"json","z":"75b73f52.a8a828","name":"","pretty":false,"x":490,"y":1960,"wires":[["25d10322.bb704c"]]},{"id":"25d10322.bb704c","type":"change","z":"75b73f52.a8a828","name":"substring tasmota JSON","rules":[{"t":"move","p":"payload.DS18B20-1.Temperature","pt":"msg","to":"payload.temp1","tot":"msg"},{"t":"move","p":"payload.DS18B20-2.Temperature","pt":"msg","to":"payload.temp2","tot":"msg"},{"t":"move","p":"payload.DS18B20-3.Temperature","pt":"msg","to":"payload.temp3","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":2020,"wires":[["da1999b2.c1f058"]]},{"id":"da1999b2.c1f058","type":"function","z":"75b73f52.a8a828","name":"prepaire EmonCMS","func":"tijd = msg.payload.Time\nwarmW = msg.payload.temp1;\nketelR = msg.payload.temp2;\nketelI = msg.payload.temp3;\nmsg = {warm_water:(warmW),ketel_retour:(ketelR),ketel_aanvoer:(ketelI)};\nmytime = new Date().toISOString();\nreturn {payload:msg, time: mytime};","outputs":1,"noerr":0,"x":810,"y":1960,"wires":[["81edafe5.62e6a","f684eeeb.842cf8"]]},{"id":"6b565123.62a9f8","type":"emoncms-server","z":"","server":"http://energy.bluemotica.nl","name":""},{"id":"43ad90ee.18186","type":"mqtt-broker","z":"","name":"","broker":"mqtt.bluemotica.nl","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":false,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willRetain":null,"willPayload":"","birthTopic":"","birthQos":"0","birthRetain":null,"birthPayload":""}]

Input is the MQTT from the tasmota firmware, output is a emoncms input node.
I used the JSON and Switch module from node-red for converting. there is possible a nicer way but that’s my lack of skill with node-red.

1 Like