If you found this project helpful, please consider supporting me:
This project uses an ESP32‑C3 with an ultrasonic sensor to measure the water level in a tank, report the fill percentage, and deep sleep between readings to save power.
It integrates with Home Assistant, storing the last known reading so you can still see the fill level even while the device is asleep.
- Reads water tank level using an AJ-SR04M or similar ultrasonic sensor
- Converts distance → tank fill percentage
- Deep sleep between readings for extended battery life
- Persistent storage in Home Assistant: keeps last known value when the ESP is offline
- OTA updates: 2‑minute update window at each wake‑up for easy firmware flashing
- Soldering Iron
- ESP32‑C3 Super Mini (or compatible ESP32 board)
- Ultrasonic Distance Sensor e.g. JSN‑SR04T or AJ-SR04M for waterproof applications)
- 6V 1W Solar Panel
- TP4056 Charging Module
- 5v Boost Converter
- 470μF Capacitor
- 1 kΩ + 2 kΩ resistors (for voltage divider on echo pin)
- Wires and a small enclosure (optional but recommended)
- VCC → 5V (from boost converter)
- GND → GND
- Trigger → GPIO 3 (change in YAML if needed)
- Echo → Voltage divider (2 kΩ to Echo, 1 kΩ to GND, take signal from between resistors) → GPIO 2
The sensor outputs 5V on Echo, but the ESP32 only tolerates 3.3V, the voltage divider drops it to a safe level.
- Solar panel → TP4056 input (IN+) & (IN–)
- TP4056 output (BAT+ & BAT–) → Li‑ion battery
- TP4056 output (BAT+ & BAT–) → Boost converter input
- Boost converter output (5V & GND) → ESP32 5V pin and Ultrasonic sensor VCC
- 470 µF capacitor across the boost converter output (helps prevent brown‑outs when ESP wakes up).
- Copy the provided
watertank-level.yamlfile into your ESPHome directory (e.g.,esphome/watertank-level.yaml). - Replace the placeholders for Wi‑Fi credentials, API key, and OTA password.
- Adjust
max_distanceandmin_distancein the YAML file to match your tank’s dimensions. - Compile and flash the firmware to your ESP32 device using ESPHome.
- Open your
configuration.yaml. - Add the provided input number and template sensor sections for retaining the last known tank level.
- Restart Home Assistant to apply the changes.
- Open your
automations.yaml. - Add the provided automation that updates the persistent tank level value whenever a new reading is received.
- Reload automations or restart Home Assistant.
- Measure your tank’s depth when empty → Set
max_distancein the ESPHome file. - Measure the distance from the sensor to the water surface when full → Set
min_distance. - Flash the firmware to your ESP device.
- Monitor the ESPHome logs to verify that readings are correct.
- The ESP wakes up and connects to Wi‑Fi & Home Assistant API.
- It opens a 2‑minute OTA window (can be changed in YAML) to allow firmware updates.
- The device takes a distance reading and converts it to a fill percentage.
- The reading is sent to Home Assistant.
- If the reading succeeded: the ESP goes into deep sleep for 1.5 hours.
- If the reading failed: it retries after 1 minute.
If you found this project helpful, you can support my work here:

