Smart Water Monitoring System Utilizing MQTT and Water Softener IQua API

by suriono in Circuits > Sensors

93 Views, 0 Favorites, 0 Comments

Smart Water Monitoring System Utilizing MQTT and Water Softener IQua API

Demonstrating a home water monitoring system leveraging Iqua Cloud and MQTT.
FV9CF5FMBZLGJJM.jpg
watersoftener.png

I recently discovered a slow leak in one of my house's toilets purely by chance. That unexpected find sparked my curiosity about water leak detection. Intrigued, I started researching online to see what solutions others had devised and how I could integrate them into my existing MQTT project. Eventually, I developed a solution by leveraging the water softener monitoring system and scaling capability of MQTT system.


First of all, despite the water softener monitoring system comes with an app (click the link) that displays water usage, sends alerts for significant leaks, and a button to shut the water off, but it lacks the capability to detect slow leaks.


Secondly, for potential substantial leaks, alerts are triggered when water consumption is greater than 300 gallons. However, these alerts have been false alarms, frequently activated by routine activities like multiple laundry cycles in a single day. Additionally, the alerts arrive one day late, making timely response impossible. To better assess water usage and react swiftly in the event of a major leak, I need more control over the data and the ability to shut off the water immediately and automatically when nobody at home for instance.


Features:

  1. Show real-time water flow in gallons per minute.
  2. Track daily water usage in gallons.
  3. Monitor continuous hourly water consumption:
  4. If usage steadily increases every hour over the past 24 hours, an email alert is sent, indicating a possible slow leak in the house.
  5. Future enhancement:
  6. Implement automatic water shut-off based on specific conditions, such as detecting water usage when the entire family is away.

Supplies

20250616_180956.jpg
20250616_180945.jpg
watersoftener.png
  1. Since this project incorporates my other MQTT project, the remaining supplies are taken from my other Instructible project: https://www.instructables.com/Freezer-Door-Alarm-System-Using-MQTT-and-ESP8266/
  2. Any water softener with iQua Wi-Fi technology, or you may already have it, such as:
  3. Morton® Demand-Control Wi-Fi 45,000 Grain Water Softener.
  4. Rheem 42,000 Grain Preferred Platinum Wi-Fi Enabled Smart Water Softener
  5. Follow the instruction of your Wi-Fi enabled water softener to download the iQua app and obtain the username and password. You will need this information for the Python password.h code later on in this tutorial.
  6. Optional: see the 3rd picture in this section, install the remote water shut-off valve for your water softener. These valves are available at stores like Home Depot or Menards, typically priced around $125. It allows the iQua app to remotely shut the water off or write a Python code for automatic shut-off.
  7. Home Depot: https://www.homedepot.com/p/Rheem-Preferred-Series-Remote-Water-Shut-Off-Valve-7388598/316362390#overlay
  8. Menards: https://www.menards.com/main/plumbing/water-filtration-softeners/water-softeners-cleaners/morton-reg-motorized-water-shut-off-valve/7379785/p-1562653716876-c-8682.htm?exp=false

Install MQTT Server and Display Module

  1. Follow my Instructable to set up MQTT on a Raspberry Pi or any single board computer (I am using a cheaper variant of Raspberry Pi: AML-S905X-C), using the this link.
  2. Follow my instructible to set up the display modules and Wemos microcontroller, using the provided link. This link shows how to build refrigerator alarms but it applies to any MQTT system. While this project can be built as a standalone system, I will also offer a tutorial on integrating it with my refrigerator door alarm. Given MQTT's high scalability, it will become clear how a water monitoring system could be developed as a standalone solution.

Upload the Arduino Code

20250610_230855.jpg
  1. This is a modified version from the refrigerators' doors alarm system from my other project, there is no change to the hardware: https://www.instructables.com/Freezer-Door-Alarm-System-Using-MQTT-and-ESP8266/. To make room for this project, the fonts for refrigerator system have been reduced and rearranged.
  2. Upload the following Arduino code to include this water monitoring system: https://github.com/suriono/MyArduino/tree/master/Mqtt%20Home/Mqtt_Doors/Display_3_Doors_Water
  3. As shown on the picture, the left side are the refrigerator doors system, and this project water monitoring on the right side.

Python Code and Package Installation

  1. In a Raspberry Pi terminal, install py_ecowater and mqtt python package libraries:
  2. pip install py_ecowater: the library to access the AWS IoT water softener Cloud server.
  3. pip install paho-mqtt: the library to publish water monitoring data to MQTT server.
  4. Download the Python code from my GitHub: https://github.com/suriono/MyArduino/blob/master/Mqtt%20Home/Mqtt_Doors/Display_3_Doors_Water/water_softener.py
  5. The code does not include password.h for security reason. It contains the credentials to my personal MQTT and the water Cloud server. You will need to create your own password.h file and substitute the credential information as shown below.
  6. The "mqtt_credentials" are the same as from the MQTT server tutorial: https://www.instructables.com/Installing-MQTT-BrokerMosquitto-and-Pi-Hole-on-AML/
  7. The "ecowater_credentials" are the same as the iQua app from the water softener.
mqtt_credentials = {
"username": "xx", "password": "xxxxxxxxx"
}

ecowater_credentials = {
"username": 'xxxxxxxxxx', "password": 'xxxxxxxxxxxxxxx'
}
  1. On the bottom of the Python code:
  2. The "interval=120" for example, specifies the data acquisition frequency from the iQua Cloud (AWS IoT) in seconds. The server has the limit of 1,000 acquisitions per day or an average of 86.4 seconds, it is crucial to not exceed this limit otherwise your account will be suspended by the server.
  3. The "retention" is how long the series of data are retained is set to 100,000 seconds. 86400 seconds = 24 hours, higher number will allow longer retention time if desirable. Feel free to adjust these two values to your preference.
  4. water_obj = Water_Monitor(interval=120)
  5. water_obj.loop_Monitoring(retention=10000, leak_period=3600).

Run the Python Code in the Background

  1. Using Putty on a terminal run the following command:
  2. nohup python3 water-softener.py & disown

The python code will run in the background and you can safely close the SSH terminal.

Analysis, Email Alert, and MQTT Troubleshooting App

Screenshot_20250617_185843_IoT MQTT Panel.jpg
  1. From the step no. 3, the "leak_period=3600" refers to the interval used to check for changes in water usage over time—in this case, every 3600 seconds (or hourly). As an example, if the water usage in the past 5 hours are 110, 111, 111, 113, 116 gallons, measured every 3600 seconds, notice the water usage increases only three hours consecutively. In this example, the "Continuous Flow" indicator shown in Step 2 at the bottom right will display 3.0.
  2. If there is a slow leak, with the "retention" is set for 24 hours, the displayed "Continuous Flow" should show as 24 hours. When this happens it will send email to myself:
  3. The following is the part of the Arduino code that send email:
  4. if ( int(tmp) == WATER_ALERT_CONTINUOUS_HOURS) {
  5. smtp_send("\nATTENTION: Potential continuous water leak\n"); // Email after continuous water flow
  6. }
  7. Any MQTT app can be used to troubleshoot this project. I use IoT MQTT Panel app. The picture in this section shows how the output looks like.

Potential Future Improvement

Any recommendations or ideas are welcome. I may continue refining the water leak alarm algorithm and the automatic water shut-off feature—especially for scenarios like being out of town, when no water usage is expected.