Ok i finally got around to testing this again with node-red.
I have come up with the following flow to calculate a daily yield from a power to kwh feed.
[{"id":"6f9e1cc5.a48e04","type":"inject","z":"caf38013.feee8","name":"","topic":"","payload":"","payloadType":"date","repeat":"300","crontab":"","once":false,"x":280,"y":360,"wires":[["de5e8aa3.22d488","3940896c.8dbab6"]]},
{"id":"de5e8aa3.22d488","type":"emoncms in","z":"caf38013.feee8","name":"Emoncms","emonServer":"","feedid":"","x":430,"y":360,"wires":[["c9fa420a.e8c4"]]},
{"id":"3940896c.8dbab6","type":"function","z":"caf38013.feee8","name":"","func":"var d = new Date();\nd.setHours(0,0,0,0);\nvar midnight = Date.parse(d);\n\nvar feedid = XXXX;\nvar apikey = \"XXXXXXXXXX\"\nvar feedstart = midnight;\nvar feedstop = midnight + 1000;\nreturn {url: \"http://EMONCMSIP:PORT/feed/data.json?id=\" + feedid + \"&start=\" + feedstart + \"&end=\" + feedstop + \"&interval=1&apikey=\" + apikey};\n","outputs":1,"noerr":0,"x":420,"y":400,"wires":[["1f906d8e.e189e2"]]},
{"id":"1f906d8e.e189e2","type":"http request","z":"caf38013.feee8","name":"","method":"GET","ret":"txt","url":"","x":580,"y":400,"wires":[["8d2de327.ddb92"]]},
{"id":"8d2de327.ddb92","type":"function","z":"caf38013.feee8","name":"","func":"function getSecondPart(str) {\n return str.split(',')[2];\n}\n\nvar values = msg.payload.split(']')\nvar value = values[1];\n\n\nreturn {payload: getSecondPart(value), topic: \"midnight\"};","outputs":1,"noerr":0,"x":740,"y":400,"wires":[["52525a28.119474","ce1e1416.c581b8"]]},
{"id":"52525a28.119474","type":"function","z":"caf38013.feee8","name":"Wait for values","func":"context.data = context.data || new Object();\nswitch (msg.topic) {\n case \"now\":\n context.data.now = msg.payload;\n msg = null;\n break;\n case \"midnight\":\n context.data.midnight = msg.payload;\n msg = null;\n break;\n default:\n msg.data = context.data;\n}\n\nif(context.data.now != null && context.data.midnight != null) {\n\tmsg2 = new Object();\n msg2 = context.data;\n context.data=null;\n\treturn msg2;\n} else return msg;\n","outputs":1,"noerr":0,"x":910,"y":380,"wires":[["70b6f1fe.a98d9"]]},
{"id":"c9fa420a.e8c4","type":"change","z":"caf38013.feee8","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"now","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":360,"wires":[["52525a28.119474","35c44f0c.bce65"]]},
{"id":"70b6f1fe.a98d9","type":"function","z":"caf38013.feee8","name":"Calculate yield + Build emonCMS string","func":"msg1 = {}\nmsg1.yieldtoday = msg.now - msg.midnight;\n\nmsg2 = {}\nmsg2.payload = \"YieldToday:\" + msg1.yieldtoday;\nreturn [msg1,msg2];","outputs":"2","noerr":0,"x":1170,"y":380,"wires":[["afb9680a.c863b8"],["73b29c82.7ed064","1d9549d1.931336"]]},
{"id":"afb9680a.c863b8","type":"debug","z":"caf38013.feee8","name":"","active":false,"console":"false","complete":"true","x":1450,"y":320,"wires":[]},
{"id":"73b29c82.7ed064","type":"debug","z":"caf38013.feee8","name":"","active":true,"console":"false","complete":"true","x":1450,"y":420,"wires":[]},
{"id":"35c44f0c.bce65","type":"debug","z":"caf38013.feee8","name":"","active":false,"console":"false","complete":"false","x":790,"y":320,"wires":[]},
{"id":"ce1e1416.c581b8","type":"debug","z":"caf38013.feee8","name":"","active":false,"console":"false","complete":"false","x":930,"y":460,"wires":[]},
{"id":"c6281a5d.2d38f8","type":"comment","z":"caf38013.feee8","name":"Insert feed id ,API key and emoncms url","info":"","x":430,"y":440,"wires":[]},
{"id":"1d9549d1.931336","type":"emoncms","z":"caf38013.feee8","name":"Emoncms","emonServer":"","nodegroup":"","x":1460,"y":380,"wires":[]}]
I’m always getting 2 results from the http request, so i added a function to only use the second one. I’m not sure actually why i’m always getting 2. When i shorten the time between start and end it gives the same result.
I’m not big in coding, but this seems to work.
Suggestions are highly appreciated!