Hey everyone! I’ve been diving into some interesting projects lately, and I wanted to share my experience with setting up a water level monitoring system using ESPHome and Home Assistant. It’s been a fun challenge, and I’m hoping to get some feedback or tips from the community.
So, here’s the setup: I have a water tank that’s about 1.12 meters deep, and I wanted to monitor the water level in real-time. I decided to use an ESP32 board along with a waterproof ultrasonic distance sensor. The sensor is mounted about 25 cm above the tank to compensate for its minimum reading distance. The goal is to have the sensor return values on a 0-100 scale, where 0 represents an empty tank and 100 represents a full tank.
I’ve successfully set up the sensor using ESPHome, and it’s currently displaying distance in meters. However, I need to convert this distance into a percentage scale for the water level. Since the water level can only drop (as water is consumed), the distance from the sensor will increase from 0.25 meters (empty) to 1.12 meters (full). This means I need to reverse the scale somehow.
I’ve been experimenting with Home Assistant’s template sensors and ESPHome’s YAML configuration to achieve this. Here’s a snippet of the code I’m working with:
yaml
sensor:
- platform: template
sensors:
water_level:
value_template: >-
{{ (1.12 - states(‘sensor.distance_sensor’)) / 0.87 * 100 }}
friendly_name: Water Level
unit_of_measurement: ‘%’
This template takes the current distance reading, subtracts it from the maximum distance (1.12 meters), divides by the range (0.87 meters), and then multiplies by 100 to get a percentage. It seems to work, but I’m wondering if there’s a more efficient or accurate way to do this. Maybe using a different formula or integrating it directly into ESPHome?
Another thing I’m considering is setting up alerts when the water level gets too low or too high. I think I can use Home Assistant’s automation feature for that. For example, sending a notification if the water level drops below 20% or rises above 90%.
I’d love to hear from anyone who has experience with similar setups. Do you have any tips for improving the accuracy of the readings? Have you encountered any common issues with ultrasonic sensors in this kind of application? I’m also curious if anyone has a better way to handle the scale conversion within ESPHome itself.
Thanks in advance for your insights and suggestions! It’s been a great learning experience, and I’m excited to see how this project evolves.