Efergy with multiple sensors (via energyhive API)

hey all,

something's over my head here..

i found this flow - which seems to work fine when having only one sensor/meter in one's account at engage.efergy.com - and i do understand it's functionality:

https://flows.nodered.org/flow/5e1d72d1f490ab98dfc447b06145ad80

but when having multiple sensors in the account the returned json seems to look quite different, and i just can't get it split up to make the three sensors work like the single one in the flow above..

this is the json with 3 sensors:

[
{"cid":"PWER","data":[{"1663623662000":137}],"sid":"xxx489","units":"W","age":1},
{"cid":"PWER","data":[{"1663623657000":55}],"sid":"xxx002","units":"W","age":6},
{"cid":"PWER","data":[{"1663623660000":533}],"sid":"xxx776","units":"W","age":3}
]

the actual sensor value is in the object with the timestamp which is in an array which is in an object which is in an array.. :face_with_spiral_eyes:

my main goal obviously would be to get the timestamp and its measurement extracted, guess i should get everything else sorted out if someone could hint me on how to do this..

tia.

The http request node can output a parsed object, check the settings.
The difficulty with your object is the measurement key is a timestamp, which i presume changes on each request,
To get the measurement and time stamp I had to use JSONata expressions or Javascript.
Here is an example with a test data generator too, for testing.
Hope it helps.

[{"id":"60008a4a.86788c","type":"inject","z":"9790f611.6dd06","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"30","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":740,"wires":[["ceaa9cf4.0ab4e8"]]},{"id":"ceaa9cf4.0ab4e8","type":"http request","z":"9790f611.6dd06","name":"Efergy Data","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://engage.efergy.com/mobile_proxy/getInstant?token=insert_your_token_here","tls":"","persist":false,"proxy":"","authType":"","x":340,"y":740,"wires":[["5a459efe.f8156"]]},{"id":"5a459efe.f8156","type":"split","z":"9790f611.6dd06","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":490,"y":800,"wires":[["8487957d.0abcb"]]},{"id":"50faf614.ea91d8","type":"inject","z":"9790f611.6dd06","name":"test input","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"\t\t[{\"cid\":\"PWER\",\"data\":[{$string($millis()+1000):$round(($random()*100)+50)}],\"sid\":\"xxx489\",\"units\":\"W\",\"age\":1},\t{\"cid\":\"PWER\",\"data\":[{$string($millis()+2000):$round(($random()*100)+100)}],\"sid\":\"xxx002\",\"units\":\"W\",\"age\":6},\t{\"cid\":\"PWER\",\"data\":[{$string($millis()-1000):$round(($random()*100)+300)}],\"sid\":\"xxx776\",\"units\":\"W\",\"age\":3}]","payloadType":"jsonata","x":170,"y":820,"wires":[["5a459efe.f8156"]]},{"id":"8487957d.0abcb","type":"change","z":"9790f611.6dd06","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload.sid","tot":"msg"},{"t":"set","p":"timestamp","pt":"msg","to":"$number($keys(payload.data[0]))","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$$.payload.data[0].* / 1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":800,"wires":[["c83d5bf9.3f7bf","88850c61.bea7b8","87f50bc3.df8728"]]},{"id":"c83d5bf9.3f7bf","type":"ui_chart","z":"9790f611.6dd06","name":"Efergy - Chart","group":"4b60f798.d4fa","order":1,"width":0,"height":0,"label":"Efergy - Chart","chartType":"line","legend":"false","xformat":"h:mma","interpolate":"linear","nodata":"waiting for inject...","dot":false,"ymin":"","ymax":"","removeOlder":"1","removeOlderPoints":"500","removeOlderUnit":"86400","cutout":"","useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":910,"y":820,"wires":[[]]},{"id":"88850c61.bea7b8","type":"debug","z":"9790f611.6dd06","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":810,"y":880,"wires":[]},{"id":"87f50bc3.df8728","type":"switch","z":"9790f611.6dd06","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"xxx489","vt":"str"},{"t":"eq","v":"xxx002","vt":"str"},{"t":"eq","v":"xxx776","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":640,"y":700,"wires":[["f642038f.0a545","5cab735b.abddf4"],["508a3c8a.c06b54","a41607e.7a17a78"],["3420fa54.d581a6","56465581.c96244"]]},{"id":"20e31a81.12889e","type":"inject","z":"9790f611.6dd06","name":"reset chart","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[]","payloadType":"json","x":380,"y":900,"wires":[["c83d5bf9.3f7bf"]]},{"id":"f642038f.0a545","type":"ui_text","z":"9790f611.6dd06","group":"4b60f798.d4fa","order":3,"width":0,"height":0,"name":"Efergy - Time Stamp","label":"Efergy - {{msg.topic}}","format":"{{msg.timestamp| date : \"h:mma\"}}","layout":"col-center","className":"","x":930,"y":580,"wires":[]},{"id":"508a3c8a.c06b54","type":"ui_text","z":"9790f611.6dd06","group":"4b60f798.d4fa","order":5,"width":0,"height":0,"name":"Efergy - Time Stamp","label":"Efergy - {{msg.topic}}","format":"{{msg.timestamp| date : \"h:mma\"}}","layout":"col-center","className":"","x":930,"y":660,"wires":[]},{"id":"3420fa54.d581a6","type":"ui_text","z":"9790f611.6dd06","group":"4b60f798.d4fa","order":7,"width":0,"height":0,"name":"Efergy - Time Stamp","label":"Efergy - {{msg.topic}}","format":"{{msg.timestamp| date : \"h:mma\"}}","layout":"col-center","className":"","x":930,"y":740,"wires":[]},{"id":"5cab735b.abddf4","type":"ui_gauge","z":"9790f611.6dd06","name":"Efergy - Reading","group":"4b60f798.d4fa","order":2,"width":0,"height":0,"gtype":"gage","title":"Efergy - {{msg.topic}}","label":"","format":"{{value}} KW","min":"0","max":"3.2","colors":["#00ff00","#ffff80","#ca3838"],"seg1":"","seg2":"","className":"","x":920,"y":620,"wires":[]},{"id":"a41607e.7a17a78","type":"ui_gauge","z":"9790f611.6dd06","name":"Efergy - Reading","group":"4b60f798.d4fa","order":4,"width":0,"height":0,"gtype":"gage","title":"Efergy - {{msg.topic}}","label":"","format":"{{value}} KW","min":"0","max":"3.2","colors":["#00ff00","#ffff80","#ca3838"],"seg1":"","seg2":"","className":"","x":920,"y":700,"wires":[]},{"id":"56465581.c96244","type":"ui_gauge","z":"9790f611.6dd06","name":"Efergy - Reading","group":"4b60f798.d4fa","order":6,"width":0,"height":0,"gtype":"gage","title":"Efergy - {{msg.topic}}","label":"","format":"{{value}} KW","min":"0","max":"3.2","colors":["#00ff00","#ffff80","#ca3838"],"seg1":"","seg2":"","className":"","x":920,"y":780,"wires":[]},{"id":"4b60f798.d4fa","type":"ui_group","name":"Energy","tab":"15ebcf5.c678631","order":null,"disp":true,"width":"6"},{"id":"15ebcf5.c678631","type":"ui_tab","name":"Home","icon":"dashboard","order":"1"}]
1 Like

oh my gosh. :hushed:
i explicitly not asked for a complete solution! thanks a bucket, there's a lot to learn for me in there.. :pray:

i already had figured i'd need jsonata, but just couldn't wrap my head around it that far yet..

for anyone finding oneself in the same boat i need to add that this multi-sensor-object isn't coming from the efergy-api (which is used in the original flow i linked) but via energyhive - no idea how these two are related, but one can input one's efergy api key there and it just works.

here's the working flow with the energyhive url (anonymised and slightly commented):

kudos again @E1cid

[
    {
        "id": "eed469f0.42ac78",
        "type": "tab",
        "label": "efergy",
        "disabled": false,
        "info": ""
    },
    {
        "id": "4fdaa584.be8fbc",
        "type": "inject",
        "z": "eed469f0.42ac78",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "10",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 150,
        "y": 140,
        "wires": [
            [
                "3120ec7f.05a454"
            ]
        ]
    },
    {
        "id": "3120ec7f.05a454",
        "type": "http request",
        "z": "eed469f0.42ac78",
        "name": "Energyhive Data",
        "method": "GET",
        "ret": "obj",
        "paytoqs": false,
        "url": "http://www.energyhive.com/mobile_proxy/getCurrentValuesSummary?token=API_KEY_HERE",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 150,
        "y": 320,
        "wires": [
            [
                "5dd89e46.e7f8f",
                "54e73801.e10948"
            ]
        ]
    },
    {
        "id": "5dd89e46.e7f8f",
        "type": "split",
        "z": "eed469f0.42ac78",
        "name": "",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 350,
        "y": 320,
        "wires": [
            [
                "a6929417.921908"
            ]
        ]
    },
    {
        "id": "f0d60938.6bc4c8",
        "type": "inject",
        "z": "eed469f0.42ac78",
        "name": "test input",
        "topic": "",
        "payload": "[{\"cid\":\"PWER\",\"data\":[{$string($millis()+1000):$round(($random()*100)+50)}],\"sid\":\"xxx489\",\"units\":\"W\",\"age\":1},\t{\"cid\":\"PWER\",\"data\":[{$string($millis()+2000):$round(($random()*100)+100)}],\"sid\":\"xxx002\",\"units\":\"W\",\"age\":6},\t{\"cid\":\"PWER\",\"data\":[{$string($millis()-1000):$round(($random()*100)+300)}],\"sid\":\"xxx776\",\"units\":\"W\",\"age\":3}]",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 140,
        "y": 440,
        "wires": [
            [
                "5dd89e46.e7f8f"
            ]
        ]
    },
    {
        "id": "a6929417.921908",
        "type": "change",
        "z": "eed469f0.42ac78",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "payload.sid",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "timestamp",
                "pt": "msg",
                "to": "$number($keys(payload.data[0]))",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$$.payload.data[0].* / 1000",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 500,
        "y": 320,
        "wires": [
            [
                "ca8db539.c77878",
                "9563c7fd.288608",
                "9ae410e2.ed5b2"
            ]
        ]
    },
    {
        "id": "ca8db539.c77878",
        "type": "ui_chart",
        "z": "eed469f0.42ac78",
        "name": "Efergy - Chart",
        "group": "cc3cfa1e.bf5538",
        "order": 1,
        "width": 0,
        "height": 0,
        "label": "Efergy - Chart",
        "chartType": "line",
        "legend": "false",
        "xformat": "h:mma",
        "interpolate": "linear",
        "nodata": "waiting for inject...",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": "1",
        "removeOlderPoints": "500",
        "removeOlderUnit": "86400",
        "cutout": "",
        "useOneColor": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "x": 960,
        "y": 440,
        "wires": [
            []
        ]
    },
    {
        "id": "9563c7fd.288608",
        "type": "switch",
        "z": "eed469f0.42ac78",
        "name": "",
        "property": "topic",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "xxxxxx",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "yyyyyy",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "zzzzzz",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 670,
        "y": 320,
        "wires": [
            [
                "d042ac94.a7119",
                "34510d6c.3f9972"
            ],
            [
                "efc70c61.4ebf2",
                "ca23b520.f01ff8"
            ],
            [
                "6e2fb4a3.e5e79c",
                "46223571.5bc22c"
            ]
        ]
    },
    {
        "id": "f1a8c78.84aa238",
        "type": "inject",
        "z": "eed469f0.42ac78",
        "name": "reset chart",
        "topic": "",
        "payload": "[]",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 500,
        "y": 440,
        "wires": [
            [
                "ca8db539.c77878"
            ]
        ]
    },
    {
        "id": "d042ac94.a7119",
        "type": "ui_text",
        "z": "eed469f0.42ac78",
        "group": "cc3cfa1e.bf5538",
        "order": 3,
        "width": 0,
        "height": 0,
        "name": "Efergy - Time Stamp",
        "label": "Efergy - {{msg.topic}}",
        "format": "{{msg.timestamp| date : \"h:mma\"}}",
        "layout": "col-center",
        "x": 980,
        "y": 200,
        "wires": []
    },
    {
        "id": "efc70c61.4ebf2",
        "type": "ui_text",
        "z": "eed469f0.42ac78",
        "group": "cc3cfa1e.bf5538",
        "order": 5,
        "width": 0,
        "height": 0,
        "name": "Efergy - Time Stamp",
        "label": "Efergy - {{msg.topic}}",
        "format": "{{msg.timestamp| date : \"h:mma\"}}",
        "layout": "col-center",
        "x": 980,
        "y": 280,
        "wires": []
    },
    {
        "id": "6e2fb4a3.e5e79c",
        "type": "ui_text",
        "z": "eed469f0.42ac78",
        "group": "cc3cfa1e.bf5538",
        "order": 7,
        "width": 0,
        "height": 0,
        "name": "Efergy - Time Stamp",
        "label": "Efergy - {{msg.topic}}",
        "format": "{{msg.timestamp| date : \"h:mma\"}}",
        "layout": "col-center",
        "x": 980,
        "y": 360,
        "wires": []
    },
    {
        "id": "34510d6c.3f9972",
        "type": "ui_gauge",
        "z": "eed469f0.42ac78",
        "name": "Efergy - Reading",
        "group": "cc3cfa1e.bf5538",
        "order": 2,
        "width": 0,
        "height": 0,
        "gtype": "gage",
        "title": "Efergy - {{msg.topic}}",
        "label": "",
        "format": "{{value}} KW",
        "min": "0",
        "max": "3.2",
        "colors": [
            "#00ff00",
            "#ffff80",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "x": 970,
        "y": 240,
        "wires": []
    },
    {
        "id": "ca23b520.f01ff8",
        "type": "ui_gauge",
        "z": "eed469f0.42ac78",
        "name": "Efergy - Reading",
        "group": "cc3cfa1e.bf5538",
        "order": 4,
        "width": 0,
        "height": 0,
        "gtype": "gage",
        "title": "Efergy - {{msg.topic}}",
        "label": "",
        "format": "{{value}} KW",
        "min": "0",
        "max": "3.2",
        "colors": [
            "#00ff00",
            "#ffff80",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "x": 970,
        "y": 320,
        "wires": []
    },
    {
        "id": "46223571.5bc22c",
        "type": "ui_gauge",
        "z": "eed469f0.42ac78",
        "name": "Efergy - Reading",
        "group": "cc3cfa1e.bf5538",
        "order": 6,
        "width": 0,
        "height": 0,
        "gtype": "gage",
        "title": "Efergy - {{msg.topic}}",
        "label": "",
        "format": "{{value}} KW",
        "min": "0",
        "max": "3.2",
        "colors": [
            "#00ff00",
            "#ffff80",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "x": 970,
        "y": 400,
        "wires": []
    },
    {
        "id": "9ae410e2.ed5b2",
        "type": "debug",
        "z": "eed469f0.42ac78",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 950,
        "y": 540,
        "wires": []
    },
    {
        "id": "54e73801.e10948",
        "type": "debug",
        "z": "eed469f0.42ac78",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 390,
        "y": 140,
        "wires": []
    },
    {
        "id": "6b7d215d.d3dab",
        "type": "comment",
        "z": "eed469f0.42ac78",
        "name": "set SIDs",
        "info": "set sensor's IDs here (sid)\n\nfor a different number of sensors add or remove outputs",
        "x": 680,
        "y": 280,
        "wires": []
    },
    {
        "id": "51b017de.788378",
        "type": "comment",
        "z": "eed469f0.42ac78",
        "name": "set API key",
        "info": "efergy API keys are working with energyhive\nhttp://www.energyhive.com/content/about/develop\n\nsee:\n\n_IMPORTANT: We continue to support existing energyhive customers but no longer sell this product.\n_\nsource: http://www.energyhive.com/content/products",
        "x": 120,
        "y": 280,
        "wires": []
    },
    {
        "id": "cc3cfa1e.bf5538",
        "type": "ui_group",
        "name": "Energy",
        "tab": "41e12c54.3109b4",
        "order": null,
        "disp": true,
        "width": "6"
    },
    {
        "id": "41e12c54.3109b4",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "order": "1"
    }
]