The quantity of payload in each 10 min

Hi guys. Can you please let me know how I can sum the number of payloads in each 10 min and send it to the debug node? Thank you so much

P.S: I already have the counter of payload from the beginning but I was asked to send the quantity of payload in each 10 min .

If you used an inject node set to 10mins, you could use the output to reset your total every 10 mins.

1 Like

you can use the aggregator node.

1 Like

Or store the total every ten mins with a inject and calculate the difference from last storing of total.

1 Like

Thank you so much, I also found the message counter node and it works too.

You can use

And set an inject node which sends msg.reset every 10 min

1 Like

Thank you so much. I used node-red-contrib-message-counter and it works too :slight_smile :slight_smile:

Hi, not 100% certain if it is the sum total of payload values or count of payloads but here is a demo that should cater for both...

chrome_u2IzTPcroS

[{"id":"226f9f18a6afc487","type":"function","z":"a0a5ddea2fa4216f","name":"Payload Total","func":"\nlet payload_history = context.get(\"payload_history\") || [];//get remembered count\nlet statusMessage;\nlet sum = 0, count = 0;\n\nif (msg.topic === \"release\") {\n    sum = payload_history.reduce((a, b) => a + b, 0) \n    count = payload_history.length;\n    payload_history = [];\n    node.status(\"Sum: 0\");\n} else if(typeof msg.payload === \"number\") {\n    payload_history.push(msg.payload);\n    sum = payload_history.reduce((a, b) => a + b, 0) \n    count = payload_history.length;\n    node.status(\"Sum: \" + sum);\n}\n\ncontext.set(\"payload_history\", payload_history); //remember count\n\nif(msg.topic == \"release\") {\n    msg.payload = {\n        count: count,\n        sum: sum\n    }\n    return [null, msg];\n} \n\nreturn [msg, null];\n\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":660,"wires":[["5999900b2df185a4"],["e6140c609f34d805"]]},{"id":"5999900b2df185a4","type":"debug","z":"a0a5ddea2fa4216f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":850,"y":620,"wires":[]},{"id":"0f206903f17e01f9","type":"inject","z":"a0a5ddea2fa4216f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":510,"y":580,"wires":[["226f9f18a6afc487"]]},{"id":"08c8d12fc86a3f32","type":"inject","z":"a0a5ddea2fa4216f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"5","payloadType":"num","x":510,"y":620,"wires":[["226f9f18a6afc487"]]},{"id":"e6140c609f34d805","type":"debug","z":"a0a5ddea2fa4216f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":850,"y":700,"wires":[]},{"id":"9a5781f4bb1f8711","type":"inject","z":"a0a5ddea2fa4216f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":510,"y":660,"wires":[["226f9f18a6afc487"]]},{"id":"339f7d87c33b9917","type":"inject","z":"a0a5ddea2fa4216f","name":"Release (every 10m)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"600","crontab":"","once":false,"onceDelay":0.1,"topic":"release","payload":"0","payloadType":"num","x":460,"y":720,"wires":[["226f9f18a6afc487"]]}]
2 Likes

Amazing , Thank you so much

Thank you :slight_smile:

Thank u so much

Thank you

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