I want to convert a train of pulses from a water meter (1 pulse per litre) into a flow rate (litres per minute). The derivative helper is kind of OK, but it lacks the timeout option that the ESPhome pulse_meter integration has. I need this because otherwise the derivate shows the last-calculated flow rate indefinitely, waiting for the next pulse to recalculate it.
My meter won’t register less than 40 litres per hour. So… if no pulse arrives within 90 seconds of the previous one, the function should show the flow rate as zero litres per minute and sit like that until the next pulse arrives, when it can start calculating again.
I can’t find a way to achieve this, short of writing an automation which would be triggered either by a change in the water meter’s pulse counter or a 90 second timeout after the last pulse. If a pulse arrives and it’s less than 90 seconds since the last, we can calculate a flow rate in litres per minute. If the 90 second timeout has been reached, the flow rate is effectively zero. But… I need to store timestamps between triggers in the automation - not something I’ve done before. Any tips, please?