I am pretty new to ESPHome - a friend got me hooked up and I am familiar with the basics, but have very little experience. So here is my problem:
I am trying to measure water flow rate and consumption using this meter, which comes with a Reed Sensor specifically made for this purpose by the manufacturer:
Now my problem is, that once or twice a day the ESP seems to measure a great number of pulses in a short period of time, leading to this:
The numbers sometime go up to several thousands.
I researched a bit and there are some setups with Reed Sensors that included a resistor and somehow also 3.3v in the schematic - but as I set the D3 pin to PULLUP and connected it to ground I concluded from several sources that this should work.
What makes it a bit harder is that I can’t reproduce the problem and it only happens every couple of hours. Aside from that the sensor is working more or less fine - it is a bit hard to tell.
Also I am not quite sure how the Pulse Meter component is working with a reed switch. For example, what happens if the meter stops exactly when the reed switch is closed? Or if it is a bad position where the reed switch somehow fluctuates becaue it is at the edge of opening / closing?
I see two options:
Try a different reed or hall sensor and see if the problem persists.
Try to filter out more than 1 pulse every 5-6 seconds. I tried median, but that didn’t work as there are not enough pulses most of the time and then to many when the problem appears.
I greatly appreciate any input / experience you might have with this. Thanks!
I would imagine it’s rapid fluctuations. The throttle or debounce filters should sort you out:
If it’s one pulse per 10 litres, work out the fastest rate you can consume water, double it for safety and set the throttle to that. So if you can pull 40 litres per minute, that’d be one pulse every 15s, so set the throttle to about 8s.
If that doesn’t work on the pulse_sensor platform, there’s also the internal_filter option:
…which might work if you’re seeing a “broad” pulse and a lot of spurious “narrow” pulses.
I read through the filters and thought that this was only to regulate sending info to HA (meaning ESP is counting the pulse, but not sending an update to HA). If that means that it basically discards the pulses it would be perfect. I set it to 10s to begin with (might be a bit aggressive, but I can lower it if it works and I am missing pulses on high usage).
Another question: If I want to internal led of the D1 mini to turn on every time it gets a pulse can I set a binary sensor to the same pin as the pulse meter (measing two sensors on one pin) and then just automate to turn on D4 when the binary sensor is ON? That would give me some idea on what’s going on with the reed sensor.
Worth a try. I did something similar for my electricity meter, but with the input connected to two pins, D2 and D5 below, then “mirrored” that pulse onto D1 to drive the external LED (instead of internal D4). I can’t remember if I tried running two sensors from one pin first.
Don’t use D3 its connected to the flash.
That will give very strange reading on the pulse counter.
Suggestion is to use d1 or d2.
Thanks for the tip - I switched to D1 for further testing.
I tought D3 was sensible because it was already PULLUP - lesson learned.
I read most of the other thread btw - just didn’t make the connection to my problem or didn’t find it.
I tried and it at least didn’t work on the first try. As soon as I have time for some soldering I will hook up the input to D1 and D2 and see if that works. But that also means that I connect D1 und D2 - would that be a problem?
I’m going to suggest “no” from looking at the “best pins to use” table at this link:
Connecting D2 and D5 certainly hasn’t caused me a problem. Logs look like this:
[13:28:47][D][binary_sensor:036]: 'Meter pulse mirror': Sending state OFF
[13:28:47][D][switch:021]: 'Garage sensor box LED' Turning ON.
[13:28:47][D][switch:045]: 'Garage sensor box LED': Sending state ON
[13:28:47][D][binary_sensor:036]: 'Meter pulse mirror': Sending state ON
[13:28:47][D][switch:025]: 'Garage sensor box LED' Turning OFF.
[13:28:47][D][switch:045]: 'Garage sensor box LED': Sending state OFF
[13:28:57][D][binary_sensor:036]: 'Meter pulse mirror': Sending state OFF
[13:28:57][D][switch:021]: 'Garage sensor box LED' Turning ON.
[13:28:57][D][switch:045]: 'Garage sensor box LED': Sending state ON
[13:28:57][D][binary_sensor:036]: 'Meter pulse mirror': Sending state ON
[13:28:57][D][switch:025]: 'Garage sensor box LED' Turning OFF.
[13:28:57][D][switch:045]: 'Garage sensor box LED': Sending state OFF
[13:29:01][D][pulse_counter:159]: 'Power Meter House': Retrieved counter: 6.00 pulses/min
[13:29:01][D][sensor:099]: 'Power Meter House': Sending state 0.36000 kW with 2 decimals of accuracy
OK, I will have to try to get an LED blinking and do some testing as the throttle with 10s did not work:
The total meter jumped 30 litres in that time intervall, meaning 3 pulses were counted. To get at that number those had to be counted in under a second which should be impossible with the throttle to 10s.
If the sensor is throttled to 10s maximum (see config above) pulse count in a minute is 6 pulses multiplied by 10 is 60l max. How is it even possible that the sensor reports 1612 l/min?
Is the order of the filters relevant? So first throttle, then multiply?
BUT: I just found out the throttle doesn’t work that way. When I just keep crossing the wires again and again it DOES only send an update to HA every 10s - but with ALL the pulses counted in between or in my case the number calculated with the filter.
So what I would need it to do is actually discard the pulses for calculation on the ESP. Basically like internal_filter but instead of discarding short pulses it should discard any pulses above x per timeframe, after that start counting again.
I have considered just using the raw pulse_meter or even a binary sensor to HA - but haven’t found anything in HA that basically says “if more than x pulses are counted in t seconds treat it as 1”.
Any ideas? I am really wondering about this as the sensor as such is being used by utilities to measure consumption so I would guess it should be working better than this.
Reed switch connected as a throttled binary_sensor, output copied to another pin, connect that pin to the pulse_counter input pin? Wastes a few pins versus the ideal, but if you have spares, it looks like it’d work.
Interesting idea - I googled that and went through the ESPHome documentation, but found nothing about it. Do you mean a template sensor like this?
Binary Sensor with throttle 10s
Template Sensor for the binary sensor
Pulse Meter Sensor - but on what?
Or how do you map that to a pin? Or do you mean with a switch that turns on a pin and measure that on another pin?! That would be - well - not very elegant…
Exactly that, and yes, not elegant. See my code above: connect your switch to D2, throttle it and it sends its output to D1. Connect D1 to D5 and you have a pulse counter with a throttled input — if the on_press event is “after” the throttle.
Quick update for future readers: It appears the problem I saw with faulty readings was due to a bad solder point on the GND pin leading to flickering like 2-3 times a day. I found out when I tried a different reed sensor board for testing and the power LED flickered on touch. So as per usual - user fucked up.
I will monitor for a couple of days and post picture and config of the final setup…
So it definitely was a badly soldered GND pin. To have some transparency on what’s going on I bought a Reed sensor on a board for 2 EUR, clipped off the sensor capsule and soldered on the Reed sensor from the water meter. Now everything’s working fine…
Hi @NamCisum, I’ve just read this topic and I’m very interested in making something similar in my water meter, so thanks a lot for sharing!
I want to ask you what Reed sensor have you used, because I’m not very familiar with them and I’m very confused with Aliexpress because thay are “window” sensors, and not sure if they will work.
Also I searched for the official Reed sensor of the meter manufacturer, but price list is >20EUR and I’m not sure I would find were to buy it.
I used the reed sensor provided by the manufacturer, but instead of connecting the two wires from the sensor directly to a digital input and GND I used one of these:
I removed the sensor capsule on top and soldered on the reed sensor from the meter. I then used the Poti and the LED to fine-tune sensitivity. You can use the AO in addition to the DO to troubleshoot (i.e. bouncing due to a slow moving dial on the meter).
i have the same Problem with the same setup but my weldings seems to be ok. Can you send me your ESP32 config please? I would like to compare it with my setup. How did you Manage your setup with the Water integration of the Energy Dashboard?
The last sensor (adc) works because I have the digital output of the reed sensor to the D1 digital input and the analogue output to the A0 analogue input. This way I can monitor the actual voltage coming into the pin which was interesting to understand how the reed sensor works… Nevertheless, the sensitivity for the digital output to gow low / high is set by the board (see post above), which I presume does some debouncing which solved my problem (I guess…).