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

I had trouble with this “double pulse_meter code” (as well as with the pulse-counter and template code to calculate liter/min). In the end only using this code that gives correct liter/min and total liter (although liter/min doesn’t immediately drop to 0 when water stops):

- platform: pulse_meter
    pin: GPIO14
    name: "Water Pulse Meter"
    unit_of_measurement: "liter/min"
    icon: "mdi:water"
    total:
      name: "Water Total"
      unit_of_measurement: "liter"
      state_class: "total_increasing"
1 Like

OK thanks for confirming, that those double counters do not work at your side. I finished my water meter as well w/o them. Added some timeout to push for faster show zero l/min when the water stops.
JJ

hi everyone i’ve been trying to follow the pieter brinkman article, i haven’t installed the sensor on the water meter yet though (wanted to make sure it works first since its outside the house)
i got the esp8266 installed and added the code (the one from MJV from Nov’ 22, the one on the article home assistant didn’t like it) unfortunately when i go. to the energy dashboard and go to add water source, HA doesnt find any sensor. i tried to install the code i added to the node but it will compile fine but when i go to install wireless i get this error
INFO Reading configuration /config/esphome/watermeter.yaml…
INFO Generating C++ source…
INFO Compiling app…
Processing watermeter (board: esp01_1m; framework: arduino; platform: platformio/espressif8266 @ 3.2.0)

HARDWARE: ESP8266 80MHz, 80KB RAM, 1MB Flash
LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
Dependency Graph
|-- ESPAsyncTCP-esphome @ 1.2.3
|-- ESPAsyncWebServer-esphome @ 2.1.0
| |-- ESPAsyncTCP-esphome @ 1.2.3
| |-- Hash @ 1.0
| |-- ESP8266WiFi @ 1.0
|-- DNSServer @ 1.1.1
|-- ESP8266WiFi @ 1.0
|-- ESP8266mDNS @ 1.2
|-- noise-c @ 0.1.4
| |-- libsodium @ 1.10018.1
Compiling /data/watermeter/.pioenvs/watermeter/src/esphome/components/api/api_connection.cpp.o
xtensa-lx106-elf-g++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
*** [/data/watermeter/.pioenvs/watermeter/src/esphome/components/api/api_connection.cpp.o] Error 1
========================= [FAILED] Took 19.78 seconds =========================

any ideas i’ve been puzzled for a week. also i’'v only been using HA for about 2 weeks as well.

To add it as water source in HA Energy Dashboard the device_class, state_class & unit_of_measurement need to match the requirements in order for the source to show up. (I was originally using “liter” for Grafana, but for HA Energy Dashboard it needs to be “L” or “m³”) . In the end figured out how to use a template to have a copy of the pulse_meter water_total output in “L”

  - platform: pulse_meter
    pin: GPIO14
    name: "Water Pulse Meter"
    device_class: water
    unit_of_measurement: "liter/min"
    icon: "mdi:water"
    total:
      name: "Water Total"
      id: water_total
      state_class: total_increasing
      unit_of_measurement: "liter"

  - platform: template
    name: "Water Main Consumption"
    id: water_main_consumption
    device_class: water
    state_class: total_increasing
    unit_of_measurement: "L"
    accuracy_decimals: 0
    icon: "mdi:water"
    lambda: |-
      return {id(water_total).state};

The wireless installation issue seems unrelated and doesn’t ring a bell

How far is the pulse / magnetic field detectable?

Sadly my water meter is out on the street under a box on the walkway. So I don’t want/can’t install anything directly visible on top of it.

I highly doubt passengers would open this box but the water guy might stop by and read the meter.

I was thinking running a longer cable with the sensor from my house next to the water pipe and then install the sensor on the edge of the box where it’s not visible.
Could this work?

Hello dydx,

I am in the same case : my water meter is out on the street, behind my wall. But luckily just behind the wall I have a hatch that contains a faucet and it’s directly behind the water meter.

So I drilled a hole where the water meter is located towards my access using a long concrete bit and threaded the sensor cable through.
Luckily I already had an electric cable inside and I just had to connect it to the sensor. At the end of this cable, my arduino, safe in my garage where it can connect to the wifi.

I had the same concerns about the water guy but I think it will be ok for him, he still can read the values even if there is a sensor over the metal spin.
I spoke to a friend who works in the field and said it was ok, no problem for anyone as soon as the values are visible.

Hope that helps :slight_smile:

1 Like

Hi @LeorFinacre

Yes thanks! Would you mind sharing a picture (ok via PM) how this looks for you? (The meter part). I’m not completely sure yet …

Will this project likely work with this water meter https://www.amazon.co.uk/Diamond-Water-meter-flow-fittings/dp/B0104NPOEE

Hey guys, all is working, but why I see only Total and Water Pulse Meter?
image

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

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

  - platform: pulse_meter
    pin: D6
    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
1 Like

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?