How to use peristatic pump until a certain volume is reached?

I am trying to activate a peristaltic pump to add media using the pH change as a trigger. So when a pH threshold is reached after a minimum interval between checks, I activate the pump. But I need to limit the added media volume.

What I have planned:
I have created a Bang-bang hysteretic function to activate the pump.
And creating a conditional to read the volume and deactivate the aforementioned function.

Is there an easier way to do it?

I would just do everything within one Conditional Function. That’s simpler (one Function instead of two), but not necessarily easier if you’re not an experienced Python programmer.