JoJo Tank Water Level Monitor – Home Assistant and ESPHome
I’ve been utilizing Home Assistant for a while now, and as part of this journey, I’ve integrated ESPHome with NodeMCU and compatible sensors. This integration led me to explore a project particularly relevant in South Africa, where I reside – monitoring the water level in my JoJo tank, a common term used locally for reserve water tanks.
In my suburban area, the water pressure is less than ideal. To address this, I’ve installed a 0.75kW booster pump on my water tank. This setup not only keeps the tank consistently filled (barring any municipal water supply issues) but also serves my home and garden irrigation needs. The system is designed to operate under normal pressure for most uses, but for applications requiring higher pressure, such as showers and baths, I’ve incorporated a Smart Switch. This switch, along with button cards on my Home Assistant dashboard, activates the pump (connected to a Sonoff POW Elite 16A Smart Power Meter Switch ), ensuring an increased water pressure supply from the tank to the house.
Given this setup, the water levels in the tank are subject to frequent changes. It’s crucial to be alerted when levels are low, especially during times when municipal water is unavailable, to avoid completely depleting the tank. Personally, I find it engaging to track the water usage and levels in the tank using Grafana.
To achieve this, I’ve employed an ultrasonic sensor attached to an ESP32 on my water tank. This sensor feeds data into Home Assistant, creating an entity that reflects the water level. While this might sound straightforward, it’s important to note that the process involves some intricate calculations and conversions. The ultrasonic sensor only measures the distance between itself and the water surface, so these data points need to be accurately translated to reflect the actual water volume.
To start off, the below components are required:
- 1x ESP-32S Development Board WiFi+Bluetooth
- 1x HC-SR04 ultrasonic sensor
- 4x Female to Female Breadboard Jumpers – 40Pcs 20CM (you will only need 4, but good to have spare of these jumper cables)
- 1x Sonoff IP66 Waterproof Junction Box
- 1x Micro USB cable (HAMA is my brand of choice)
- 1x USB power supply
Wiring Diagram for ESP32 and HC-SR04 sensor:
This project is tailored for those who have a foundational understanding of Home Assistant and ESPHome, as it was designed specifically for my personal Home Assistant setup. As of now, I haven’t developed any Arduino IDE code for this initiative. My approach for all ESP32 projects, including this one, involves the exclusive use of Home Assistant and ESPHome.
Below, I will share the ESPHome code that I’ve utilized for this project, aptly named “Jojo-Echo”. Please remember to input your own WiFi details and other necessary configurations into the code. It’s also crucial to ensure that your wiring corresponds correctly to the GPIO pins as defined in the code. This alignment is essential for the successful operation of the project.
esphome: name: jojo-echo platform: ESP32 board: esp32dev # Enable logging logger: # Enable Home Assistant API api: ota: password: "xxxxxxxxxxxx" wifi: ssid: "Your WiFi SSID" password: "Your WiFi Password" # Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "JoJo-Echo Fallback Hotspot" password: "Password for fallback" captive_portal: sensor: - platform: ultrasonic trigger_pin: GPIO5 echo_pin: GPIO18 name: "JoJo Ultrasonic Sensor" unit_of_measurement: "L" update_interval: 10s filters: - sliding_window_moving_average: window_size: 5 send_every: 5 - lambda: return 3.14 * 0.42 * 0.42 * (1.95-x) * 1000.0 ; - filter_out: nan
In my code, I have implemented two key filters to enhance the accuracy of the water level readings from the Jojo tank:
1. Sliding Window Moving Average: This filter operates by taking a distance measurement from the sensor every 10 seconds. Once it has collected 5 such readings, it calculates their average. This averaged value is then transmitted to Home Assistant as the official reading. The rationale behind using this filter is to counteract any potential inaccuracies caused by water ripples, which might skew a single reading. For adaptability to different scenarios, you can modify the `window_size` and `send_every` parameters according to your specific requirements.
2. Lambda: Given that the Jojo tank is circular, it’s necessary to apply a specific formula to calculate the volume of water based on the sensor’s reading. The formula used is: (V = pi r^2 h), where (V) is the volume, (r) is the radius of the tank, and (h) is the height of the water, which is derived from subtracting the sensor reading from the total height of the tank. To convert the volume to liters, the result is then multiplied by 1000. This formula is crucial for obtaining an accurate measurement of the water volume in the tank, taking into consideration its unique shape.
For this project, I’m using a 1000 Litre JoJo Slimline tank, which has specific dimensions that are crucial for the accurate calculation of water volume. While the official dimensions of the tank might indicate a height of 2.06 meters, in my formula, I’ve used a height of 1.95 meters. This discrepancy is because the sensor is mounted 110mm above the full water level. Consequently, when the sensor reads a distance of 1.95 meters, it corresponds to a full tank capacity of 1000 liters.
When adapting this setup for a different tank or a tank of a different size, it’s essential to obtain or measure the exact dimensions of your tank. This includes the height, width, and depth, as these dimensions directly influence the accuracy of the volume calculation. Once you have these measurements, you can adjust the formula accordingly to ensure that the water level readings are as precise as possible for your specific tank.
The next step involves the physical installation of the system on the JoJo tank. An important component of this setup is the Sonoff Waterproof junction box, which is listed among the required parts. This box is essential because it protects the sensor from humidity and other outdoor conditions.
For the installation, you’ll need to modify the Sonoff waterproof box by creating two holes. These holes are for positioning the Ultrasonic sensor so that it faces downwards towards the water. This orientation is crucial for accurate measurement of the water level.
Given that the HC-SR04 sensor, which is used in this setup, is not inherently waterproof, it’s a wise precaution to have some spare sensors on hand. While I haven’t experienced any failures with these sensors under these conditions, having spares is a practical measure. This ensures that you can quickly replace a sensor if it becomes necessary, maintaining the continuous operation of your water level monitoring system.
When mounting the Ultrasonic sensor on your JoJo tank, it’s crucial to position it as flush as possible with the tank’s lid. This ensures that the sensor is oriented perfectly downward, at a 90-degree angle to the water surface. This alignment is key for accurate distance readings.
Additionally, aim to maintain a gap of approximately 10-20 centimeters between the sensor and the water’s surface when the tank is at its maximum capacity. This spacing aligns with the specific values I mentioned earlier in my formula and is important for ensuring the sensor’s readings are accurate and reliable.
With these steps completed, your water level monitoring project is essentially ready to go. It’s a straightforward yet enjoyable project. You can now leverage Home Assistant to set up automations based on your tank’s water levels or simply use it for monitoring purposes – because, well, it’s quite cool to have such capabilities at your disposal!
I encourage you to share your experiences, thoughts, or even your own Water Tank project. It’s always inspiring to see how others adapt and implement similar ideas, so feel free to comment, like, or share your own journey with us!
Leave a Reply