Come up with a prototype flow that just passes msgs if rate is less than 5 messages over a 4 second period
If number of msgs increases (simulated by just pressing inject button to add extra msgs) then the output ceases
As @dceejay says, not prob practible to hold 40 msgs so need a better approach (got an idea for that already as I'm typing this)
[{"id":"24d330a9.4419d","type":"inject","z":"b8cb348c.6744d8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":130,"y":740,"wires":[["9193fe7a.a32b"]]},{"id":"9193fe7a.a32b","type":"change","z":"b8cb348c.6744d8","name":"","rules":[{"t":"set","p":"pastMsgs","pt":"flow","to":"[\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis(),\t $millis()\t]","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"pastMsgs","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":740,"wires":[["3af660a6.c9012"]]},{"id":"3af660a6.c9012","type":"debug","z":"b8cb348c.6744d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":630,"y":740,"wires":[]},{"id":"55f55057.fd8a2","type":"inject","z":"b8cb348c.6744d8","name":"","topic":"repeat 1/sec","payload":"","payloadType":"date","repeat":"1","crontab":"","once":true,"onceDelay":"1","x":150,"y":880,"wires":[["7534777.24a2688"]]},{"id":"6ff51717.c9e9d8","type":"debug","z":"b8cb348c.6744d8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":930,"y":940,"wires":[]},{"id":"84b3b1f3.ce318","type":"change","z":"b8cb348c.6744d8","name":"","rules":[{"t":"set","p":"pastMsgs","pt":"flow","to":"$append([$millis()],$flowContext(\"pastMsgs\"))","tot":"jsonata"},{"t":"set","p":"pastMsgs","pt":"flow","to":"$flowContext(\"pastMsgs\")[[0..4]]","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"pastMsgs","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":940,"wires":[["6ff51717.c9e9d8","dd144bb9.1ec8c8"]]},{"id":"dd144bb9.1ec8c8","type":"change","z":"b8cb348c.6744d8","name":"","rules":[{"t":"set","p":"timeDiff","pt":"flow","to":"$number($flowContext(\"pastMsgs\")[0] - $flowContext(\"pastMsgs\")[4])","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"timeDiff","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":1040,"wires":[["c9f22113.41627"]]},{"id":"86441db6.47522","type":"switch","z":"b8cb348c.6744d8","name":"","property":"timeDiff","propertyType":"flow","rules":[{"t":"gte","v":"4000","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":610,"y":860,"wires":[["9aac6e39.e466c"]]},{"id":"9aac6e39.e466c","type":"debug","z":"b8cb348c.6744d8","name":"OUTPUT msgs","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":940,"y":860,"wires":[]},{"id":"c9f22113.41627","type":"debug","z":"b8cb348c.6744d8","name":"Time over 5 msgs (ms)","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","x":960,"y":1040,"wires":[]},{"id":"7534777.24a2688","type":"counter","z":"b8cb348c.6744d8","name":"","init":"0","step":"1","lower":null,"upper":null,"mode":"increment","outputs":2,"x":340,"y":880,"wires":[["86441db6.47522","84b3b1f3.ce318"],[]]},{"id":"2148402c.a3de2","type":"inject","z":"b8cb348c.6744d8","name":"","topic":"","payload":"Extra Message","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":940,"wires":[["7534777.24a2688"]]}]