Help getting tasmota to nodeRED to emoncms

I’ve done some searching, and can’t find what I’m looking for. Can anyone share their NodeRED setup with me?

I’ve got emoncms working nicely. I’ve got NodeRED up and running and talking to the Mosquitto server. I’ve got two Tasmota smart plugs, which monitor energy use and can talk to an MQTT broker. I just can’t crack getting that data across into an input to Emoncms.

I’m not the sharpest spoon in the drawer, and I could probably bumble my way to something over time, but if someone already has something that works, I’d love to just take it and run with it.

Welcome Tom.

You need to process the Tasmota data in NodeRed and split out the energy reading and send that to a MQTT Topic e.g. emon/TasPower1. Emoncms will pick up anything published to the base topic emon/ and it will just appear as an Input. I note you say an MQTT Broker - Emoncms and Node-Red need to be pointing to the same broker or you need to bridge the 2 brokers together.

You can send a JSON string with a timestamp and multiple measurements e.g.

{"temperature": 21.400000000000002, "external temperature": 0, "humidity": 45.2, "battery": 2.8000000000000003, "time": 1652943122, "rssi": -70}

Personally I set my Tasmota devices to send UNIX time with readings. By default, the ‘time’ is local time.

HTH

1 Like

Thanks @borpin. I’ve used one of the code blocks from your old posts to get the data translated to something digestible by Emoncms. I’ll do a write up for the sake of future googlers once it’s all settled.

Can I ask a follow-on question: whats the best way to take and process the power measurements into a useful feed?

There’s two “power” feeds: “Power”, which is an instantaneous reading, and “Period”, which is Whr since the last report. Using power-kWh for “Power” works ok, but I can see that it’s not high enough resolution to be accurate. Using an accumulator on “Period” should be better, but doesn’t seem to work as well as expected either.

About what you are doing.

These plugs will never be accurate. What resolution are you looking for?

You can change the reporting period from the plug, in Tasmota and you can also often calibrate the plugs.

You might find the returned accumulated value is more accurate.

Thanks for responding.

My current goal is to try and stamp down my energy consumption a bit, by monitoring the major draws on power, sieving them out and then attacking the smaller items.

It’s not about resolution as such, just about making sure I’m taking the best reading I can with the tools that I have. Ideally I’d like to overlay the readings from each plug on my overall consumption, and be able to say “that was the washer/dryer coming on” etc, and for the trace to be the right sort of size, rather than 20% low or something.

The “instantaneous power” reading is clearly not the right one to use, because it has a lag on it, even at 10s or 20s intervals.

The “period power” reading looked promising, and I’ve turned the resolution on that reading up, but it’s still not quite right.

I’ve tried using kWh to Power on the “Period” power, but it’s not right either.

Any ideas?

Well of course there is a lag. However, most items draw a reasonably constant power over 10s period, but yes it is still approximate.

Have you calibrated the plugs?

How do you know it isn’t accurate?

To be honest you do not need high accuracy for that.

Does your plug provide Energy (Wh) readings as well as Power (W)?

I think you mean power to kWh - why isn’t it right?

For future reference, here is the Node Red flow that I used:

[
    {
        "id": "b520d17bc62281f4",
        "type": "mqtt in",
        "z": "2984cc27db306d58",
        "name": "emonpi_MQTT",
        "topic": "Smartplug/Smartplug2/SENSOR/#",
        "qos": "2",
        "datatype": "auto",
        "broker": "cc4085cc0f2a8b60",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 140,
        "y": 320,
        "wires": [
            [
                "9cef9887c14df4b4",
                "610c90dfed258921"
            ]
        ]
    },
    {
        "id": "9cef9887c14df4b4",
        "type": "json",
        "z": "2984cc27db306d58",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 330,
        "y": 380,
        "wires": [
            [
                "ed94099e23c03861",
                "043037b642a8f5cf"
            ]
        ]
    },
    {
        "id": "ed94099e23c03861",
        "type": "debug",
        "z": "2984cc27db306d58",
        "name": "json payload",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 610,
        "y": 240,
        "wires": []
    },
    {
        "id": "043037b642a8f5cf",
        "type": "function",
        "z": "2984cc27db306d58",
        "name": "Parse for Emoncms input",
        "func": "var newmsg ={};\n\n//Remember to add timezone to date-time string\nvar newDateObj = new Date(msg.payload.Time);\n\ntimeObject = new Date(newDateObj.getTime());\n\ntimeObject = timeObject.getTime()/1000;\n\nnewmsg.time = timeObject;\n\nnewmsg.payload = msg.payload.ENERGY;\n//newmsg.payload.time = msg.payload.Time; // as string\n\nreturn newmsg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 570,
        "y": 380,
        "wires": [
            [
                "70ffe13f42e4ccd5",
                "771ec034df8b4112"
            ]
        ]
    },
    {
        "id": "70ffe13f42e4ccd5",
        "type": "debug",
        "z": "2984cc27db306d58",
        "name": "parsed output",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 860,
        "y": 240,
        "wires": []
    },
    {
        "id": "610c90dfed258921",
        "type": "debug",
        "z": "2984cc27db306d58",
        "name": "MQTT in",
        "active": false,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 370,
        "y": 240,
        "wires": []
    },
    {
        "id": "771ec034df8b4112",
        "type": "mqtt out",
        "z": "2984cc27db306d58",
        "name": "emonpi_MQTT_push",
        "topic": "emon/test/Smartplug2",
        "qos": "0",
        "retain": "false",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "cc4085cc0f2a8b60",
        "x": 860,
        "y": 380,
        "wires": []
    },
    {
        "id": "cc4085cc0f2a8b60",
        "type": "mqtt-broker",
        "name": "",
        "broker": "127.0.0.1",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    }
]

I’ve copied shamelessly from @borpin here:

I’ll keep working on the accuracy of the plugs and report that back separately…

8 posts were split to a new topic: Using MQTT to get data