Build a water meter with ESPHome and proximity sensor (no soldering required)

Because you have twice the same definition

So I also have a Neptune T10, am in the US. I’ve tried the sensor as well and I never get any pulses. I know this meter is compatible with Flume. I wonder what they use as a sensor??

1 Like

I have the meter in the picture included. I am not able to get a signal using a proximity sensor. Where I can find the spinning magnet?


1 Like

I also have Neptune T10, any luck finding a solution? I was hoping DIY solution.

1 Like

Hello everyone,
First of all, I would like to mention that I am a complete novice in this matter, so I ask for your indulgence.
My english isn’t that good either, hence the google translation
I realized the project with an ESP8266 the LJ18A3 sensor.
The results are also arriving in the Home Assistant, I have copied the code and it can certainly be improved, suggestions are welcome.
My problem (see graphic) are these deflections after which I would consume 60000l or 12000l.
I have no explanation for that, my wife also thinks the amount of water measured is not correct (manual comparison)
Now my question to the community, hoping for help.
How do I calibrate the sensor?
Where do the “freaks” come from?
Is the sensor placed correctly?
The sensor and the ESP are powered by a branded USB power supply.
Hope you can help and thank you in advance.

https://www.dropbox.com/scl/fo/5wckn0r5c5wgrt23gkcz0/h?rlkey=v1ovhmvonsiajyniekzxspz4l&dl=0

I have a problem with i think are the liters water. Someone who knows what the problem is.

esphome:
  name: watermeter-home
  friendly_name: watermeter_home

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "RYGJ6iv2oRc7YD58gcA+esugt/QEcL7LGHWX26a1tDA="

ota:
  password: "******"

wifi:
  ssid: ********
  password: *******!

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Watermeter-Home Fallback Hotspot"
    password: "********"

captive_portal:


sensor:
  - platform: pulse_counter
    pin: GPIO12
    update_interval : 6s
    name: "water pulse"
    id: water_pulse

  - platform: pulse_meter
    pin: GPIO12
    name: "Water Pulse Meter"
    unit_of_measurement: "liter/min"
    icon: "mdi:water"
    total:
      name: "Water Total"
      unit_of_measurement: "liter"

  - platform: pulse_meter
    pin: GPIO12
    name: "Water Pulse Meter"
    unit_of_measurement: "liter/min"
    icon: "mdi:water"
    total:
      name: "Water Meter Total"
      unit_of_measurement: "m³"
      id: water_meter_total
      accuracy_decimals: 3
      device_class: water
      state_class: total_increasing
      filters:
        - multiply: 0.001

  - platform: template
    name: "Water Usage Liter"
    id: water_flow_rate
    accuracy_decimals: 1
    unit_of_measurement: "l/min"
    icon: "mdi:water"
    lambda: return (id(water_pulse).state * 10);
    update_interval: 6s

After the most recent update of ESPhome some tweaks to the water-meter code may be required, relating to the multiple usage of the same pin. This code fixes the errors, unfortunately unable to test whether it affects the sensor readings.

sensor:
  - platform: pulse_counter
    pin: 
      number: GPIO12
      allow_other_uses: true
    update_interval: 6s
    name: "water pulse"
    id: water_pulse
  - platform: pulse_meter
    pin: 
      number: GPIO12
      allow_other_uses: true
    name: "Water Pulse Meter"
    unit_of_measurement: "liter/min"
    icon: "mdi:water"
    total:
      name: "Water Meter Total"
      unit_of_measurement: "m³"
      id: water_meter_total
      accuracy_decimals: 3
      device_class: water
      state_class: total_increasing
      filters:
        - multiply: 0.001
  - platform: template
    name: "Water Usage Liter"
    id: water_flow_rate
    accuracy_decimals: 1
    unit_of_measurement: "l/min"
    icon: "mdi:water"
    lambda: return (id(water_pulse).state * 10);
    update_interval: 6s
    device_class: water
3 Likes

This indeed solved my issue with multiple Pin usage. Thx

1 Like

Based on some comments in a previous thread, I suppose getting rid of the pins being used twice would be better. Since the introduction of Water into the Energy dashboard, only one entity would be sufficient:

sensor:
  - platform: pulse_meter
    pin: 
      number: GPIO12
    name: "Water Pulse Meter"
    unit_of_measurement: "liter/min"
    icon: "mdi:water"
    total:
      name: "Water Meter Total"
      unit_of_measurement: "m³"
      id: water_meter_total
      accuracy_decimals: 3
      device_class: water
      state_class: total_increasing
      filters:
        - multiply: 0.001

2 Likes

I have followed the original setup of this water meter, after changing the “allow_other_uses” it worked but then came across your single sensor setup which makes sense.

However I get very weird numbers.
According to the “water meter total” I already consumed 27.684 m³ in the last 10 minutes. (dish washer and testing water at the faucet)

27m3 is 27 000 liters of water, which is bonkers. I assume there is something wrong with either the “multiply” for my setup, or the actual sensor changed its output? I’m using the same one as the OP.

Great coding @MJV
Thanks for the update!

I made the sensor and works straight after first try.

Question: I would like to implement the real water sensor count which increments the usage in a counter. This has two usages: calibration of pulsecoding and logging of watermeter. How would one achieve this?

which ESPHome YAML code is the most current in 2024?
when using the code form: Build a cheap water usage sensor using ESPhome and a proximity sensor - PieterBrinkman.com doesnt work anymore

1 Like

I recently used this one: https://github.com/geertmeersman/energie-meter/
I used a Wemos D1 clone as I already had it.
I dont have a gas meter, so left that one out.
Also, in the utility meter yaml example you need to specify the ESPhome sensor, not “sensor.water_used”.
After calibrating, works like a charm!

image

1 Like

@rda great, can you show me the yaml config for esphome.

And how dou you count the actual value of the watermeter?

Is it possible with this watermeter (M120 Elster I guess)

I got LJ18A3-8-Z/BX NPN?

I have a Badger Meter 62584-020 Recordall Transmitter Register.
Data sheet suggests magnetic (metal) disk nutates to transfer to other magnetic disk…etc
It detects metal, the copper pipes, the metal to the frame of my desk…etc.

But couldnt for the life of me figure out where the sensor/disk was. Is it possible the disk is not metal/magnetic? the Glass/plastic isnt as thick as I feared and was really really hoping this would work as my water bill spiked huge last bill and was hoping to get independent monitoring to corraborate and troubleshoot?

Do I possibly need the PNP one instead?

If this doesnt work, what other use cases can I repurpose this sensor???

1 Like

I uave a question on this.
I have a meter with 1 pulse per gal and its counts the gallons correctly, but the gallons per minute do just show 1 x 12 gal/min and then nothing again while water is running. And still counting the gallons up.
Here my code:

sensor:
  - platform: pulse_counter
    pin:
      number: GPIO14
      inverted: true
      mode:
        input: true
        pullup: true
    name: "${upper_devicename} Flow"
    unit_of_measurement: "gal/min"
    icon: "mdi:water"
    update_interval: 5s
    accuracy_decimals: 0
    internal_filter: 400ms
    count_mode:
      rising_edge: DISABLE
      falling_edge: INCREMENT
    filters:
      - lambda: return (x);
    total:
      name: "Total Water Consumption"
      unit_of_measurement: "gal"
      device_class: water
      state_class: total_increasing
      accuracy_decimals: 0
      icon: "mdi:faucet"

Is there anything obvious that i am doing wrong?
Thx gor any thoughts

Sorry for the late reply, missed the update I think.

Here is the code for watermeter.yaml:

packages:
  base: !include common/base.yaml
  base_global: !include common/base_global.yaml
  
substitutions:
  device_name: watermeter
  device_name_short: watermeter
  friendly_name: "Water Meter"
  esp_type: "ESP8266"
  impulsfactor_water: "0.001"
  impulsfactor_gas: "0.01"
  update_interval: 60s
  update_interval_sensor: 10s
  
esphome:
  name: ${device_name}
  friendly_name: ${friendly_name}
#  platform: ESP32
#  board: esp32dev
#  platformio_options: 
#    platform: espressif32
#    board: az-delivery-devkit-v4
#    board_build.mcu: esp32
#    board_build.f_cpu: 240000000L

esp8266:
  board: d1_mini
  framework:
    version: recommended

# # Enable logging
# logger:

# # Enable Home Assistant API
# api:
#   encryption:
#     key: "J4aOHwwXt4GpYe9w5gsjq6IzVtQuwvVlJLxtuq7LEwQ="

# ota:
#   password: "44699917877381d973c90764f474624f"

# wifi:
#   ssid: !secret wifi_ssid2
#   password: !secret wifi_pwd2

#   # Enable fallback hotspot (captive portal) in case wifi connection fails
#   ap:
#     ssid: "Watermeter Fallback Hotspot"
#     password: "XeTdLirl68sm"

# captive_portal:
    

globals:
  - id: total_pulses_gas
    type: int
    restore_value: false
    initial_value: '0'
  - id: total_pulses_water
    type: int
    restore_value: false
    initial_value: '0'

binary_sensor:
  - platform: gpio
    id: internal_pulse_counter_water
    pin: GPIO2
    internal: true
    filters:
      - delayed_on: 100ms
    on_press:
      then:
        - lambda: id(total_pulses_water) += 1;

sensor:
  - platform: template
    name: "Water used"
    device_class: water
    unit_of_measurement: "m³"
    state_class: "total_increasing"
    icon: "mdi:water"
    accuracy_decimals: 3
    update_interval: ${update_interval_sensor}
    lambda: |-
        return id(total_pulses_water) * ${impulsfactor_water};

I did not change the common yaml files from the repository other than refering to my own secrets.

Seems like it, you have one with the metal plate, so try if the sensor led blinks if you hold the sensor above that one.

I thikn that if there is a metal disk, it would be deep inside, where an external sensor would not detect it. Also, it seems like this meter already has a digital output? Can’t you use that insted? Or search the web for an optical sensor solution which can detect the digits or other indicators on this meter.