Giter VIP home page Giter VIP logo

esphome-water-meter's Introduction

ESPHome-Water-Meter

Having embarked on SESCO (Electric) Meter node to measure my house electrical consumption, this project is similarly on mission to measure and automate another important utility consumed by the house - Water (supplied here by LAKU in Sarawak) using Home Assistant & ESP Home. visitors

Project Objectives | Development | Diagrams | Bill of Materials | Code | Automations | References |

  • Power measurement and remote switch for Water Pump (Not covered here. This was just hooking up to a Sonoff POWR2 flashed with Tasmota).
  • Water consumption reporting on hourly, daily, monthly interval vs. current monthly bill reporting.
  • Notifications for anomalies or where intervention is required i.e. water supply cutoff, backwash required, leak detection.
  • Solenoid automation i.e. force natural flow when inlet pressure is sufficient to reduce power use from water pump, irrigate garden, etc.

Phase 1 : Water Flow Rate measurement, May-June 2021

I started off with a cheap and easy to buy YF-S201 Hall Effect Water Meter flow sensor. Having not doing any research beforehand - the basic idea was the meter would produce pulse outputs - applying similar pulse_counter feature from ESPHome as implemented on the Power Meter skids would give me my water flow rate readings per min/seconds and summing it up would give total water volume consumed.

Hence Phase 1a was deployed but came with challenges noted below:

  1. 1/2" connection didn't fit well with poly pipe couplers with minor drip leak observed. Reapplying thick layers of PTFE tape didn't help either so applied PVC glue, let it cure and the drip leaks eventually stopped.
  2. Flow rate pulse is characterized as Frequency (Hz) = 7.5 * Flow rate (L/min) . Implemented this in ESPHome but was struggling to see acceptable values - mostly over and beyond the meter faceplate flow rate of 1-30 L/min. Despite having learnt and worked on Field Instrumentations 10 years ago - later did I realized this water turbine meter is undersized hence the overrange readings! Sigh

Hence Phase 1b was sanctioned to resize to a bigger meter:

  1. Triggered happily the 'checkout-now' when a DN40 turbine meter recommendations showed up in Shop** .
  2. Only realized upon arrival DN40 - 1 1/2" inches is not a normal household size relative to current mains sized at DN25 - 1"!
  3. This time around - I was conscious to achieve better accuracy, metering straight line requirements must at least be demonstrated. But having to already default on the requirements with DN40 to DN25 adapter immediately upstream and downstream of the meters - I went with the approach - try first lah, revisit later (only if! where to find DN40 polypipes and couplers in town?).
  4. Meters installed horizontally at ground level.

Also included a 2 channel relay; reserved for future phase 4 to (re)deploy and upgrade water irrigation system replacing the now defunct (for more than 2 years) timer based water irrigation tap controller.

Phase 2 : Water Pressure measurement, August 2021

AliExpre** must have been reading my mind, having to advertise some pressure transmitter product recommendations. I research through finding if 4-20mA based transducers similar to ones used in my line of work would be better instead of voltage based alternatives.

4-20mA solutions are available but would be too costly for simple home use and the plugin board may need more tinkering to work with ESPHome existing libraries. Hence settled for this 5V based 0.5-4.5Vdc output , 0-174 psi transmitter.

*

Some other notes from this phase:

  1. Pressure Tx came in 1/4" - Searched for adapters at local hardware shops but yet again not a common household size except for drinking water filters connections. Ended up shipping from Semenanjung via Shopp**.

  2. NodeMCU ESP8266 comes with only 1 ADC channel and reading range of 0-3.3V; more than what the transmitter would output at upto 4.5V. Since I needed more Analogs channels I could swap for ESP32 + voltage divider circuit to bring it down to 3.3V; or use a analog to digital multiplexer - ADC1115. Went for the ADC1115 route which despite an additional board, IMO is simpler and yields better accuracy.

  3. I had no other means to verify what my water mains or pump output pressure was or had been delivering. So I ordered a manual pressure gauge and did a bench test - to map out voltage reading to pressure reading from manual gauge to plot in ESPHome curve.

    Literally a real bench test!

    The transmitters performed as specs - produced a straight line curve; though only then I realized my water pressures were no near to 60-80% range of the transmitters at max 12 bar/174 psi vs pump output at 6 bar. Again - oklah, for measuring water pressure only - not as IPF tripping initator or reading production critical Compressor Discharge Pressures (CDP) / Trunkline Export pressures!

Phase 3 : Filter Backwash automation

This is yet to commence but what gets me motivated is to find the best mechanism to drive this sand filter 3 way multiport valve; requiring step turns at (close to) 0-90-180 angles.

Currently exploring a few ideas:

  • 3d printing adapter to current valve handle - drive rotation by coupling it to servo with the enough torque value. 3d model for adapter can try to learn and scan using XboxOne camera.
  • Explore linear actuators? Current automatic window openers driven by chain can bend at angle - but can it still bend at 180? Want to explore
  • There would be no IP3X products readily available - hence a makeshift ingress protection would need to designed as well.

Ruled out:

  • Off the shelf actuators - too costly (RM500++) and is timer based - defeats the purpose to have it Smart Home IOT connected.
  • Valve couplers - Have 2 pcs ordered last year, not yet installed anywhere in the house but limited to 90degree turns and on/off mechanism with limit switch as end stoppers - No rotary encoders to do partial turns.

Phase 4 : Garden Irrigation automation

Basic concept is to drive irrigation by 12vdc valves - Not a priority for now but would want to see later if rework can be done to convert existing single zone irrgation (one master valve irrgates front and backyard) to multiple zones (at least three) - but this will require digging up and laying new pipes.

Process Flow Diagram

EasyEDA Connection diagram

**This would be my first drawing using EasyEDA - yet to master this software beyond drawing simple hookup diagrams. For illustration only.

Visual connection Diagram

**Drawn using handy old Powerpoint. Component images from the internet and are not mine.

Current cramped layout as per phase 2:

A combination of local sellers and international - mostly via Shop** and A**Express and also some local hardware stores too. Links are for sharing and verify, proceed at own risk for sellers latest validity/reputation.

Hardware

# Item Unit Price, RM Quantity Total Price, excl Shipping Remark and Link
1 Turbine Water Meter 56.20 1 pcs 56.20 DN40 1.5 Turbine Meter (YF-DN40) Flow rate : 5~200L/min
Flow Pulse: F(Hz)=(0.45xQ) +/-3%
Q=L/min 1L water= 27Pulse


2 Fittings and Poly couplers for Turbine meter ~RM10 2 each RM20 Take note of your water main line size! My incoming mains poly pipe are at DN25 while this Turbine Meter is DN40!!

Had to search hardware shops around down and landed one shop that was able to provide me with 1 1/2" to 3/4" fitting but in galvanized metal. Pair this with DN25 to 3/4" poly couplers.
3 Wiring + Weather Protector ~RM0.80 +/- 10metres RM10 For wiring - with Alarm panel Konnected project - I had plenty to spare so mostly re-use. These alarm panel comes in 4 core which is enough for the meter and transducers.


Since these cables are also not meant for sun/rain/heat - I covered these cables in 7mm corrugated PVC cables from local electrical shop. This is sample for reference.
4 Pressure sensors Transducers RM28.10 3 pcs RM84.30 EBOWAN DC 5V G1/4 Pressure Sensor Transmitter Pressure Transducer 1.2 MPa 174 PSI For Water Gas Oil

Working Voltage: 5VDC
Output Voltage: 0.5-4.5 VDC
Sensor material: Carbon steel alloy
Working Pressure Range: 0-1.2 MPa


Pressure range is 0-1.2MPa/0-12Bar/0-174 Psi with voltage output of 0.5v to 4.5v (Linear). More than enough for household at 12 bar but note that connection is 1/4"
5 Fittings and Poly couplers for pressure transmitters RM4.50 (Fittings) + RM9.00 couplers 3 sets RM40 This time another search looking at local hardware stores and couldnt locate any 1/4" to 3/4" or 1/2" couplers that I can fit to DN25 Female Poly Tee.


So search online and landed on this SUS304 1/4" to 1" fitting.
Total Hardware RM210.50 Estimate lah

Electronics

# Item Unit Price, RM Quantity Total Price, excl Shipping Remark and Link
1 ESP8286/ESP32 with baseboard RM 16.20+ RM 56.20 1 set 72.40 ESP8286 or ESP32 choice is yours.

My curent setup uses NodeMCU Lolin 8286.
Make sure to get baseboard like this which makes power supply input, prototyping and assembling easier.
2 PSU RM45 1 unit RM45.00 I went for a compact 240vac to 12vdc PSU converter purchased from local electrical shop. If not mistaken rated for 3A. Reason for 12vdc instead of 5vdc was considering future valve actuators that I may put in.

Sample online here
3 ADC converter - ADS1115 16-bit Analog to Digital Converter RM23.80 1 unit RM23.80 For Pressure Transmitters analog to digital converter. Be it for ESP8286 (comes with only 1 ADC channel) or ESP32 (multiple channel available) - voltage output range (0.5-4.5v) from pressure transmitters still would have required voltage divider circuit.
Using ADS1115 provides additional 4 ADC channels for ESP8266 via I2C.

Purchased online from here.
4 Junction Box RM15.00 1 RM15.00 Local hardware store - see your own requirements and sizing.
5 Fittings and Poly couplers for pressure transmitters RM4.50 (Fittings) + RM9.00 couplers 3 sets RM40 This time another search looking at local hardware stores and couldnt locate any 1/4" to 3/4" or 1/2" couplers that I can fit to DN25 Female Poly Tee.


So search online and landed on this SUS304 1/4" to 1" fitting.
Total Electronics RM196.20 Buy local electrical store where possible.

Other consumables - terminal blocks, cable glands, dupont jumper wires (male/female), PCB Spacer

Download code from repo here.

substitutions:
  name: diy-watermeter
  friendly_name: Diy Watermeter
  
esphome:
  name: diy-watermeter
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: !secret wifi
  password: !secret wifi_pass

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

captive_portal:

# esp8266 gpio layout
# D0
# D1 - I2C - ADS1115 SCL / Former pulse counter
# D2 - I2C - ADS1115 SDA
  # ADS1115
  # Channel A0 - Incoming
  # Channel A1 - After Filter (Tank)
  # Channel A2 - Household
  # Channel A3 - Spare
# D3 
# D4
# D5 - Water Pulse Counter / Former Relay
# D6 - Relay
# D7 - Relay
# D8
# RX
# TX
# A0

i2c:
  sda: D2
  scl: D1
  scan: true
  id: bus_a
  
ads1115:
  - address: 0x48
  
sensor:
  - platform: ads1115
    multiplexer: 'A0_GND'
    gain: 6.144 
    name: "A0 Voltage - Incoming Pressure Transmitter"
    device_class: voltage
    state_class: "measurement"
    update_interval: 30s
    
  - platform: ads1115
    multiplexer: 'A0_GND'
    gain: 6.144 
    name: "Main Water pressure - Bar"
    id: main_water_supply_bar
    device_class: pressure
    state_class: "measurement"
    icon: "mdi:gauge"
    accuracy_decimals: 2
    filters:
      - calibrate_linear:
            - 0.633 -> 0.34  
            - 0.862 -> 1.03
            - 1.11 -> 1.72
            - 1.47 -> 2.75
            - 1.63 -> 3.47
            - 2.02 -> 4.48
            - 2.01 -> 4.68
    unit_of_measurement: bar
    update_interval: 30s    
    
  - platform: ads1115
    multiplexer: 'A0_GND'
    gain: 6.144 
    name: "Main Water pressure - Psi"
    id: main_water_supply_psi
    device_class: pressure
    state_class: "measurement"
    icon: "mdi:gauge"
    accuracy_decimals: 2
    filters:
      - calibrate_linear:
            - 0.633 -> 5.0  
            - 0.862 -> 15.0
            - 1.11 -> 25.0
            - 1.47 -> 40.0
            - 1.63 -> 50.0
            - 2.02 -> 65.0
            - 2.01 -> 68.0
    unit_of_measurement: psi
    update_interval: 30s    
    
  - platform: ads1115
    multiplexer: 'A1_GND'
    gain: 6.144 
    name: "A1 Voltage - Tank Transmitter"
    device_class: voltage
    state_class: "measurement"
    id: a1_voltage
    update_interval: 30s    
    
    
  - platform: ads1115
    multiplexer: 'A1_GND'
    gain: 6.144 
    name: "Tank Water supply pressure - Bar"
    id: tank_water_supply_bar
    device_class: pressure
    state_class: "measurement"
    icon: "mdi:gauge"
    accuracy_decimals: 2
    filters:
      - calibrate_linear:
            - 0.633 -> 0.34  
            - 0.862 -> 1.03
            - 1.11 -> 1.72
            - 1.47 -> 2.75
            - 1.63 -> 3.47
            - 2.02 -> 4.48
            - 2.01 -> 4.68
    unit_of_measurement: bar
    update_interval: 30s    
    
  - platform: ads1115
    multiplexer: 'A1_GND'
    gain: 6.144 
    name: "Tank Water supply pressure - Psi"
    id: tank_water_supply_psi
    device_class: pressure
    state_class: "measurement"
    icon: "mdi:gauge"
    accuracy_decimals: 2
    filters:
      - calibrate_linear:
            - 0.633 -> 5.0  
            - 0.862 -> 15.0
            - 1.11 -> 25.0
            - 1.47 -> 40.0
            - 1.63 -> 50.0
            - 2.02 -> 65.0
            - 2.01 -> 68.0
    unit_of_measurement: psi
    update_interval: 30s    
    
    
  - platform: ads1115
    multiplexer: 'A2_GND'
    gain: 6.144 
    name: "A2 Voltage - Household Transmitter"
    device_class: voltage
    state_class: "measurement"
    id: a2_voltage
    update_interval: 30s
    
  - platform: ads1115
    multiplexer: 'A2_GND'
    gain: 6.144 
    name: "Household supply water pressure - Bar"
    id: household_water_supply_bar
    device_class: pressure
    state_class: "measurement"
    icon: "mdi:gauge"
    accuracy_decimals: 2
    filters:
      - calibrate_linear:
            - 0.633 -> 0.34  
            - 0.862 -> 1.03
            - 1.11 -> 1.72
            - 1.47 -> 2.75
            - 1.63 -> 3.47
            - 2.02 -> 4.48
            - 2.01 -> 4.68
    unit_of_measurement: bar
    update_interval: 30s  
    
  - platform: ads1115
    multiplexer: 'A2_GND'
    gain: 6.144 
    name: "Household supply water pressure - Psi"
    id: household_water_supply_psi
    device_class: pressure
    state_class: "measurement"
    icon: "mdi:gauge"
    accuracy_decimals: 2
    filters:
      - calibrate_linear:
            - 0.633 -> 5.0  
            - 0.862 -> 15.0
            - 1.11 -> 25.0
            - 1.47 -> 40.0
            - 1.63 -> 50.0
            - 2.02 -> 65.0
            - 2.01 -> 68.0
    unit_of_measurement: psi
    update_interval: 30s    

  - platform: ads1115
    multiplexer: 'A3_GND'
    gain: 6.144 
    name: "A3 - Voltage Ref"
    device_class: voltage
    state_class: "measurement"
    id: a3_voltage
    update_interval: 30s
    

  - platform: template
    name: "Water Filter DeltaP - bar"
    device_class: pressure
    state_class: "measurement"
    lambda: return ( id(main_water_supply_bar).state - id(tank_water_supply_bar).state );
    unit_of_measurement: bar
    update_interval: 30s    
    
  - platform: template
    name: "Water Filter DeltaP - psi"
    device_class: pressure
    state_class: "measurement"
    lambda: return ( id(main_water_supply_psi).state - id(tank_water_supply_psi).state );
    unit_of_measurement: psi
    update_interval: 30s    

  - platform: pulse_counter
    pin: D5
    unit_of_measurement: 'L/min'
    accuracy_decimals: 1
    update_interval: 60s
    name: 'Water Meter House'
    filters:
    - lambda: return (x / 27.0);  
    
    total:
      unit_of_measurement: 'L'
      name: 'Water Meter Total'
      accuracy_decimals: 1
      filters:
      - lambda: return (x / 27.0);

  - platform: wifi_signal
    name: "${friendly_name} Wifi "
    update_interval: 60s

switch:
  - platform: gpio
    pin: D6
    name: "Backyard Sprinkler Valve (NC)"  
    id: backyardsprinkler_valve    

  - platform: gpio
    pin: D7
    name: "Water Main Natural Flow to House Valve (NO)"  
    id: watermain_naturalflow_valve 

  - platform: restart
    name: "${friendly_name} Restart"
    

text_sensor:
  - platform: version
    name: ${friendly_name} ESPHome Version
    

# Enable logging
logger:

web_server:
  port: 80

# Enable Home Assistant API
api:
  reboot_timeout : 0s
    
ota:

Work in progress. No automations yet as still in data gathering. Some early ideas to be implemented in Node Red:

  1. Alert if inlet pressure goes to 0 to indicate water supply cutoff. Evaluate only if flow meter is 0 (not flowing).
  2. Perform household minute leak check during quiet hours (similar to Pressure Leak check sequence during Gas Turbine startup hahaha!). Record pressure, and compare how many psi dropped after interval, compare against acceptable leakage. Abort test if flow meter register reading.
  3. Backwash - evaluate filter dP if above defined threshold and evaluate only during no flow conditions. Store and compare max DP recorded over days/weeks to inform if dP is on increasing trend.

Current observations:

  • Household supply water pressure at no flow would be higher than Mains water and Tank Water supply (after filter). Can attribute this to the static head to the highest water point in the house.
  1. Home Assistant Forum - Using ESPHome to build water flow rate meter

esphome-water-meter's People

Contributors

anas-ivs 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

Watchers

 avatar  avatar  avatar

esphome-water-meter's Issues

EspHome and flow meter

How many flow meters can I connect to ESPHome ? I need more than a few and connect all of them to ESPHome, do you have experience with that?
Many thanks

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.