A salt level monitor for the water softener

A water softener fails quietly. Nobody notices the salt ran out until the dishwasher starts leaving spots and someone opens the brine tank to find it empty. This is a small sensor that removes the surprise.

What it is

An ESP32 dev board running ESPHome, mounted in the garage at the softener, with an HC-SR04 ultrasonic sensor looking down into the brine tank from the lid. The sensor sends a ping and times the echo off the salt surface. Knowing the distance when the tank is full and the distance when it is empty turns that into a percentage, and ESPHome reports it to Home Assistant along with the usual diagnostics: WiFi signal, uptime, IP address, firmware version. It has been running since February 2026 without attention.

Schematic: ESP32 with an HC-SR04 on GPIO23 and GPIO22, echo wired directly

The HC-SR04 is the cheapest distance sensor there is, a couple of dollars each, and it is fine for this. Salt sits in a rough, sloped pile rather than a flat surface, so individual readings bounce around by a few percent, which is why the number gets smoothed before anyone sees it. Two things to get right: the sensor’s transducers face down and must not touch the brine, and the lid it mounts in stays put, because a few millimeters of shift changes the calibration.

About the wiring. The HC-SR04 is a 5 volt part and its echo pin puts 5 volts straight into an ESP32 input rated for 3.3. The right fix is a two-resistor divider on that line. I did not bother, it has run since February without complaint, and I know that is not a defense. If you build one, spend the two resistors.

Making the number useful

The sensor pings once a minute and the distance becomes a percentage between two calibration points, the distance when the tank is topped off and the distance when it needs a refill. A moving average takes out the jitter. A second filter on the ESP holds the reported value steady through any sudden rise, because brine sloshing and a hand in the tank both look like a refill for a few minutes; if the rise is still there after 30 minutes, it was real and the new value is accepted. Home Assistant then rounds to the nearest 5 percent for the dashboard, so the number moves when the salt does, not when the reading wobbles.

The ESPHome config and the Home Assistant pieces are in the repository.

One automation does the rest. When the level has been below 30 percent for five minutes, both phones get a notification with the current percentage and “time to refill”. The five-minute hold means a hand in the tank during a refill does not fire it.

Why bother

Twenty dollars and an afternoon. In return, salt gets bought before it runs out and the softener never regenerates on an empty tank. The small ones that kill one chore are the ones that stay installed.

Tagged home-assistant, esphome, esp32, sensors.