Water Meter sensor - Australia, Victoria

@jkerekes look here for example: myHomeAssistant/esphome/kincony-kc868-a16.yaml at b7c47efcda4563c3afe161639b87d633f2b8c137 · Roving-Ronin/myHomeAssistant · GitHub

Note the line…

allow_other_uses: true

Just an update confirming that those switches work a treat - I also have oodles left-over if anyone wants some.
Some other notes:

  • That size reed switch is a near-perfect fit, and the leads both coming out of the same end makes it much easier to wire going into the meter’s receptacle.
  • My meter was 5L/pulse too, but the magnet dial appears to be about 1/3 ON, and 2/3 OFF, so you could (in theory) get better precision by counting rising and falling edges with appropriate weights (or just do 2.5L each direction approximately).
  • The Zigbee switch sensor is working great
  • Zipties aren’t the best way to mount the sensor box to the meter, but it’s doing the trick for now :woozy_face:
  • To get the open/close sensor to work as a cumulative meter in HASS, I added an automation that increments a counter helper on the state changes, and then added a template helper that multiplies the pulse count by the pulse weight to get total litres of usage.




1 Like

This is awesome - where abouts are you located? I’d be keen to buy a couple of the sensors off of you, but may not be worth the postage to the ACT.

Thanks!

I tried this but the battery on the Aqara door & window sensor died inside of a week.

How did you modify the solar panel to work

VIC - they’re pretty small, reckon I could squeeze them in a letter envelope. Ping me your address if you’re keen!

1 Like

It’s a bit of a hack-job, but does the trick. Essentially I just removed the series resistor (R1) that was in line with the LEDs, which stops them running at night, and then hardwired a 3v3 switching regulator to the switched power supply, which then powers the window sensor PCB.
For the sensor, I just desoldered the magnetic switch (Q1), followed the traces to determine which pin is the input to the microcontroller, and soldered a header on, which I then routed to an screw connector mounted externally, which the reed switch is connected to.

(it’s snug, but it fits!)

I’ve sent you a DM with my details, thanks! :slight_smile:

I just wanted to add my variation on this.
I ended up using an Seeed Studio Xiao ESP32C3 board and a hall effect transistor from Jaycar that was connected to an ADC connection. It uses ESPHome software.
The Hall Effect transistor provides a continuous reading that changes as the magnet in the water meter gets closer and then moves away, you can set some upper and lower limits for the ADC value (with hysteresis) to give you the ‘count’ value for each (in my case) 10 L.
The hall effect transistor fits into the small hole the same way the reed switch does but of course requires a cable with 3 leads. As the water meter is just outside my garage, I can run a cable with 5V to power it. Therefore the whole of the electronics fits into a small 3D printed case that I attach to the water pipe.

The YAML file is

external_components:
  - source: 
      type: local
      path: /config/My_Components
    components: [my_pulse_counter]

sensor:
  - platform: adc
    pin: GPIO2
    name: "Water Meter Reading"
    update_interval: 1s
    raw: True
    device_class: water
    id: "water_meter_reading"
    attenuation: 12db

binary_sensor:
  - platform: analog_threshold
    name: "Water Meter Threshold"
    id: water_meter_threshold
    sensor_id: water_meter_reading
    threshold:
      upper: 2500
      lower: 2300


my_pulse_counter:
    id: "water_pulse_count"
    sensor_id: water_meter_threshold
    name: "Water Pulse Count"

and the external code referenced is (.cpp then .h and finally init.py):

#include "my_pulse_counter.h"
#include "esphome/core/log.h"

namespace esphome {
namespace my_pulse_counter {

static const char *const TAG = "my_pulse_counter";

const char *const EDGE_MODE_TO_STRING[] = {"DISABLE", "INCREMENT", "DECREMENT"};

void MyPulseCounterSensor::set_sensor( binary_sensor::BinarySensor *target_sensor)
{
    this->sensor_ = target_sensor;
    this->sensor_->add_on_state_callback([this](float sensor_value) {
        if( !std::isnan( sensor_value)) {
            if( this->last_state_ != sensor_value)
            {
                if( sensor_value > 0)
                {
                    this->current_total_++;
                    this->publish_state( this->current_total_);
                }
                this->last_state_ = sensor_value;
            }
        }
    });
}


void MyPulseCounterSensor::setup()
{
  ESP_LOGCONFIG(TAG, "Setting up pulse counter '%s'...", this->name_.c_str());
  this->current_total_ = 0;
  this->last_state_ = 0;
}

void MyPulseCounterSensor::set_total_pulses(uint32_t pulses)
{
  this->current_total_ = pulses;
  this->publish_state(pulses);
}

void MyPulseCounterSensor::dump_config()
{
  LOG_SENSOR("", "Pulse Counter", this);
  LOG_UPDATE_INTERVAL(this);
}

void MyPulseCounterSensor::update()
{
}

}  // namespace my_pulse_counter
}  // namespace esphome
#pragma once

#include "esphome/core/component.h"
#include "esphome/core/hal.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/binary_sensor/binary_sensor.h"


namespace esphome {
namespace my_pulse_counter {

using pulse_counter_t = int32_t;


class MyPulseCounterSensor : public sensor::Sensor, public PollingComponent {
 public:
  void set_sensor( binary_sensor::BinarySensor *target_sensor);
  void set_total_pulses(uint32_t pulses);

  /// Unit of measurement is "pulses/min".
  void setup() override;
  void update() override;
  float get_setup_priority() const override { return setup_priority::DATA; }
  void dump_config() override;

 protected:
  binary_sensor::BinarySensor *sensor_{nullptr};
  uint8_t last_state_;
  uint32_t current_total_{0};
};

}  // namespace my_pulse_counter
}  // namespace esphome
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import binary_sensor, sensor
from esphome.const import (
#    CONF_COUNT_MODE,
#    CONF_FALLING_EDGE,
#    CONF_ID,
#    CONF_RISING_EDGE,
#    CONF_NUMBER,
    CONF_SENSOR_ID,
#    CONF_TOTAL,
    ICON_PULSE,
    STATE_CLASS_MEASUREMENT,
#    STATE_CLASS_TOTAL_INCREASING,
#    UNIT_PULSES_PER_MINUTE,
#    UNIT_PULSES,
#    UNIT_COUNTS_PER_CUBIC_METER,
    UNIT_COUNTS_PER_CUBIC_CENTIMETER,
    UNIT_CUBIC_METER,
)
from esphome.core import CORE

pulse_counter_ns = cg.esphome_ns.namespace("my_pulse_counter")
PulseCounterCountMode = pulse_counter_ns.enum("MyPulseCounterCountMode")

MyPulseCounterSensor = pulse_counter_ns.class_(
    "MyPulseCounterSensor", sensor.Sensor, cg.PollingComponent
)


CONFIG_SCHEMA = cv.All(
    sensor.sensor_schema(
        MyPulseCounterSensor,
#        unit_of_measurement=UNIT_PULSES_PER_MINUTE,
        unit_of_measurement=UNIT_COUNTS_PER_CUBIC_CENTIMETER,
        icon=ICON_PULSE,
        accuracy_decimals=2,
        state_class=STATE_CLASS_MEASUREMENT,
    )
    .extend(
        {
            cv.Required(CONF_SENSOR_ID): cv.use_id(binary_sensor.BinarySensor),
        },
    )
    .extend(cv.polling_component_schema("60s")),
)


async def to_code(config):
    var = await sensor.new_sensor(config)
    await cg.register_component( var, config)
    sens = await cg.get_variable( config[CONF_SENSOR_ID])
    cg.add(var.set_sensor(sens))

I also use basically the same thing to monitor my gas meter - there is a place where the hall effect transistor can fit into the bottom on the meter and it also works in exactly the same way as the water meter.
(The code is heavily based on various examples in the ESPHome documentation - any bad coding practices are my own!!!).
Susan

Hey, I’m not too sure how to message you directly, but can you message me so I can send my address? I’ll send you a few dollars to pay for it and postage!

G’day all. Have just installed a Smart Gateways NL water meter sensor which, 10 days in, works really well for my WA Water Corp meter here in Perth. It is a ESP-based gateway with a proximity sensor. Nothing flash but it worked out of the box. The sensor cable is lightly buried from the water meter to the garage where the ESP gateway is mounted, under cover.

The one snag is after 8 perfectly accurate days, meaning HA consumption = physical meter consumption, the sensor went nuts and randomly added about 2,200L over an hour, while the physical meter recorded 4L of consumption. Sensor has not been physically moved for the past week and I had no water being consumed during the period.

In the sensors that you use in your setup, have you had situations where the sensor randomly sends pulses on its own? If yes, how often have you had this occur and did you find any triggers for this? Wanting to see if there is some pattern to this or if this simply needs to be declared a “technical Act of God”!

Any input would be much appreciated, thanks!

Were you watching the 2,200L being added over the hour or just saw later that it had jumped? Also did it jump in 1 step or more?
The reason I ask is that restarting the HA and not setting up the sensors correctly can make the ‘daily meter’ readings jump by whatever the total was from the monitored sensor. (That happened to me!!!)
Susan

I was planning to setup something myself, then last week was notified that my water meter here in Melb was going to be replaced by a ‘smart meter’. So have put my plans on hold for now - once the meter is replaced I’ll see if it is possible to get anything from it directly (unlikely as I believe the meters they are installing use the mobile network), or (more likely) if it has to be accessed via the supplier portal.

From other posts, people asking for API type access to these systems have found their user accounts permanently locked out of their water providers portal.

IMHO your probably better off long term looking to get your own smart water meter installed (on ‘your side’ of the boundary). With an RS485 (Modbus) meter you could connect it to an ESP32 and also get live usage data and flow rate data.

Something like this: Smart Residential Ultrasonic Water Meter Wireless Domestic Water Meter Manufacturers - Wholesale Smart Residential Ultrasonic Water Meter Wireless Domestic Water Meter - SH Meters

Thanks for responding Susan!

I saw the jump after the readings stabilised, then went to investigate what happened. There was no water consumption and no HA restart before and after the jump. The sharp fall after 1800 was my re-calibrating the utility_meter to remove the total spike.

Have not physically touched the sensors since installation 8 days prior. The sensor has also behaved normally since the spike, coming on 3 days now.

Looked like a really nice water consumption pattern for a pool or spa - if only I had one!

Ouch. Thanks for the warning! Ok, maybe can do something like screen scraping. Not a huge fan of that, but definitely nothing wrong with it from a legal standpoint as long as you keep the requests within a reasonable number

Wondering if anyone has installed a meter like this and can help share experience, cost etc?

Do any of your neighbours have one??? :upside_down_face:
Susan

Not that I can see a km around me!