Water Meter sensor - Australia, Victoria

I’m going to pick some up from jaycar later today, once i build my I’ll share my schematics

you may want to lookup the difference between pull_down and pull_up GPIOs they vary from dev board to board.

I’ve had some success with the glass reed switches from Jaycar. It seems to be working well.

The first one would barely register a pulse on the bench with a magnet but the second (installed much jankier in the meter!) seems to be working well! Not sure if it matters but I paid close attention the second time not to bend the legs too tight. This article was useful: How_to_Handle_a_Reed_Switch-1.pdf

The code below isn’t perfect and I’m a novice, but it seems to be working well. If the community would like to see an extended version that includes local caching of the meter values to survive a reboot just say the word.

Here’s a subsection of my ESPHome code running on ESP8266.

sensor:
  - platform: pulse_counter
    pin: 
      number: GPIO15
      inverted: True
    unit_of_measurement: 'L/min'
    update_interval: 60s
    name: 'Water Usage'
    id: waterusage
    accuracy_decimals: 0
    filters:
      - multiply: 5
#If your meter is 25mm to 40mm then set to 5. If you meter is 15mm to 20mm then set to 0.5
    
    total:
      name: "Water Usage Total"
      id: waterusagetotal
      unit_of_measurement: "L"
      state_class: total_increasing
      device_class: water
      accuracy_decimals: 0
      filters:
      - multiply: 5
#If your meter is 25mm to 40mm then set to 5. If you meter is 15mm to 20mm then set to 0.5

I’m away for a week so excuse delayed responses if you have any questions.

1 Like

While I’m with South East Water as well my meter looks like meter 3 in the URL referenced at the beginning of this thread (i.e. Read your water meter | South East Water).

image
I know the meter has seen better days :slight_smile:

No idea about the specs of this meter but does anyone know whether this has a similar reed mechanism that’s used for the meter described at the beginning of this thread? If not it gets pretty engaged as I think I’d have to go down the image recognition route which is challenging for an outdoor device…

The other path might be to wait for a meter upgrade (if this ever happens) as I read that South East Water has digital meters running.

If there is a port, it should be near the gauge numbers. I had to have a dig around mine to find it. It could also have a plastic plug covering it

1 Like

With a bit of a clean up that meter will work with this setup.

It works pretty well.

The beauty of the LJ18A3-8-Z/BX-5V is that it connects directly to the Esp32 without the need for any resistors etc.

That looks like a great way of measuring your water consumption to help with water leaks . Please share the code for esp32 including the reboot workaround.

1 Like

Hi All,

I have used up 2 jay car reed switches now.
Where exactly is the switch supposed to sit in the slot to register? I bent as close to the glass as possible to get the deeper reading but nothing. doesn’t matter if I rotate 360 degrees.
however it does work flawlessly on the bench.

filtered a lot due to length of cable 30+ meters and uses a pull up resistor 10o 3.3v->gpio16. This is very stable for me. may need to edit for your circumstances

  name: water-meter
  friendly_name: "Water Meter"

esp32:
  board: lolin_s2_mini
  variant: esp32s2
  framework:
    type: esp-idf

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: true
  ap:
    ssid: "Water Meter AP"
    password: !secret wifi_password

captive_portal:

logger:

api:
  encryption:
    key: !secret encryption_key

ota:
  - platform: esphome
    password: !secret ota_password

web_server:
  port: 80

sensor:
  - platform: pulse_meter
    pin:
      number: GPIO16
      inverted: true
      mode:
        input: true
        pullup: true
    name: "Water Flow Rate (l/min)"
    id: water_pulse_meter
    unit_of_measurement: 'l/min'
    icon: "mdi:water"
    internal_filter: 400ms
    internal_filter_mode: PULSE
    filters:
      - sliding_window_moving_average:
          window_size: 10
          send_every: 5
      - throttle: 3s
      - debounce: 50ms
      - multiply: 5

    on_raw_value:
      then:
        - output.turn_on: onboard_led
        - delay: 300ms
        - output.turn_off: onboard_led

    total:
      name: "Water Usage Total (L)"
      id: water_usage_total
      unit_of_measurement: "L"
      state_class: total_increasing
      device_class: water
      accuracy_decimals: 2
      filters:
        - multiply: 5

  # Existing water usage in cubic meters (m³) sensor
  - platform: template
    name: "Water Usage Total (m³)"
    id: water_usage_total_m3
    unit_of_measurement: "m³"
    icon: "mdi:water"
    accuracy_decimals: 3
    lambda: |-
      return id(water_usage_total).state / 1000.0;

  # Real-Time Daily Cost Sensor
  - platform: template
    name: "Water Usage Cost per Day"
    id: water_cost_per_day
    unit_of_measurement: "AUD"
    icon: "mdi:currency-usd"
    accuracy_decimals: 2
    update_interval: 1min
    lambda: |-
      const float cost_per_m3 = 4.212;
      return id(water_cost_per_day).state + (id(water_usage_total_m3).state * cost_per_m3);

  # Cumulative Water Cost Sensor (adds up each day)
  - platform: template
    name: "Cumulative Water Cost (AUD)"
    id: cumulative_water_cost
    unit_of_measurement: "AUD"
    icon: "mdi:currency-usd"
    accuracy_decimals: 2
    lambda: |-
      return id(cumulative_water_cost).state;

time:
  - platform: homeassistant
    id: homeassistant_time

binary_sensor:
  - platform: template
    name: "Day Change"
    lambda: |-
      auto now = id(homeassistant_time).now();
      return now.hour == 0 && now.minute == 0;
    on_press:
      then:
        - lambda: |-
            // Add the current day's cost to the cumulative cost
            id(cumulative_water_cost).publish_state(id(cumulative_water_cost).state + id(water_cost_per_day).state);
            // Reset the daily water cost to $2.56 fixed charge at the start of the new day
            id(water_cost_per_day).publish_state(2.56);

output:
  - platform: gpio
    pin: GPIO15
    id: onboard_led
    inverted: False

Nice templates! I might give those a go.
I bought my reed switch from Amazon: eMagTech 20pcs Plastic Reed Switch Reed Contact Normally Open Magnetic Induction Switch

I did have to bend the far end close to the body to get it to work.

I have 18 spare (broke one) so feel free to PM me your address and I’ll post you a few :smiley:

haha thanks for the offer. I actually purchased that same item this morning for delivery tomorrow. ignore the code above for now as I can’t test it until the items arrive…

Hi all, I am trying to setup a water meter in ha as well. It looks like I have the reed switch port on my meter but my issue is that I don’t have any way to get the irrigation cable to where I have all of my server equipment and was wondering if anyone has been successful in creating a battery solution for an esp32?

not sure on battery.
but tbh I just low level trenched an old 40m cat5 cable I had around. works a charm. if I end up finding this super useful ill do a better cable job.
I also had to tunnel under a wall 0.5m deep to reach my meter box on the nature strip

edited my final code above. working great. although I wish I had the finer 0.5l increments. but 5l will do with the 25mm meter

I originally tried doing a battery operated ESP8266 solution, using these solar gutter lights from Aldi that I cannibalised, but the idle power draw of the ESP was too much (it was about the same as the peak output of the (admittedly small) solar panel - ~80mA).
To this end, I’ve actually switched to using a Zigbee door/window sensor, which is way more efficient, as its idle power draw is basically zero, and only transmits when the meter is actuating. I imagine you could get more efficient with the ESP by messing around with deep sleep settings on an ESP32, but this seemed like the easier option.
Unfortunately, the reed switches I bought (some chunkier glass ones off ebay) don’t seem to be picking up my meter’s pulses… wondering if they’re not sensitive enough for the meter. Currently awaiting some of these (5x25mm), so we’ll see if they’re any good. If they do pick it up, the form factor would be more convenient at least.

I got a water meter sensor working using a ESP32 , but when I try to use a D1 mini it doesn’t work , any ideas how to get it going using a D1 mini , here the code I’m using

sensor:
  - platform: pulse_meter
    pin: GPIO15
    name: "Instant water consumption"
    unit_of_measurement: "L/min"
    icon: "mdi:water"
    timeout: 1s
    accuracy_decimals: 3
    filters:
      - lambda: return (x / 2.0);
    total:
      name: "Total water consumption"
      unit_of_measurement: "m³"
      device_class: water
      state_class: total_increasing
      accuracy_decimals: 3
      icon: "mdi:water"
      filters:
        - lambda: return (x / 2000.0);
  1. It doesn’t give you ‘Instant Water Consumption’, this will give you the ‘Flow Rate’.

  2. Change your timeout, this is saying your dial is rotating every second and if it doesn’t then to discount it.

  3. I assume the meter is 1 impulse = 0.5L, given the “lambda: return (x / 2.0)”

  4. Accuracy decimals is saying track it down to 1ml, change it to 1 decimal if your meter does 0.5L per impulse or 0 if it tracks litres only.

Suggest you drop the multiplication / x divide by stuff out and try it without any, writing down the physical meter reading first then filling up 10L or so from a tap, then check the meter reading outside. This way you can confirm what your meters 1 impulse actually equates to. I have an Elster V100 meter and it should be 1imp = 0.5L, but doing this we worked out it’s actually 1imp = 5L.

Have a look at this code here, for how can be done: myHomeAssistant/esphome/kincony-kc868-a16.yaml at 5d2f6a8e500d5c562ea2b413a1f544a54ece8f6f · Roving-Ronin/myHomeAssistant · GitHub

PS. Also mind that there is a ‘global’ to store away the previous water reading, that is then used on the Water Consumed and Water Consumed Total sensors. See: myHomeAssistant/esphome/kincony-kc868-a16.yaml at 5d2f6a8e500d5c562ea2b413a1f544a54ece8f6f · Roving-Ronin/myHomeAssistant · GitHub

As an aside, if you have a total water consumed sensor (as per prior post gives an example), then this might be of interest. Based upon the @dentra ‘Energy Statistics’ custom_component, this instead provides a breadkdown of the water consumed for Daily, Yesterday, Week, Month and Year. (Note: the last 3 will show ‘NA’ until the next period rolls around i.e. Monday, 1st of month or year).

Example of the code to add into your esp yaml:

###############################################################
#
# Custom Components to be utilised
#

external_components:
  - source: github://roving-ronin/myhomeassistant/components
    refresh: 0s

###############################################################
#
# Water Statistics Sensors
#

# sensor:
  - platform: "water_statistics"
    total: water_consumed_total

    water_today:
      name: "Water - Consumed Today"
      id: water_consumed_today
      web_server_sorting_weight: '23'
    
    water_yesterday:
      name: "Water - Consumed Yesterday"
      id: water_consumed_yesterday
      web_server_sorting_weight: '24'

    water_week:
      name: "Water - Consumed Week"
      id: water_consumed_week
      web_server_sorting_weight: '25'
    
    water_month:
      name: "Water - Consumed Month"
      id: water_consumed_month
      web_server_sorting_weight: '26'

    water_year:
      name: "Water - Consumed Year"
      id: water_consumed_year
      web_server_sorting_weight: '27'

Example of output:

image

Note: “Water - Consumed Total” is the 'total_increasing" / raw sensor that just keeps on adding from day 1. I use some helpers and automations with the pulse_counter to give me another sensor that mimics the reading on the physical water meter.

For Gas consumption there’s another simiilar custom_component to do with same for gas readings.

Sensors work fine in the Energy Dashboard, avoiding the need for manually maintaining ‘utility_meters’… and with gas and water, you’ll probably start working out when kids are taking long showers.

…now if only the Energy Dashboard added support for Gas in MJ (not just m3).

How do I flip the output signal

sorry? example… from what / to?

When pin 15 is not connected to GND it is counting up , I need to reverse this

I finely got it going with the code below , just need to calibrate it

sensor:
  - platform: pulse_meter
    pin: 
      number: GPIO3
      mode: INPUT
    name: 'Water sensor pulse'
    # Sometimes the sensor keeps triggering, so we debounce the binary sensor here. Seems to be necessary to not get crazy values.
    internal_filter: 100ms
    # Not sure why/if this is needed --> seems not?
    # internal_filter_mode: PULSE
    # Flow lower than 0.5l/30s is zero
    timeout: 30s

    unit_of_measurement: 'L'
    device_class: water
#      state_class: measurement # --> `water` is not allowed to be measurement, must be total or total_increasing
    filters:
      - multiply: 0.5  # (0.5L/1 pulse)
    accuracy_decimals: 1

    total:
      unit_of_measurement: 'L'
      device_class: water
#      state_class: measurement # --> `water` is not allowed to be measurement, must be total or total_increasing
      name: 'Water sensor total'
      filters:
        - multiply: 0.5  # (0.5L/1 pulse)
      accuracy_decimals: 1

First-time ESPHome user here.

Bought a Pico W like the OP.
My meter is 1 Pulse / 5.0 Litre.

I tried to use the following however I get an error:

sensor:
  - platform: pulse_counter
    pin:
      number: GPIO7
      inverted: true
      mode:
        input: true
        pullup: true
    update_interval : 10s
    name: "pulse water"
    id: pulse_water

  - platform: pulse_meter
    pin:
      number: GPIO7
      inverted: true
      mode:
        input: true
        pullup: true
    name: "Water Pulse Meter"
    id: water_pulse_meter
    unit_of_measurement: 'l/min'
    icon: "mdi:water"
    internal_filter: 100ms
    timeout: 30s
    filters:
      - throttle: 10s
      - multiply: 5
    total:
      name: "Water Usage Total"
      id: water_meter_total
      unit_of_measurement: "m³"
      accuracy_decimals: 3
      device_class: water
      state_class: total_increasing
      filters:
        - multiply: 5

Error:

INFO ESPHome 2024.8.3
INFO Reading configuration /config/esphome/water-meter-sensor-pico-w.yaml...
Failed config

sensor.pulse_counter: [source /config/esphome/water-meter-sensor-pico-w.yaml:26]
  
  Pin 7 is used in multiple places.
  platform: pulse_counter
  pin: 
    number: 7
    inverted: True
    mode: 
      input: True
      pullup: True
      output: False
      open_drain: False
      pulldown: False
      analog: False
  update_interval: 10s
sensor.pulse_meter: [source /config/esphome/water-meter-sensor-pico-w.yaml:37]
  
  Pin 7 is used in multiple places.
  platform: pulse_meter
  pin: 
    number: 7
    inverted: True
    mode: 
      input: True
      pullup: True
      output: False
      open_drain: False
      pulldown: False
      analog: False
  name: Water Pulse Meter

Looks like it has an issue with the PIN being specified twice?
However I am using the same code as the OP.

Any help would be appreciated.