Problem with Reed Sensor on Water Meter

Hi all,

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:


German Website: → Click.

The Reed Sensor tracks the turning wheel below it and should give a pulse every 10 litres of water by just closing the contact on the two wires.

I use a AZ Delivery D1 Mini and hooked the sensor up to GND and D3, heres the config for Pulse Meter:

esphome:
  name: esp-0dev
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "KMesh"
  password: "#redacted#"
  manual_ip:
    static_ip: 192.168.23.34
    gateway: 192.168.23.1
    subnet: 255.255.255.0
    dns1: 192.168.23.1  

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp-0Dev Fallback Hotspot"
    password: "###"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

sensor:
  - platform: pulse_meter
    pin:
      number: D3
      mode: INPUT_PULLUP
    unit_of_measurement: 'l/min'
    name: 'Wasser Durchfluss'
    internal_filter: 100ms
    filters:
      - multiply: 10
    total:
      name: "Wasser Gesamt"
      unit_of_measurement: "m³"
      accuracy_decimals: 3
      filters:
        - multiply: 0.01

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:
grafik

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:

  1. Try a different reed or hall sensor and see if the problem persists.
  2. 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.

Hi.

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.

In this thread you can probably find answer some of the issues people have encountered with water meters.

/Mattias

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.

switch:
  - platform: gpio
    pin:
      number: D4
      inverted: yes
    name: "Garage sensor onboard LED"
    id: "onboard_led"
    internal: true

  - platform: gpio
    pin:
      number: D1
      inverted: yes
    name: "Garage sensor box LED"
    id: "box_led"
    internal: true

  - platform: restart
    name: "Garage sensor restart"

binary_sensor:
  - platform: gpio
    pin: D2
    name: "Meter pulse mirror"
    internal: true
    on_press:
      then:
        - switch.turn_off: box_led
    on_release:
      then:
        - switch.turn_on: box_led

sensor:
  - platform: pulse_counter
    pin: D5
    unit_of_measurement: 'kW'
    name: 'Power Meter House'
    filters:
      - multiply: 0.06
    id: house_power

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?

Here’s the config for that:

sensor:
  - platform: pulse_meter
    pin:
      number: D1
      mode: INPUT_PULLUP
    unit_of_measurement: 'l/min'
    name: 'Wasser Durchfluss'
    internal_filter: 100ms
    filters:
      - multiply: 10
      - throttle: 10s
    total:
      name: "Wasser Gesamt"
      unit_of_measurement: "m³"
      accuracy_decimals: 3
      filters:
        - multiply: 0.01
        - throttle: 10s


binary_sensor:
  - platform: gpio
    pin: D2
    name: "Meter Pulse Mirror"
    internal: true
    on_press:
      then:
        - switch.turn_off: onboard_led
    on_release:
      then:
        - switch.turn_on: onboard_led

switch:
  - platform: gpio
    pin:
      number: D4
      inverted: yes
    name: "Onboard LED"
    id: "onboard_led"
    internal: true

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:
grafik

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?

Perhaps you need a good old-fashioned RC debounce circuit. YouTube probably has loads of tutorials for what we used to get out of books.

Possibly yes :slight_smile:

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?

  1. Binary Sensor with throttle 10s
  2. Template Sensor for the binary sensor
  3. 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… :slight_smile: :smiley:

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. :man_shrugging:

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…

Thanks for your help along the way!

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:

https://www.amazon.de/AZDelivery-KY-025-Magnetschalter-Sensor-gratis/dp/B07ZJ62W44/ref=sr_1_6?__mk_de_DE=ÅMÅŽÕÑ&crid=296EM04NFMAFI&keywords=reed+sensor&qid=1662148519&sprefix=reed+sensor%2Caps%2C286&sr=8-6

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).

2 Likes

Hi @NamCisum,

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?

Thanks in futher and kind regards.

Sure, here’s the relevant part (it’s an ESP8266):

(From your username I gather you speak German, so I leave it uncommented)

sensor:
  - platform: pulse_meter
    pin: D1
    unit_of_measurement: 'l/min'
    name: 'Wasser Durchfluss'
    internal_filter: 5000ms
    filters:
      - multiply: 10
    total:
      name: "Wasser Gesamt"
      unit_of_measurement: "m³"
      device_class: water
      state_class: total_increasing
      accuracy_decimals: 3
      filters:
        - multiply: 0.01
  - platform: adc
    pin: A0
    name: "Wasser A0"
    update_interval: 10s
    filters:
      - delta: 0.1

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…).