Raspberry Pi MQTT Water Softener Salt Level Sensor



I live in an area with some pretty hard well water with a very high amount of iron. There is a water softener in the basement for removing the iron but often I forget to check the salt level. When there isn't enough salt in the brine tank to clean the system it doesn't take long for the water to begin tasting/smelling of iron and all of the bathroom fixtures to discolor. For a while, I've been trying to come up with a way to monitor the salt level and even get notified when the level is below a certain watermark (pun intended).

This post is going to describe the monitoring device that I've come up with and will be followed by posts describing the designing of the device, the software involved, and how to configure Home Assistant to display the monitor data and alert when the salt level is low.


My water softener consists of 2 tanks. One is the actual softener and the other is the brine tank. The brine tank needs to be filled with salt regularly. Cleaning/regeneration cycles occur based off of household water usage and the salt level drops in the brine tank as it's absorbed in the brine water at the bottom. I need to be able to determine how low the salt level is in the tank so I know it's time to buy more salt and refill it.

I decided to base this sensor off of an HC-SR04 Ultrasonic Distance Sensor that I got in one of the Arduino kits I've accumulated over the years. It has a measurement range of 3/4" to 13' which is more than enough to measure the distance from the top of the tank to the top of the salt and is cheap enough to replace if/when the harsh saltwater environment takes its toll. I won't get into how exactly the ultrasonic sensor works but here is a good reference.

While I could have used an ESP32 microcontroller to run the sensor, I decided to use a Raspberry Pi 3 board that I had laying around. My intent is to later expand its use to other basement sensors like monitoring the sump pump, water pump, etc.

Using the Raspberry Pi and Python, the sensor is triggered every 5 minutes (yes, excessive) to measure the salt level, calculate the remaining capacity of the tank, and send an MQTT message with the latest measurement data. I'm using an MQTT topic hosted by a separate Raspberry Pi running Home Assistant server. In Home Assistant I've configured a sensor to listen for the MQTT messages. On the dashboard, I've created a card to render the current level in the brine tank and using an automation I've configured an alert to appear on the dashboard and my mobile device when the status is "low" (See below)

I currently am working on a case design that will include a bracket for the tank but for now, I just have it attached to a 2x4 that spans the sides of the tank (yep, it's pretty janky).

In future posts I'll cover more details about:
  • The sensor itself
  • The python script that runs the sensor
  • How I've configured Home Assistant to leverage the sensor.

Comments

Popular Posts