Calculating Daily Totals

Continuing the discussion from Node-red ui for emoncms dashboards posted by @bart.ellast :

The source input is from a emonTX, which is processed as follows -
Log to Feed
Power to kWh
Power to kWh/d

Further information about daily logging can be found here.

Paul

1 Like

Thank you Paul.

As i suspected you are pulling the daily data from a kwh/d feed.
Currently i use only kwh accumulating feeds. Pulling data from these feeds only gives the latest value and should be substracted with the data at the start of the day.

I had already been testing to do that with node-red and kwh accumulating feeds, but it’s not so easy for me.
I would need to request data at a certain time (epoch). But if i remember correctly the FEED API only lets me specify start and end times. Which makes things more difficult.

/feed/data.json?id=0&start=UNIXTIME&end=UNIXTIME&interval=5

Using a power to kwh/d should be more easy but can maybe show small deviations to my existing power to kwh feeds?

Hello Bart. If you make two requests one at the present time and the other at the start of the day that can work and is how the myelectric dashboard calculates its weekly, monthly totals.

To request the value at a given timestamp set the end timestamp to be 1 second after the start timestamp and set the interval to be one:

/feed/data.json?id=0&start=1467986007000&end=1467986008000&interval=1

1 Like

@TrystanLea I believe that Bart is wanting the equivalent of a power to kWh/d process for his kWh accumulating feeds, which resets the feed data at midnight and accumulates throughout the following day.
This would allow him to be able to make an api call to capture the current value without having to specify start & end times.

I don’t have any kWh accumulating feeds, but I assumed that ‘power to kWh/d’ process would have worked?
Have you tried this @bart.ellast ?

Paul

@Paul , I have switched over from using power to kwh/d a while ago because they gave me a couple of annoyances. kwh accumulating feeds seemed to be the new “way to go”.
I’m totally fine with the accumulating kwh feeds though.
It’s just not as easy to extract daily usage data with node-red as you are doing with kwh/d feeds.

@TrystanLea , i’ll try your example! Thanks.

I actually want to calculate the daily yield from a solar pv installation. Because the bar graphs, using kwh accumulators, don’t show the data from today (up until time of viewing).

Sorry to piggyback of an existing thread but I have a need to display daily, weekly and monthly kWh figures outside of emoncms, drawing data directly from the relevant feeds tables that I have stored in mySQL. Problem is that I can’t get my head around how to calculate the numbers. Can anyone help? I can’t make the assumption that any given feed has been recorded at 10 second intervals as this data is coming from a number of installations and we set the interval differently, with longer intervals at more recent installations.

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!