Get Statistics: Max, Min, Sum and so on

Hello,

As i understood History nod can not give this infos, but only array of value, that you have to handle by yourself.
Is there something like Statistic node to get sum, min, max, avg and so on in period of time?

Thanks a lot!

I have never seen that node before.
But I did a quick test and I assume you need to use the function node. The array is multi leveled and if you need to set time parameters then you need to loop the array (I think).

I tried it out and this seems to meet your requests.

Just make sure you set the min and max to values that is above and below what you expect.

[{"id":"c9a655.5d06f9a8","type":"api-get-history","z":"2227cef1.c55b22","name":"","server":"4bbca37b.1700ec","startdate":"2020-08-30T00:00:00+00:00","enddate":"2020-08-30T24:00:00+00:00","entityid":"sensor.andreas_light_sensor","entityidtype":"is","useRelativeTime":false,"relativeTime":"","flatten":true,"output_type":"array","output_location_type":"msg","output_location":"payload","x":430,"y":540,"wires":[["bc2130a4.73ef9"]]},{"id":"5d1ec5bc.5906fc","type":"debug","z":"2227cef1.c55b22","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":660,"y":420,"wires":[]},{"id":"760d0ad1.6a6ca4","type":"inject","z":"2227cef1.c55b22","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":540,"wires":[["c9a655.5d06f9a8"]]},{"id":"bc2130a4.73ef9","type":"function","z":"2227cef1.c55b22","name":"","func":"var sum = 0;\nvar min = 2500;\nvar max = -50;\nvar state = 0;\n\nmsg.payload.forEach(function(entry) {\n    state = parseInt(entry[\"state\"]);\n    sum = sum + state;\n    if(state > max) max = state;\n    if(state < min) min = state;\n});\nmsg.sum = sum;\nmsg.max = max;\nmsg.min = min;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":680,"y":540,"wires":[["5d1ec5bc.5906fc"]]},{"id":"4bbca37b.1700ec","type":"server","z":"","name":"Home Assistant","addon":true}]

And it gave me:
image

Ha, its right the same that i have made before :wink: Look:


I have just added prorection of “unknown” states