Code Monkey home page Code Monkey logo

esphome-water-meter's Introduction

ESPHome Water Meter

Read this in other languages: French

Photo du boitier contenant l'électronique

Presentation

If you have a water meter (Sensu R-315 for my part), it may have an indicator allowing you to know the current consumption fairly accurately. Its operation is quite simple, a disc (see photo) visible in the dial of the meter rotates at a speed proportional to the flow of circulating water. It is designed so that each complete revolution corresponds to 1L of water.

The disc consists of a reflective part and a matt part (see photo below), so, by using an adapted sensor, it is possible to detect the rotation of the disc and thus to deduce the current consumption of your meter.

Water meter photo

In order to detect the rotation of the disk, I used a sensor TCRT5000 with an IR emitting LED and a photo-transistor in the same case. It is possible to find these sensors on stand-alone boards with an operational amplifier and an adjustable resistor for a very interesting price.

I glued the sensor on both sides with a very approximate method but it works very well, however I plan to make a 3D printable part to facilitate the installation.

Photo of the meter with the sensor placed on it

Features

Consumption measurements

  • Daily consumption
  • Weekly consumption
  • Monthly consumption
  • Annual consumption
  • Primary / secondary consumption: Meters that can be reset to 0 at any time to perform any kind of measurement.
  • Current consumption: Indicates the instantaneous consumption.
  • Last consumption: Indicates the last consumption (the measurement continues as long as the meter is running without interruption for more than 5 minutes).

Updates

2024-01-15

  • Updated using pulse_meter integration (used for several months with much better accuracy)
  • Removed parts not directly related to water consumption measurement (led, temperature measurement)
  • Having changed my meter, I no longer intend to designate a suitable support for the Sensu R-315 meter.

Setup

First, you need to set the pulse_gpio used as input:

substitutions:
  name: watermeter
  friendly_name: "Water meter"
  pulse_gpio: GPIO18

Operation

The operation is quite simple and the most important YAML part is shown below:

binary_sensor:
  # TCRT5000 pulse counter
  - platform: gpio
    id: water_pulse
    pin:
      number: $pulse_gpio
      allow_other_uses: true
    internal: true
    filters:
       - delayed_on_off: 50ms
       - lambda: |-
          id(main_counter_pulses) += x;
          id(secondary_counter_pulses) += x;
          id(daily_counter_pulses) += x;
          id(weekly_counter_pulses) += x;
          id(monthly_counter_pulses) += x;
          id(yearly_counter_pulses) += x;
          id(event_quantity) += x;
          return x;
    on_state:
       - script.execute: publish_states

A digital sensor is declared and uses the digital input/output 18 on which the TCRT5000 is connected.

A filter allows to suppress parasitic pulses coming from the sensor if its state is not defined during more than 50 milli-seconds.

Once the filter is passed, we land in the lambda or C code is executed and which simply consists in incrementing the global defined above.

Another part declares a pulse counter type sensor which allows to know the instantaneous consumption.

sensor:
  - platform: pulse_meter
    id: water_pulse_counter
    name: "${friendly_name} water consumption"
    pin:
      number: $pulse_gpio
      allow_other_uses: true
    internal_filter: 100ms
    unit_of_measurement: "L/min"
    accuracy_decimals: 2
    timeout: 30s
    icon: "mdi:water"

Files

  • watermeter.yaml: The ESPHome configuration file
  • network.yaml: Your network information
  • secrets.yaml: The secret information about your network.

esphome-water-meter's People

Contributors

hugokernel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esphome-water-meter's Issues

Wiring diagram ESP and sensor

Hi, could you please provide me the wiring diagram?
Especially the TRCT5000 sensor to ESP8266
I would like to use pin A0 to display the battery voltage. ESP will be powered by a battery and a solar panel.
Thanks

Wich counter to use and how to set it

Hi,
My physical water counter gives me the consumption 777365Liters
I'd like one counter to be equal to this number in order to check my measurements
Which one should I use (main or primary)
And how can i set it please ?
Thanks

Gr8 work

Had to just thank you for this great work. The setup is simple of course but they way you implented the software is great! Merci.
BTW, for myself I added the new measurement/total_increasing Esphome state classes (preparing for the inclusion of 'water' in the energy dashboard). Also, I used the utility meter functionality to calculate hourly, daily, etc. counts instead.

1 question though: why do you multiply the pulse rate?

filters: # Divide by 60 - multiply: 0.0167

Pulse error

I have a problem the sensor gives me a correct l/min value followed immediately by an incorrect one which means that only the incorrect value is displayed

Screenshot_2024-04-27-21-53-05-531_io homeassistant companion android

Sensor Placement and distance

Hi,

first of all thank you for your work. Unfortunately I am not able to get this system to work properly on my Sensus 620 watermeter.
Is there a specific place on the rotary disc to place the sensor? At what distance do i have to place it?

Currently my situation is like this:

  1. Sensor placed slightly offcenter so that the metal discs leaves the Field of view completely during a rotation.
  2. Distance to the surface ~1mm for the middle part, 2,5mm for the leds
  3. The indicator LED on the sensor is either completely off all the time (Potentionmeter turned all the way down), or completely on (Potentiometer turned very slightly.

It is therefore not picking up pulses at all.

Thank you very much for your help and happy new year.

Counter increment at boot

I have modified your code and implemented my two counters, it seams to work well, thank for your work.

But i have noticed something : if i reboot the esp8266, the main counters (i have two, one for cold water, one for hot water) are incremented by 1.

I'd like them not to be incremented
I don't use the same kind of sensor, I use reed sensors (only two wires, dry contact), so i declare their pins input pull-up, could that be the cause ?

I mean because pin goes high when declared, so it increments the counter. But I would imagine nothing happens before pin definition are finished (as in Arduino void setup() )
Thanks again

Retour d'expérience

Bonjour
Je dispose de deux compteurs actuellement monitorés sous domoticz (froid et chaud)
J'aimerais connaître votre retour d'expérience car je passe sous home assistant et j'hésite à faire mes mesures sous esp home ou espeasy
Les mesures sont elles fiables ? Les avez vous comparées aux indications sur le compteur ?
Pensez vous qu'un seul wemos D1 mini puisse gérer les deux voies de mesure sans qu'un top sur un compteur fasse louper un top sur l'autre compteur ?
Merci

Switch or button

In code we can see....

switch:
  - platform: template
    name: "${friendly_name} reset main counter **button**"
    icon: "mdi:restart"
    turn_on_action:
      - script.execute: reset_main_counter

  - platform: template
    name: "${friendly_name} reset secondary counter **button**"
    icon: "mdi:restart"
    turn_on_action:
      - script.execute: reset_secondary_counter

name is button, but you use switch :)

this looks better

button:
  - platform: template
    name: "reset main counter button"
    icon: "mdi:restart"
    on_press:
      - script.execute: reset_main_counter

  - platform: template
    name: "${friendly_name} reset secondary counter **button**"
    icon: "mdi:restart"
    on_press:
      - script.execute: reset_secondary_counter

in my option restart should be button too

  - platform: restart
    name: "restart"

edit: Add code blocks

Compilation error with ESPHome version 2024.5.4

When I compile the 'watermeter.yaml' file in the latest version of ESPHome (version 2024.5.4) I get the following error message:

Compiling .pioenvs/watermeter/lib67b/ESP8266WiFi/ESP8266WiFiSTA-WPS.cpp.o
/config/esphome/watermeter.yaml: In lambda function:
/config/esphome/watermeter.yaml:322:63: error: 'api_apiserver' was not declared in this scope; did you mean 'api_apiserver_id'?
  322 |                   api = new api::HomeAssistantServiceCallAction<>(api_apiserver, true);
      |                                                               ^~~~~~~~~~~~~
      |                                                               api_apiserver_id
*** [.pioenvs/watermeter/src/main.cpp.o] Error 1

When I replace:

api = new api::HomeAssistantServiceCallAction<>(api_apiserver, true);

by

api = new api::HomeAssistantServiceCallAction<>(api_apiserver_id, true);

everything compiles again without issues.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.