I’m trying to integrate my home water and gas usage into HA. I bought a cheap water flow meter with built in hall sensor from ali, but it wasn’t accurate at low flow rates. The home’s water utility meter is very accurate. For $10 an easp32 and a QMC5883L Magnetometer can sufficiently read magnetic changes inside the meters!
I’m just struggling to convert the sine wave reported over i2c into pulse count data. I have tried using lambda as a trigger when sensor value reaches a high point in the curve, but i’m lost in then feeding that to a pulse counter.
I thought about trying to output the signal, using a GPIO to another pin on the board setup as a pulse counter, but it seems like there must be an easier way i’m missing.
I wouldn’t think you would be able to feed into a pulse counter from a sensor, the pulse counters are hardware in the chip that count pulses at the pin.
I would think you would need to use a custom sensor that would count the pulse internally.
I’m looking to do the same thing, but had hoped that someone has already done the work.
I havn’t spent much time on it. I did find a solution by using mysensors that I’ll probably use eventually. I’m sure ESPhome can provide the same functionality, but I lack the understanding to make it work right now.
Every time your binary sensor turns on, turn on a GPIO output (using on_press and on_release). Short this to another GPIO input that you can feed to your pulse counter.
I will try this out this week. My current current setup does measure the field strength peaks accurately. I just need this counter solution to make is useable. Thanks Tom.
So I have something that is mostly working and if your cycles are as long as they look it may work for you. It’s not for me because the qmc5883l is only sampling once a second and my meter spins faster than that.
Thanks for this. I am able to monitor my water at my water softener turbine sensor using your code with some modifications. The turbine can spin about 30rps so setting the interval to 5ms works perfectly.
Keep track of the max and min values ever reported, so in a matter of few cycles you’ll know the range of the sensor.
Then compare each reading with the previous one, and if it’s increasing, once it crosses the mid point you count one tick. Every 30 seconds you publish the daily count (see the daily energy example).
If you need more help than this you can try with chatgpt, it gave me a basically complete sketch with a request similar to what I just told you.
Thanks for sharing this project. Got water meter sensor going and in process of getting gas meter sensor up and running. Still too early to determine accuracy but water seems fairly close at least.
Glad you found it useful. If you want you can use the same ESP32 (recommended) or ESP8266 for both meters. Instead of including esphome-water-meter.yaml, include esphome-two-meters.yaml. See the file for the available substitutions.
Thanks @tronikos. Amazing project and your instructions are detailed. I followed along and set this up on first try. I was wondering why my calculations were reported in gallons then I read more and figured I had to change the “Volume” to litres. Now that I have water fairly close to accurate (off by 1.7L). Going to start with the natural gas meter. Hopefully you have the time to do one on electricity monitoring Then I will everything monitored
That means you successfully get triggers on your template sensor?
If so, you could use a template number and number.increment action on your sensor code.