# Can I calculate water usage if I know GPM and run time?

I have 65 irrigation heads and I know they flow 2.3 gallons per minute (GPM). I’m using HA to run the irrigation (using Smart Irrigation). Since HA will know the amount of time the irrigation runs can I use this data to calculate my water usage? I’d like to track the gallons used (and preferably, the cost) and reset it each month. Then I can use that data in my automation to turn off my irrigation if I hit a set monthly budget.

The irrigation integration calculates the amount of time the irrigation should run, I have an automation that runs each zone for that amount of time. Presumably, I could calculate my water usage in that automation somehow. For example, have an action in the automation that calculates `runtime * total gpm`. But that would just calculate the gallons used during that single watering. What would I use to track the cumulative amount?

Thanks. It looks like in order to use this I’ll need to create a sensor that monitors the amount of time the zone valve is open, multiply that time by the GPM then by the cost per gallon. Then I just need to multiply that by 15 zones

My zones are all switches in HA (switch.zone_1, switch.zone_2, etc). How would I create a sensor that tracks the amount of time the zone is on? If I can get that figured out I think I can stumble my way through a template to multiply by GPM and cost then add all the zones. Any help with that first step is appreciated.

1 Like

Take a look at this sensor. I use it my own project, examples can be found here.
Cheers

Thanks for the reply. I looked at the unlimited irrigation system. I want to stick with the HA smart irrigation add-on.

I was thinking more about this. If I know that my total system will use 150gpm and I know at the beginning of the script that the system will run for 25 minutes ( `sensor.adjusted_time_zone2to14`) and I know my cost is \$0.0116 per gallon can I make the script run that calculation at the beginning and update the utility meter with the result?

If system usage (gpm) and cost (\$/g) are constants then your budget is really just time, how many minutes per month can I afford to run the system for. As mentioned above something like this should add up the time.

``````utility_meter:
monthly_water_usage:
name: Monthly Water Usage
cycle: monthly
delta_values: true
``````

In HA sensors consume other sensors so if you really want it in \$'s then create another sensor (template) that reads the utility meter and multiplies it by 0.029 (150 * 0.0116 / 60).

BTW: HAsmartirrigation and Irrigation Unlimited work very well together. One accurately calculates the run times and the other manages the system. If your system is not too complicated then stick with the automation examples in HAsmartirrigation.

I like where you are going with this, but that doesn’t quite work. I’m using the sensor `sensor.adjusted_time_zone1` to set the runtime of the zone (I have 15 total zones, just using one here as an example). However, that sensor will update every evening at 11pm based on how much irrigating the system thinks my yard needs. The irrigation runs for that set time every Mon, Wed, Fri, the irrigation script resets the bucket which would set that `sensor.adjusted_time_zone1` to 0.

So the utility meter isn’t actually tracking how long the zone runs, but how long it’s supposed to run. What tells the utility meter that the zone ran for that amount of time? `sensor.adjusted_time_zone1` might be “5 minutes” one day, “15 minutes” the next day then “0 minutes” the 3rd day after the irrigation runs. Will the utility meter correctly record 15 minutes as the runtime? How does it know to record that amount? Something must trigger it.

Take a look at the history_stats integration. It has an example that shows how long a light has been on for today. Other examples show the last 24 hours from 4pm to 4pm, 30 days and so on. Should be able to adapt it to this month.

Thanks! I think history_stats may work for this. The only problem I see is getting the dates to line up. My water bill always calculates from the 22nd of one month to the 22nd of the next month. I found how to start the history_stat on May 22nd to get it going, and I can set the duration to 30 days, but that will eventually get out of sync.

``````- platform: history_stats
name: Zone 1 Cummulative Runtime
entity_id: switch.zone_1
state: "on"
type: time
start: "{{ now().replace(year=(now().year-0)).replace(month=5).replace(day=22).replace(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0) }}"
duration:
days: 30
``````

Do you know how I can have it start on the 22nd of every month and end on the 22nd of the next month?

Actually, I may have figured it out. Would this be the correct syntax to have the history stat collect data between the 22nd of each month? So, start every month on the 22nd and restart the following month on the 22nd?

``````- platform: history_stats
name: Zone 1 Cummulative Runtime
entity_id: switch.zone_1
state: "on"
type: time
start: "{{ now().replace(day=22).replace(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0) }}"
end:  "{{ now().replace(month=(now().month+1)).replace(day=22).replace(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0) }}"
``````

It looks about right. Sort of a sliding window.