Node-RED function counter reset and function 4 outputs

Here's a link to something similar I knocked-up for someone just before Christmas.
It uses a number of the ideas suggested by @hotNipi.
You will need to modify the flow to suit your particular need.