I have two valve entities that can be either on or off and if they are on I know the amount of water that is coming out of one end with a relative high certainty.
They are actually little power outlet controlled pumps going into a micro drip system. I know the number of drip outlets and that each is putting out 2l/h. So in the end I could say: If this valve was open (pump was on) for 3 minutes and it has 16 drip outlets it would be 2000 / 60 * 3 * 16 = 1600ml or 1,6l.
I am not sure how I would be able to do this in a template. In the end I would want to put it into a Utility Meter to track the usage but for that I need a sensor entity that tracks the l of water used. How could I do it?
I have similar config but for furnace. I know how long burner is on and I estimated how much gas is used by one stage burner. It is not 100% accurate but it is way over 95% as I use gas for cooking daily.
In sensors.yaml I have
- platform: history_stats
name: Buderus On Time Today
entity_id: binary_sensor.buderus_kessel_betrieb_1_stufe
unique_id: 561dda8d-06a9-4322-8785-9fd364690ed2
state: "on"
type: time
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
So it will calculate how long the burner is on
In template.yaml i have
One thing you need is a sensor that simply returns the L/h or L/min value - either 0 when off or the known value when on: 2L/h. Summing the value over time is what integral sensors do. You can create a helper in the helper section. Make sure to use Left Riemann sum as the method or you’ll get weird values.
It will create the total use over time. If you want use per year, month, day, etc. you can use utility meters.
The approach also works if the L/h value is not constant, e.g. if it uses the number of valves that are open or a percentage value to collect the total flow at that instant.
Ps. Though it really isn’t hard once you know how: if you want to do something similar for energy then there is an integration that makes this easier, unfortunately it only does Watts to kWh and not L/min to L although the principle is exactly the same.