Counting the frequency of sensor changes and setting the appropriate mode

I have a gas meter that tracks gas usage. I want to distinguish the gas heater modes based on how rapidly it consumes gas. There are three modes:

  • Water Heating: the gas meter uses 1 unit (0.01) every 10-30 seconds.
  • Heating: the gas meter uses 1 unit (0.01) every 60-90 seconds.
  • Off: no usage at all.

How can I accurately measure and set the appropriate value in the input_select?

Here is example of gas usage when heating water: