Frequency Meter for displaying fuel totals

Hi All, i have a pulse/frequency meter running in node red.
I want to setup a page to

  1. display the flow rate per litre
  2. show how much fuel was used
  3. when no flow shows for 1 minute its stores the total.
  4. starts again when flow is detected.

I have the flow rate showing up, just need some advice on how to show accumulated litres .

cheers

Store for later historical viewing or just till the next one?

To provide suggestions for the other questions:

  1. What do you mean by flow rate per litre? Do you mean Litres per minute or something? If so then look at the Range node.
  2. For the running total you need to integrate the rate over time. I can't immediately see a node/flow that will help you with this so you might have to write a function node to do it. Basically each time a new frequency comes in you need to multiply it by the time interval since the last value and add it to the previous running total. So you will need to keep in the node context the time of the last value and the running total then. Have a look at the docs page on Writing Functions for some ideas on how to do that.
    3 and 4. This can also be addressed in the function node by keeping track of how long the flow has been at zero and when one minute of nothing has passed then clear the total and start again.

Possibly the easiest way to do that is with a JavaScript timeout function:

When your function receives a msg, you start a setTimeout function for 1 minute and assign that to a variable. When you receive another msg, you cancel the last one and recreate it. You also check a context variable flag to see whether to continue processing.

Inside the timeout function, the code is executed only if the timeout period elapses which it won't if you are getting messages <1min apart since you keep destroying it.

The timeout code will save the current total and set the context variable flag to pause the outer processing.

I assumed that even when there is no flow you will still get messages with a flow rate value of zero, in which case I don't think setTimeout does the job. If the messages stop completely when there is no flow then that is the way to go, or use a Trigger node to achieve a similar result.

Fair point.