Need help with setup Efergy Power Monitor to switch LinkNode R4

Hi,

I'm totally new to Node-RED so bear with me as I still have to learn it.

What I want to achieve:
A energy sensor is monitoring the household power consumption and when a certain threshold is reached let's say 2500w it have to trigger a relay, a second threshold 4500w to trigger a second relay.

I guess with Node-RED it's doable (if you now how).

Hardware I want to use:

  1. RPi2 for Node-RED
  2. Efergy Engage Energy Monitor Sensor
  3. LinkNode R4 (ESP8266 with 4 relays)

Someone already found a way to import the Energy Monitoring data to Node-RED described here:
https://flows.nodered.org/flow/5e1d72d1f490ab98dfc447b06145ad80

So are there any people who guide me to the right direction on how to accomplisch this?

Thanks in advance !

1 Like

Hi. There are plenty of people here willing to help so long as you try yourself first.

The worst kind of help requests are the ones that go something like "hi I have 2 sensors I want to put on dashboard and in my database. How do I do it?".

Most ignore these. Or at minimum reply with "what part are you stuck with, dashboard? Sensor values? What sensors? Database? What database? " Etc.

So, best thing you can do, is work in small parts.

Get your values coming in (use debug nodes - EVERYWHERE)

Play with triggers, change nodes, switch node. Learn how they work by themselves (use debug nodes everywhere)

Read the docs. Especially"working with messages" - the are a couple of golden Nuggets in there that will make you just "get it"

1 Like

Thanks, I will try my best.

Well I have reading a lot and come to the conclusion that this is where it ends for my logical skills.

I have figured out how to flash Tasmota FW to LinkNode-R4 and this works now via Node-RED, spend the whole evening on it to accomplish :smiley:

I just don't now how to go further from here.
Making a flow so that the Efergy Power Data will be used to trigger a relay when a certain threshold is reached and toggle the relay again when it becomes below this certain treshold.

If someone good at this stuff would be so nice to help me to setup this I would be so greatfull.

Otherwise I have to let it go as my skills don't reach such level of logic.

To help you out, we'll need a copy of your data and flow.

Put a debug node (set for show complete msg) on the end of the second node "efergy data" then in the debug window, press the copy data button that appears on the right when you hover over the msg.

This will permit us to replicate your data without having your sensors.

Paste that data in a reply

```
Like this
```

Next, select all your nodes and export (ctrl+e) them and paste them in the same reply...

```
Like this
```

Lastly, try (in a bullet list or logical text) describe what you want to happen and when.

We'll see if we can give you steer.


If you can, look into to modifying your devices to use MQTT. Sooooooo much simpler.
1 Like

I have managed to control the LinkNode-R4 relais via MQTT !

However putting the whole nodes here including my personal TOKEN everyone would be able to see my household power usage, I think thats no a good idea.

Is there a way I can PM you my Token (in trust) via this forum as I don't see any mailing options nor to moderators, mabe it's disabled for me !?

Please let me now.

I don't need your token. I don't need the http node.

Just your flow (minus the API key) and the data that comes out of the http node (you can sanitise the data if necessary).

What I intend to do (or if you can, even better) is replace you http node with the data (to fake the http request) while I try to help you figure this out.

Failing that, PM me and I'll sanitise it.

Ps, don't forget your logic.

I have found a workaround by activate a temporary API key, I can revoke it anytime.

What I want it to do:
When the power consumption is 2000 Watts or higher for more than 20 seconds it have to trigger the relay.
When the power consumption gets below 2000 Watts it turns the relay back off.

I send you a PM with the API Token, now you can see the data that is comming in.

[
    {
        "id": "1ebf393d.e7fa97",
        "type": "comment",
        "z": "f2b9628e.ad156",
        "name": "Efergy - Get Power Consumption",
        "info": "Get and Put Sensor data",
        "x": 150,
        "y": 140,
        "wires": []
    },
    {
        "id": "f5a50b16.0a7518",
        "type": "http request",
        "z": "f2b9628e.ad156",
        "name": "Efergy Data",
        "method": "GET",
        "ret": "txt",
        "paytoqs": false,
        "url": "https://engage.efergy.com/mobile_proxy/getInstant?token=PUT THE TOKEN HERE",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 300,
        "y": 200,
        "wires": [
            [
                "aa91d8.6101fe28",
                "bfa4484b.591988",
                "49ae325.016b8cc",
                "ca230ac4.1567f8"
            ]
        ]
    },
    {
        "id": "aa91d8.6101fe28",
        "type": "json",
        "z": "f2b9628e.ad156",
        "name": "",
        "x": 490,
        "y": 240,
        "wires": [
            [
                "414d2361.f9e26c"
            ]
        ]
    },
    {
        "id": "b315b88c.819bd8",
        "type": "debug",
        "z": "f2b9628e.ad156",
        "name": "Time",
        "active": true,
        "tosidebar": true,
        "console": false,
        "complete": "payload.last_reading_time",
        "x": 840,
        "y": 200,
        "wires": []
    },
    {
        "id": "293de335.dbe94c",
        "type": "debug",
        "z": "f2b9628e.ad156",
        "name": "Age [s]",
        "active": true,
        "console": "false",
        "complete": "payload.age",
        "x": 630,
        "y": 160,
        "wires": []
    },
    {
        "id": "bfa4484b.591988",
        "type": "json",
        "z": "f2b9628e.ad156",
        "name": "",
        "x": 490,
        "y": 200,
        "wires": [
            [
                "33078b11.3ff434"
            ]
        ]
    },
    {
        "id": "49ae325.016b8cc",
        "type": "json",
        "z": "f2b9628e.ad156",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 490,
        "y": 160,
        "wires": [
            [
                "293de335.dbe94c"
            ]
        ]
    },
    {
        "id": "33078b11.3ff434",
        "type": "function",
        "z": "f2b9628e.ad156",
        "name": "Time Compiler",
        "func": "var date = new Date(msg.payload.last_reading_time);\nmsg.payload.last_reading_time = date.toString();\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 650,
        "y": 200,
        "wires": [
            [
                "b371826e.b645d",
                "b315b88c.819bd8"
            ]
        ]
    },
    {
        "id": "d01901cf.38cb7",
        "type": "ui_chart",
        "z": "f2b9628e.ad156",
        "name": "Efergy - Chart",
        "group": "e02625b9.1e18d8",
        "order": 1,
        "width": 0,
        "height": 0,
        "label": "Efergy - Chart",
        "chartType": "line",
        "legend": "false",
        "xformat": "%a %H:%M",
        "interpolate": "linear",
        "nodata": "waiting for inject...",
        "ymin": "0",
        "ymax": "3.2",
        "removeOlder": "1",
        "removeOlderUnit": "86400",
        "outputs": 1,
        "x": 1020,
        "y": 240,
        "wires": [
            []
        ]
    },
    {
        "id": "21c9cd86.8ca3f2",
        "type": "ui_gauge",
        "z": "f2b9628e.ad156",
        "name": "Efergy - Reading",
        "group": "e02625b9.1e18d8",
        "order": 2,
        "width": 0,
        "height": 0,
        "gtype": "gage",
        "title": "Efergy - Reading",
        "label": "kW",
        "format": "{{value}} ",
        "min": "0",
        "max": "3.2",
        "colors": [
            "#00ff00",
            "#ffff80",
            "#ca3838"
        ],
        "x": 1030,
        "y": 280,
        "wires": []
    },
    {
        "id": "414d2361.f9e26c",
        "type": "function",
        "z": "f2b9628e.ad156",
        "name": "Extract \"reading\"",
        "func": "var power = { payload: msg.payload.reading };\nreturn power;",
        "outputs": 1,
        "noerr": 0,
        "x": 660,
        "y": 240,
        "wires": [
            [
                "c9a1ed8a.46dbf"
            ]
        ]
    },
    {
        "id": "4de4f65b.726cd8",
        "type": "debug",
        "z": "f2b9628e.ad156",
        "name": "Power [kW]",
        "active": true,
        "tosidebar": true,
        "console": false,
        "complete": "payload",
        "x": 1010,
        "y": 320,
        "wires": []
    },
    {
        "id": "c9a1ed8a.46dbf",
        "type": "range",
        "z": "f2b9628e.ad156",
        "minin": "0",
        "maxin": "1000",
        "minout": "0",
        "maxout": "1",
        "action": "scale",
        "round": false,
        "name": "Scaler",
        "x": 840,
        "y": 240,
        "wires": [
            [
                "21c9cd86.8ca3f2",
                "d01901cf.38cb7",
                "4de4f65b.726cd8"
            ]
        ]
    },
    {
        "id": "b371826e.b645d",
        "type": "ui_text",
        "z": "f2b9628e.ad156",
        "group": "e02625b9.1e18d8",
        "order": 3,
        "width": 0,
        "height": 0,
        "name": "Efergy - Time Stamp",
        "label": "Efergy - Timestamp:",
        "format": "{{msg.payload.last_reading_time}}",
        "layout": "col-center",
        "x": 890,
        "y": 160,
        "wires": []
    },
    {
        "id": "b1ecaf96.c80db",
        "type": "inject",
        "z": "f2b9628e.ad156",
        "name": "10s - Ping",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "10",
        "crontab": "",
        "once": true,
        "x": 130,
        "y": 200,
        "wires": [
            [
                "f5a50b16.0a7518"
            ]
        ]
    },
    {
        "id": "ca230ac4.1567f8",
        "type": "debug",
        "z": "f2b9628e.ad156",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 490,
        "y": 80,
        "wires": []
    },
    {
        "id": "653bb1d7.6a192",
        "type": "mqtt out",
        "z": "f2b9628e.ad156",
        "name": "",
        "topic": "cmnd/linknode-r4/power1",
        "qos": "0",
        "retain": "",
        "broker": "6737dff6.47f55",
        "x": 350,
        "y": 400,
        "wires": []
    },
    {
        "id": "57084f40.2ead4",
        "type": "inject",
        "z": "f2b9628e.ad156",
        "name": "",
        "topic": "",
        "payload": "off",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "x": 110,
        "y": 400,
        "wires": [
            [
                "653bb1d7.6a192"
            ]
        ]
    },
    {
        "id": "cd8e27ff.adf208",
        "type": "inject",
        "z": "f2b9628e.ad156",
        "name": "",
        "topic": "",
        "payload": "on",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "x": 110,
        "y": 440,
        "wires": [
            [
                "653bb1d7.6a192"
            ]
        ]
    },
    {
        "id": "47d6d7bb.5a0d38",
        "type": "inject",
        "z": "f2b9628e.ad156",
        "name": "",
        "topic": "",
        "payload": "toggle",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "x": 110,
        "y": 480,
        "wires": [
            [
                "653bb1d7.6a192"
            ]
        ]
    },
    {
        "id": "4b728383.08fb6c",
        "type": "comment",
        "z": "f2b9628e.ad156",
        "name": "MQTT control",
        "info": "Controlling the relay via MQTT\n\nroot topic followed by relay/0/set\naccepted messages:\n0: off\n1: on\n2: toggle",
        "x": 90,
        "y": 340,
        "wires": []
    },
    {
        "id": "708458f8.cf90a8",
        "type": "inject",
        "z": "f2b9628e.ad156",
        "name": "",
        "topic": "",
        "payload": "blink",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "x": 110,
        "y": 520,
        "wires": [
            [
                "653bb1d7.6a192"
            ]
        ]
    },
    {
        "id": "e02625b9.1e18d8",
        "type": "ui_group",
        "z": "",
        "name": "Energy",
        "tab": "601a006d.4855f",
        "order": null,
        "disp": true,
        "width": "6"
    },
    {
        "id": "6737dff6.47f55",
        "type": "mqtt-broker",
        "z": "",
        "name": "",
        "broker": "192.168.1.5",
        "port": "1883",
        "clientid": "node-red",
        "usetls": false,
        "compatmode": true,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    },
    {
        "id": "601a006d.4855f",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "order": "1"
    }
]
```

^ this is what I meant...

This is a common technique on node-red forum. You provide actual sample data so someone can help you.


First, some care points...

  • You convert the same result 3 times (three JSON nodes do exactly the same thing).

    1. This is unnecessary - you only need to do it once
    2. It is completely unnecessary as http request node "Efergy Data" can return JSON
    3. You should always check the status code == 200 to ensure you have good data.

    That now looks like this...

  • In your "time compiler" function, you replace the original value of msg.payload.last_reading_time - my recommendation is to leave the original fields alone and simply add another propery to the msg. This helps you understand if it worked correctly when you see it in the debug window.

  • The "extract reading" function is overkill for simply setting msg.payload to the value of msg.payload.reading - use a change node to reduce the overhead. Also, it is often helpful to retain the original payload (for debugging or further downstream operations)...


OK, so this is where we are at now...

Now to help you achieve your goal...

There are quite a few ways to achieve this.

  • Simple comparisons in a function node or switch node
  • using a PID node e.g. node-red-contrib-pid to better control the switching and avoid overshoot or chatter

I will add the logic you asked for using switch node

Final code...

[{"id":"20ead1f2.8bdeae","type":"comment","z":"b1c27b9d.5a0ab8","name":"Efergy - Get Power Consumption","info":"Get and Put Sensor data","x":170,"y":180,"wires":[]},{"id":"44803c5c.3e1034","type":"http request","z":"b1c27b9d.5a0ab8","name":"Efergy Data","method":"GET","ret":"obj","paytoqs":false,"url":"https://engage.efergy.com/mobile_proxy/getInstant?token=xxxxxxxx","tls":"","persist":false,"proxy":"","authType":"","x":130,"y":280,"wires":[["234838b5.52b648"]]},{"id":"9559932.8e2047","type":"debug","z":"b1c27b9d.5a0ab8","name":"Time","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":830,"y":200,"wires":[]},{"id":"f17aa1c8.1220a","type":"function","z":"b1c27b9d.5a0ab8","name":"Time Compiler","func":"var date = new Date(msg.payload.last_reading_time);\nmsg.payload.date = date.toString();\nreturn msg;","outputs":1,"noerr":0,"x":580,"y":260,"wires":[["23969398.4eb0dc","9559932.8e2047","792f6968.819588","e2281fda.33ae8"]]},{"id":"b8c6584c.8763f8","type":"ui_chart","z":"b1c27b9d.5a0ab8","name":"Efergy - Chart","group":"47eadd44.cdde64","order":1,"width":0,"height":0,"label":"Efergy - Chart","chartType":"line","legend":"false","xformat":"%a %H:%M","interpolate":"linear","nodata":"waiting for inject...","ymin":"0","ymax":"3.2","removeOlder":"1","removeOlderUnit":"86400","outputs":1,"x":860,"y":360,"wires":[[]]},{"id":"b0bad3f2.5b623","type":"ui_gauge","z":"b1c27b9d.5a0ab8","name":"Efergy - Reading","group":"47eadd44.cdde64","order":2,"width":0,"height":0,"gtype":"gage","title":"Efergy - Reading","label":"kW","format":"{{value}} ","min":"0","max":"3.2","colors":["#00ff00","#ffff80","#ca3838"],"seg1":"","seg2":"","x":870,"y":400,"wires":[]},{"id":"530630a2.8b89c","type":"debug","z":"b1c27b9d.5a0ab8","name":"Power [kW]","active":false,"tosidebar":true,"console":false,"complete":"payload","x":850,"y":440,"wires":[]},{"id":"bb29f4b7.3cf8b8","type":"range","z":"b1c27b9d.5a0ab8","minin":"0","maxin":"1000","minout":"0","maxout":"1","action":"scale","round":false,"property":"payload","name":"Scaler","x":610,"y":380,"wires":[["b0bad3f2.5b623","b8c6584c.8763f8","530630a2.8b89c"]]},{"id":"23969398.4eb0dc","type":"ui_text","z":"b1c27b9d.5a0ab8","group":"47eadd44.cdde64","order":3,"width":0,"height":0,"name":"Efergy - Time Stamp","label":"Efergy - Timestamp:","format":"{{msg.payload.date}}","layout":"col-center","x":880,"y":240,"wires":[]},{"id":"b6fcd65c.d0fd78","type":"inject","z":"b1c27b9d.5a0ab8","name":"10s - Ping","topic":"efergy","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":"","x":130,"y":220,"wires":[["44803c5c.3e1034"]]},{"id":"976fdce3.f3cdc","type":"debug","z":"b1c27b9d.5a0ab8","name":"good data","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":360,"y":230,"wires":[]},{"id":"1b9f2057.78521","type":"mqtt out","z":"b1c27b9d.5a0ab8","name":"","topic":"cmnd/linknode-r4/power1","qos":"0","retain":"","broker":"91974801.1d5348","x":350,"y":680,"wires":[]},{"id":"bc494a61.b79808","type":"inject","z":"b1c27b9d.5a0ab8","name":"","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":110,"y":680,"wires":[["1b9f2057.78521"]]},{"id":"9d702475.aecad8","type":"inject","z":"b1c27b9d.5a0ab8","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"x":110,"y":720,"wires":[["1b9f2057.78521"]]},{"id":"5c2afcfa.cad9a4","type":"inject","z":"b1c27b9d.5a0ab8","name":"","topic":"","payload":"toggle","payloadType":"str","repeat":"","crontab":"","once":false,"x":110,"y":760,"wires":[["1b9f2057.78521"]]},{"id":"5a79f536.ec200c","type":"comment","z":"b1c27b9d.5a0ab8","name":"MQTT control","info":"Controlling the relay via MQTT\n\nroot topic followed by relay/0/set\naccepted messages:\n0: off\n1: on\n2: toggle","x":110,"y":600,"wires":[]},{"id":"e89907dd.ab8148","type":"inject","z":"b1c27b9d.5a0ab8","name":"","topic":"","payload":"blink","payloadType":"str","repeat":"","crontab":"","once":false,"x":110,"y":800,"wires":[["1b9f2057.78521"]]},{"id":"234838b5.52b648","type":"switch","z":"b1c27b9d.5a0ab8","name":"statusCode == 200?","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"200","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":320,"y":280,"wires":[["f17aa1c8.1220a","976fdce3.f3cdc"],["5a780ff5.68d92"]]},{"id":"5a780ff5.68d92","type":"debug","z":"b1c27b9d.5a0ab8","name":"bad data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":360,"y":329,"wires":[]},{"id":"792f6968.819588","type":"change","z":"b1c27b9d.5a0ab8","name":"payload.reading > payload","rules":[{"t":"set","p":"payloadOriginal","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload.reading","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":320,"wires":[["bb29f4b7.3cf8b8","c6026e79.8412f"]]},{"id":"c6026e79.8412f","type":"debug","z":"b1c27b9d.5a0ab8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":830,"y":320,"wires":[]},{"id":"42a82927.b1a9c8","type":"switch","z":"b1c27b9d.5a0ab8","name":"reading > 2000?","property":"payload.reading","propertyType":"msg","rules":[{"t":"gte","v":"2000","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":166,"y":520,"wires":[["6082c5bc.57fbac"],["6a5dad97.2b0ec4"]]},{"id":"e2281fda.33ae8","type":"link out","z":"b1c27b9d.5a0ab8","name":"to Control Logic -->","links":["58aefe72.db676"],"x":875,"y":280,"wires":[],"l":true},{"id":"58aefe72.db676","type":"link in","z":"b1c27b9d.5a0ab8","name":"","links":["e2281fda.33ae8"],"x":54,"y":520,"wires":[["42a82927.b1a9c8"]]},{"id":"1ca9d79e.7f5fb8","type":"trigger","z":"b1c27b9d.5a0ab8","op1":"","op2":"on","op1type":"nul","op2type":"str","duration":"20","extend":false,"units":"s","reset":"","bytopic":"all","name":"Wait 20s then send \"on\"","x":609,"y":500,"wires":[["ebe21e64.d76e4"]]},{"id":"6a5dad97.2b0ec4","type":"change","z":"b1c27b9d.5a0ab8","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":379,"y":560,"wires":[["1ca9d79e.7f5fb8","6082c5bc.57fbac","47480db4.3cc144"]]},{"id":"6082c5bc.57fbac","type":"trigger","z":"b1c27b9d.5a0ab8","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"0","extend":false,"units":"ms","reset":"","bytopic":"all","name":"","x":379,"y":500,"wires":[["1ca9d79e.7f5fb8"]]},{"id":"47480db4.3cc144","type":"change","z":"b1c27b9d.5a0ab8","name":"set payload off","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"},{"t":"delete","p":"reset","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":579,"y":560,"wires":[["ebe21e64.d76e4"]]},{"id":"e3ec95ba.ad8318","type":"link in","z":"b1c27b9d.5a0ab8","name":"-> on/off","links":["50ca6f68.a7384"],"x":100,"y":640,"wires":[["1b9f2057.78521","56b0234e.d4090c"]],"l":true},{"id":"50ca6f68.a7384","type":"link out","z":"b1c27b9d.5a0ab8","name":"send on/off -->","links":["e3ec95ba.ad8318"],"x":859,"y":560,"wires":[],"l":true},{"id":"56b0234e.d4090c","type":"debug","z":"b1c27b9d.5a0ab8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":310,"y":640,"wires":[]},{"id":"ebe21e64.d76e4","type":"rbe","z":"b1c27b9d.5a0ab8","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":829,"y":500,"wires":[["50ca6f68.a7384"]]},{"id":"50d0574e.b13c98","type":"comment","z":"b1c27b9d.5a0ab8","name":"Control logic","info":"Get and Put Sensor data","x":109,"y":480,"wires":[]},{"id":"7b89b9c3.c0aed8","type":"inject","z":"b1c27b9d.5a0ab8","name":"Fake data 633 W","topic":"efergy","payload":"{\"age\":2,\"last_reading_time\":1588673388000,\"reading\":633}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":365,"wires":[["cdbb6950.8b0a38"]]},{"id":"d9535be3.d32088","type":"inject","z":"b1c27b9d.5a0ab8","name":"Fake data 2011W","topic":"efergy","payload":"{\"age\":2,\"last_reading_time\":1588673388000,\"reading\":2011}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":405,"wires":[["cdbb6950.8b0a38"]]},{"id":"cdbb6950.8b0a38","type":"change","z":"b1c27b9d.5a0ab8","name":"","rules":[{"t":"set","p":"statusCode","pt":"msg","to":"200","tot":"num"},{"t":"set","p":"payload.last_reading_time","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":255,"y":385,"wires":[["234838b5.52b648"]],"l":false},{"id":"38c56e23.6e5a32","type":"comment","z":"b1c27b9d.5a0ab8","name":"Test by clicking...","info":"Get and Put Sensor data","x":120,"y":331,"wires":[]},{"id":"47eadd44.cdde64","type":"ui_group","z":"","name":"Energy","tab":"49ab9140.63333","order":null,"disp":true,"width":"6"},{"id":"91974801.1d5348","type":"mqtt-broker","z":"","name":"","broker":"192.168.1.5","port":"1883","clientid":"node-red","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"49ab9140.63333","type":"ui_tab","name":"Home","icon":"dashboard","order":"1"}]
1 Like

It is working PERFECTLY ! :star_struck:

THANK YOU SO MUCH !!!!

Well I discover an issue.

I have 3 Efergy sensors:
Sensor-1: Main Power Usage
Sensor-2: Solar Power
Sensor-3: (experimental)

Now and then one of the other sensors wattage data shows up and that causes the 20 seconds timer to reset back at the begining resulting in not trigger the relay.
That would be those zero's '0'

Is there anything in the payload that differentiates or identifies the values? If so, you can add a switch node & filter any readings that don't match?

Alternatively, is there something you can do with the URL to ONLY access the 1 reading you require?

As a hack, you could filter out any value less than say 50 (or ignore zero values)?
Its a hack and might not be suitable - last resort though - if the options in previous post are not possible.

I just have discovered that all Efergy data is also available at energyhive.com and if I use my token there I receive a whole other payload:

Here for example as "object 0" this is my main sensor I want to use.
Yep, drawing 3177 Watts at that moment.
afbeelding

This is the URL of energyhive that I have discovered:
http://www.energyhive.com/mobile_proxy/getCurrentValuesSummary?token= PUT TOKEN HERE

About that 20 seconds delay till it gets triggered.

This is to avoid the relay acting as crazy on and off all the time when power usage spikes !

So when power goes up at a certain threshold for more than 20 seconds long the output can be triggered.

In which case, after the http node, put a function node that searches the payload array for an object containing cid with value "PWER" then send the value in data[0] through the payload.

Thanks for the info but I just can't do it.
I have search many Java examples but non work for me :thinking:

Here you go.

Please take the time to look closely what i changed. I heavily commented the function node to assist your learning - please try to figure it out.

sanitised flow...

[{"id":"4a249378.25a16c","type":"comment","z":"b1c27b9d.5a0ab8","name":"Efergy - Get Power Consumption","info":"Get and Put Sensor data","x":210,"y":200,"wires":[]},{"id":"accaddc3.362e2","type":"http request","z":"b1c27b9d.5a0ab8","name":"V1 URL","method":"GET","ret":"obj","paytoqs":false,"url":"https://engage.efergy.com/mobile_proxy/getInstant?token=xxxxxxxxx","tls":"","persist":false,"proxy":"","authType":"","x":140,"y":320,"wires":[["d1777e14.ac83e"]]},{"id":"382683be.59561c","type":"debug","z":"b1c27b9d.5a0ab8","name":"Time","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":870,"y":240,"wires":[]},{"id":"2933877c.95f368","type":"function","z":"b1c27b9d.5a0ab8","name":"Process values","func":"//V1 = getInstant: If payload is NOT an array, we are using getInstant\n//V2 = getCurrentValuesSummary: If payload IS an array, we are using getCurrentValuesSummary\n\n//As it already works for V1, we will translate V2 data to V1 style.\n\n//the style of V1 data is ...\n//{\"age\":0,\"last_reading_time\":1588755045000,\"reading\":233}\n\n\nvar V = 0;//unknown\nif(typeof msg.payload == \"object\"){\n    V = 1;//payload is an object!  Set V to 1\n}\nif(Array.isArray(msg.payload)){\n    V = 2;//payload is an Array!  Set V to 2\n}\n\n\nif(V === 1){\n    //for V1 we add .date to the payload & return it\n    msg.orig_data_v1 = {...msg.payload};//copy the original data here for later debugging\n    msg.payload.date = new Date(msg.payload.last_reading_time);\n    return msg;\n} else if(V === 2) {\n    //make data compatible to V1\n    //The reading should be in payload.reading\n    //\n    //The date value we want is the 1st KEY of payload[0].data[0]\n    //because the time stamp is a key not a value\n    // {\n    //     \"cid\":\"PWER\",\n    //     \"data\":[{\"1588754281000\":718}],  << time stamp is a KEY! crazy!\n    //     \"sid\":\"778544\",\n    //     \"units\":\"W\",\n    //     \"age\":3\n    // }\n    var newPayload;\n    msg.orig_data_v2 = msg.payload;//copy the original data here for later debugging\n    var itemOfInterest = msg.payload[0];\n    \n    //inside the V2 data should be a data[] array.\n    //if its not an array or its empty, throw an error\n    if(Array.isArray(itemOfInterest.data) === false){\n        throw new error(\"data array not found - invalid data\")\n    }\n    \n    if(itemOfInterest.data.length <= 0){\n        throw new error(\"data array is empty - invalid data\")\n    }\n    \n    //now get the timestamp of 1st data element\n    var keys = Object.keys(itemOfInterest.data[0] || {}); //\n    if(keys.length <= 0){\n        throw new Error(\"no data found in msg.payload[0].data[0]\")\n    }\n    let key = keys[0];//get key name (this is also the time stamp - stupid design)\n    let last_reading_time = parseInt(key);\n    let keyVal = itemOfInterest.data[0][key];//get the value of the first key\n    //now build a new payload in format of V1\n    msg.payload = {\n        last_reading_time: last_reading_time, //get the timestamp from first key in keys\n        date : new Date(last_reading_time).toString(), \n        age : itemOfInterest.age,\n        cid : itemOfInterest.cid,\n        reading: keyVal,\n        units: itemOfInterest.units\n    }\n    return msg;\n} else {\n    throw new Error(\"Unable to determine data version\")\n}\n","outputs":1,"noerr":0,"x":620,"y":300,"wires":[["e9af5cc2.dcfcb","382683be.59561c","5f92417e.e2cb7","fd870e93.2aec3"]]},{"id":"d300039.3ce8f","type":"ui_chart","z":"b1c27b9d.5a0ab8","name":"Efergy - Chart","group":"f60c1c41.e1741","order":1,"width":0,"height":0,"label":"Efergy - Chart","chartType":"line","legend":"false","xformat":"%a %H:%M","interpolate":"linear","nodata":"waiting for inject...","ymin":"0","ymax":"3.2","removeOlder":"1","removeOlderUnit":"86400","outputs":1,"x":900,"y":400,"wires":[[]]},{"id":"287dda19.d420d6","type":"ui_gauge","z":"b1c27b9d.5a0ab8","name":"Efergy - Reading","group":"f60c1c41.e1741","order":2,"width":0,"height":0,"gtype":"gage","title":"Efergy - Reading","label":"kW","format":"{{value}} ","min":"0","max":"3.2","colors":["#00ff00","#ffff80","#ca3838"],"seg1":"","seg2":"","x":910,"y":440,"wires":[]},{"id":"d8c2d3fb.45741","type":"debug","z":"b1c27b9d.5a0ab8","name":"Power [kW]","active":false,"tosidebar":true,"console":false,"complete":"payload","x":890,"y":480,"wires":[]},{"id":"500e9d42.13caf4","type":"range","z":"b1c27b9d.5a0ab8","minin":"0","maxin":"1000","minout":"0","maxout":"1","action":"scale","round":false,"property":"payload","name":"Scaler","x":650,"y":420,"wires":[["287dda19.d420d6","d300039.3ce8f","d8c2d3fb.45741"]]},{"id":"e9af5cc2.dcfcb","type":"ui_text","z":"b1c27b9d.5a0ab8","group":"f60c1c41.e1741","order":3,"width":0,"height":0,"name":"Efergy - Time Stamp","label":"Efergy - Timestamp:","format":"{{msg.payload.date}}","layout":"col-center","x":920,"y":280,"wires":[]},{"id":"81d55671.67c0d8","type":"inject","z":"b1c27b9d.5a0ab8","name":"Poll trigger","topic":"efergy","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":140,"y":280,"wires":[["accaddc3.362e2"]]},{"id":"39db22a4.085cee","type":"debug","z":"b1c27b9d.5a0ab8","name":"good data","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":400,"y":270,"wires":[]},{"id":"2c88ad29.e08332","type":"mqtt out","z":"b1c27b9d.5a0ab8","name":"","topic":"cmnd/linknode-r4/power1","qos":"0","retain":"","broker":"91974801.1d5348","x":390,"y":720,"wires":[]},{"id":"b9848359.f4886","type":"inject","z":"b1c27b9d.5a0ab8","name":"","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":150,"y":720,"wires":[["2c88ad29.e08332"]]},{"id":"1385010d.ff469f","type":"inject","z":"b1c27b9d.5a0ab8","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"x":150,"y":760,"wires":[["2c88ad29.e08332"]]},{"id":"d63f80f8.a66fd","type":"inject","z":"b1c27b9d.5a0ab8","name":"","topic":"","payload":"toggle","payloadType":"str","repeat":"","crontab":"","once":false,"x":150,"y":800,"wires":[["2c88ad29.e08332"]]},{"id":"c860661b.eca998","type":"comment","z":"b1c27b9d.5a0ab8","name":"MQTT control","info":"Controlling the relay via MQTT\n\nroot topic followed by relay/0/set\naccepted messages:\n0: off\n1: on\n2: toggle","x":150,"y":640,"wires":[]},{"id":"1329881b.d99a38","type":"inject","z":"b1c27b9d.5a0ab8","name":"","topic":"","payload":"blink","payloadType":"str","repeat":"","crontab":"","once":false,"x":150,"y":840,"wires":[["2c88ad29.e08332"]]},{"id":"d1777e14.ac83e","type":"switch","z":"b1c27b9d.5a0ab8","name":"statusCode == 200?","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"200","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":360,"y":320,"wires":[["2933877c.95f368","39db22a4.085cee"],["31c461e8.04297e"]]},{"id":"31c461e8.04297e","type":"debug","z":"b1c27b9d.5a0ab8","name":"bad data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":400,"y":369,"wires":[]},{"id":"5f92417e.e2cb7","type":"change","z":"b1c27b9d.5a0ab8","name":"payload.reading > payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.reading","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":360,"wires":[["500e9d42.13caf4","d5f2ec7.051391"]]},{"id":"d5f2ec7.051391","type":"debug","z":"b1c27b9d.5a0ab8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":870,"y":360,"wires":[]},{"id":"b94c43d7.48bdd","type":"switch","z":"b1c27b9d.5a0ab8","name":"reading > 2000?","property":"payload.reading","propertyType":"msg","rules":[{"t":"gte","v":"2000","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":206,"y":560,"wires":[["ba9fee7a.83d08"],["3a66945b.1b711c"]]},{"id":"fd870e93.2aec3","type":"link out","z":"b1c27b9d.5a0ab8","name":"to Control Logic -->","links":["aaaa75dd.178b08"],"x":915,"y":320,"wires":[],"l":true},{"id":"aaaa75dd.178b08","type":"link in","z":"b1c27b9d.5a0ab8","name":"","links":["fd870e93.2aec3"],"x":94,"y":560,"wires":[["b94c43d7.48bdd"]]},{"id":"bde601d5.d8bc4","type":"trigger","z":"b1c27b9d.5a0ab8","op1":"","op2":"on","op1type":"nul","op2type":"str","duration":"20","extend":false,"units":"s","reset":"","bytopic":"all","name":"Wait 20s then send \"on\"","x":649,"y":540,"wires":[["3a9326c6.b364aa"]]},{"id":"3a66945b.1b711c","type":"change","z":"b1c27b9d.5a0ab8","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":419,"y":600,"wires":[["bde601d5.d8bc4","ba9fee7a.83d08","e4fa88c8.226ae8"]]},{"id":"ba9fee7a.83d08","type":"trigger","z":"b1c27b9d.5a0ab8","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"0","extend":false,"units":"ms","reset":"","bytopic":"all","name":"","x":419,"y":540,"wires":[["bde601d5.d8bc4"]]},{"id":"e4fa88c8.226ae8","type":"change","z":"b1c27b9d.5a0ab8","name":"set payload off","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"},{"t":"delete","p":"reset","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":619,"y":600,"wires":[["3a9326c6.b364aa"]]},{"id":"7af53c49.a5f6a4","type":"link in","z":"b1c27b9d.5a0ab8","name":"-> on/off","links":["3f253d43.166872"],"x":140,"y":680,"wires":[["2c88ad29.e08332","6740cc45.ba9e84"]],"l":true},{"id":"3f253d43.166872","type":"link out","z":"b1c27b9d.5a0ab8","name":"send on/off -->","links":["7af53c49.a5f6a4"],"x":899,"y":600,"wires":[],"l":true},{"id":"6740cc45.ba9e84","type":"debug","z":"b1c27b9d.5a0ab8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":350,"y":680,"wires":[]},{"id":"3a9326c6.b364aa","type":"rbe","z":"b1c27b9d.5a0ab8","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":869,"y":540,"wires":[["3f253d43.166872"]]},{"id":"d307ad1d.d5cb4","type":"comment","z":"b1c27b9d.5a0ab8","name":"Control logic","info":"Get and Put Sensor data","x":149,"y":520,"wires":[]},{"id":"6e2adb52.bd0a24","type":"http request","z":"b1c27b9d.5a0ab8","name":"V2 URL","method":"GET","ret":"obj","paytoqs":false,"url":"http://www.energyhive.com/mobile_proxy/getCurrentValuesSummary?token=xxxxxxxxxxxxx","tls":"","persist":false,"proxy":"","authType":"","x":140,"y":400,"wires":[["d1777e14.ac83e"]]},{"id":"3af814c8.75730c","type":"inject","z":"b1c27b9d.5a0ab8","name":"Poll trigger","topic":"efergy","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":140,"y":360,"wires":[["6e2adb52.bd0a24"]]},{"id":"1b0124c4.021c6b","type":"inject","z":"b1c27b9d.5a0ab8","name":"Fake V2 data 640 W","topic":"efergy","payload":"[{\"cid\":\"PWER\",\"data\":[{\"1588756181000\":640}],\"sid\":\"778544\",\"units\":\"W\",\"age\":10},{\"cid\":\"PWER\",\"data\":[{\"1588756185000\":318}],\"sid\":\"838150\",\"units\":\"W\",\"age\":6},{\"cid\":\"PWER_SUB\",\"data\":[{\"1588756187000\":169}],\"sid\":\"770194\",\"units\":\"W\",\"age\":4}]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":610,"y":80,"wires":[["66a00c4e.33bb54"]]},{"id":"5b6c2519.72464c","type":"inject","z":"b1c27b9d.5a0ab8","name":"Fake V2 data 2025W","topic":"efergy","payload":"[{\"cid\":\"PWER\",\"data\":[{\"1588756181000\":2025}],\"sid\":\"778544\",\"units\":\"W\",\"age\":10},{\"cid\":\"PWER\",\"data\":[{\"1588756185000\":318}],\"sid\":\"838150\",\"units\":\"W\",\"age\":6},{\"cid\":\"PWER_SUB\",\"data\":[{\"1588756187000\":169}],\"sid\":\"770194\",\"units\":\"W\",\"age\":4}]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":620,"y":120,"wires":[["66a00c4e.33bb54"]]},{"id":"66a00c4e.33bb54","type":"change","z":"b1c27b9d.5a0ab8","name":"","rules":[{"t":"set","p":"statusCode","pt":"msg","to":"200","tot":"num"},{"t":"set","p":"payload.last_reading_time","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":775,"y":80,"wires":[["5bb51509.f0121c"]],"l":false},{"id":"c7208d72.8c616","type":"link out","z":"b1c27b9d.5a0ab8","name":"","links":["79befa9e.011164"],"x":415,"y":80,"wires":[]},{"id":"41f5c25e.086ebc","type":"comment","z":"b1c27b9d.5a0ab8","name":"V1 Test data (uses getInstant API)","info":"Get and Put Sensor data","x":220,"y":40,"wires":[]},{"id":"68fc93dc.ea427c","type":"inject","z":"b1c27b9d.5a0ab8","name":"Fake V1 data 633 W","topic":"efergy","payload":"{\"age\":2,\"last_reading_time\":1588673388000,\"reading\":633}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":80,"wires":[["62a58709.c50fb8"]]},{"id":"8ecabd4f.f925e","type":"inject","z":"b1c27b9d.5a0ab8","name":"Fake V1 data 2011W","topic":"efergy","payload":"{\"age\":2,\"last_reading_time\":1588673388000,\"reading\":2011}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":120,"wires":[["62a58709.c50fb8"]]},{"id":"62a58709.c50fb8","type":"change","z":"b1c27b9d.5a0ab8","name":"","rules":[{"t":"set","p":"statusCode","pt":"msg","to":"200","tot":"num"},{"t":"set","p":"payload.last_reading_time","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":355,"y":80,"wires":[["c7208d72.8c616"]],"l":false},{"id":"79befa9e.011164","type":"link in","z":"b1c27b9d.5a0ab8","name":"--> test data","links":["5bb51509.f0121c","c7208d72.8c616"],"x":150,"y":240,"wires":[["d1777e14.ac83e"]],"l":true},{"id":"5bb51509.f0121c","type":"link out","z":"b1c27b9d.5a0ab8","name":"","links":["79befa9e.011164"],"x":835,"y":80,"wires":[]},{"id":"75f0c38.3e33f3c","type":"comment","z":"b1c27b9d.5a0ab8","name":"V2 Test data (uses getCurrentValuesSummary API)","info":"Get and Put Sensor data","x":690,"y":40,"wires":[]},{"id":"f60c1c41.e1741","type":"ui_group","z":"","name":"Energy","tab":"79f14fa.889beb","order":null,"disp":true,"width":"6"},{"id":"91974801.1d5348","type":"mqtt-broker","z":"","name":"","broker":"192.168.1.5","port":"1883","clientid":"node-red","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"79f14fa.889beb","type":"ui_tab","name":"Home","icon":"dashboard","order":"1"}]
1 Like

This function node code you programmed is total hardcore for me.
I never would accomplisched that, but I try to understand whats going on.

I use only data from URL v2 as this works as it suppose to why schould I alsy use the v1 data ?

I'm testing it right now and it seems to work altough that Node-RED always disconnect from MQTT and re-connects again, very anoying.

1 Like

Check you only have one mqtt config node. And if you deliberately have more than one, make sure they don't have same clientID