Cache and analyze past ESPHome data based on current sensor readings

I have ESPHome running on an ESP8266 and I’m using it to monitor my whole house water filtration system with pressure sensors on both sides of the filter system. As soon as I built it and started monitoring the sensors I realized that in order to really measure the “filter health”, I need water demand. If no water is flowing through the “plugged” filters then there will be no pressure drop across the filters (which is what I’m looking for).

Because of that, I ended up looking at both sensors ever 1-2 seconds and calculating the delta. This is very wasteful since most of the day there is no flow through the filters. I thought about this for a while and what I really want is a real-time flow value that I can use to trigger a higher-resolution view of the drop across the filters. So, I bought a water flow meter.

Unfortunately, the water flow meter I got doesn’t have very granular output. It outputs a single pulse for every gallon and since a lot of the time we’re flushing a toilet or washing our hands the reading is very small. What’s worse is if I look at that output once in a minute the pulse(s) may have happened early on in the minute and now the water flow is actually off so calculating delta doesn’t work reliably.

What’s the best way to organize my ESPHome data to capture “filter health” most accurately?

I’m wondering about this approach:

  • When flow is over 3gpm (which means I got at least three pulses in one minute)
  • And the previous measurement was also over 3gpm (sustained usage for over a minute)
  • Now take the cached pressure measurements from over the previous minute and calculate delta from it

I’m thinking I have “high-flow” and maintain a “high-flow” state from one minute to the next, then that previous minute’s pressure measurements are probably most likely to be during a high-flow state. I’m just not sure what the best way to approach this using ESPHome methods. I know this is a very complex way to handle it but it should be possible, right?

Alternatively, I could:

  • When flow is over 3gpm, start temporary recording of pressure values
  • If the next minutes flow is also over 3gpm, record temporary values as permanent values (publish to HA?)
  • If the next minutes flow is under 3gpm, throw the temporary values out

Any ESPHome pros want to take a shot at trying to build that? :smiley: I’ve got something complicated and it’s working but neither of these ways.