Amount of water used during irrigation cycle


I have an irrigation valve and a watermeter set-up in HA. I would like a sensor which will give me the amount of water used each time an irrigation cycle is completed(valve open and closed). Perhaps even with the cost. Is this possible and if yes, what would be the best way to approach this?
I am thinking a template sensor, but have no idea where to start.

Tell me more about the water meter you have in HA. What hardware is it and how does it show up in the system.


Thank you for your reply.
I use a gateway fixed to my analoge water meter which sends the data through mqtt protocol. It shows me the actual gauge reading, hourly, monthly and yearly usage.

There are several ways to approach this. Here is an approach.

A) Meter reading at start of cycle. Create a template sensor with a trigger on irrigation start capturing the current water meter reading.
B) Total volume for cycle. Create a template sensor with a trigger on irrigation stop that calculates the difference between the current water meter reading and the value in Sensor A
C) Total cost for cycle. Create a template sensor with a Trigger on B, that multiplies the trigger value * the water cost. Consider using an input number to store the cost per unit of water.

Thank you, sounds good. I will try.
Referring to the last part of your answer: what would an input number do and why would that be beneficial?

You could put your cost of water per gallon (or whatever unit it is in) in that input number, that way if it changes you can just update the input number in a dashboard vs editing the YAML.

It would probably be easier to just log the time the valve has been on using history stats and multiply that by the flow rate in a template sensor.

Not sure if that would work since the different valves have different flow rates and these are not 100% constant.

If you know that info, it should be doable. You’d just have multiple history stat sensors.