Measuring individual devices from total consumption based on Boolean/switch etc

I am measuring my whole house water consumption. It’s a sensor “gallon” of total usage.

Now I would like to measure just the water consumed by irrigation. Since irrigation happens only at night, I can assume no other water is being consumed at the same time. And since I use Rachio, I know exactly when irrigation runs (based on switch entities of the valves).

What is the best way to implement this?

Seems this is not too trivial. If I use a template sensor in which I pass the total consumption when the switch entity is enabled I get big jumps. Possibly I need to take the derivative and then integrate but this feels complicated and inaccurate. And even then, the integration sensor does not have an “enable”.

I think utility_meter may do what you want here.

Create a utility meter, using your whole house sensor. Give it two tariffs, you can name it “irrigation” and “other”.

When the meter select is set to irrigation, any increase in the whole house sensor is added to the irrigation sensor. When the meter select is set to other, any increase in the whole house sensor is added to the second sensor.

This is phenomenal!!!
I think it works