Creating array and then average

Hi everyone,
I am getting msg payload 4 times per day. So i want to store msg value in array of 4 elements.
Then, I want to calculate average of these 4 Elementes. But I am stuck in between counter(to count which number of payload) and msg payload value.
How to do better way?

Thank you
kind regards,
Gautam

Hi and welcome.
Not sure of better way, but you could hold the last 4 values in context and at certain time of day read context and average.
e.g.

[{"id":"262a06c7.d1a87a","type":"inject","z":"c74669a0.6a34f8","name":"at set time","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":880,"wires":[["65f10022.76a3c8"]]},{"id":"65f10022.76a3c8","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$average($flowContext(\"hold\"))","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":880,"wires":[["7e06057b.d1b80c"]]},{"id":"7e06057b.d1b80c","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":570,"y":840,"wires":[]},{"id":"7f3522a3.fa06ac","type":"inject","z":"c74669a0.6a34f8","name":"incoming readins","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$ceil($random()*5)","payloadType":"jsonata","x":180,"y":800,"wires":[["c99a39e2.503808"]]},{"id":"c99a39e2.503808","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"hold","pt":"flow","to":"$append([payload],$flowContext(\"hold\"))[[0..3]]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":800,"wires":[[]]}]

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.