Check out my blog post that describes how to build this project and how I designed it. https://codejockeyscorner.blogspot.com/2021/10/raspberry-pi-mqtt-water-softener-salt.html
More information here: http://www.steves-internet-guide.com/into-mqtt-python-client/
pip install paho-mqtt
Update the following MQTT configuration values:
#MQTT constants
mqttBroker = "<% MQTT_HOST %>"
mqttTopic = "home/pi/softener"
mqttUser = "homeassistant"
mqttPassword = "<% MQTT_PASSWORD %>"
Update the sensor pins to match how you wired your sensor
#sensor constants
TRIG = 23
ECHO = 24
Update the following distances to match your specific brine tank measurements
#measurements constants
TANK_EMPTY_DISTANCE = 31 #inches
TANK_FULL_DISTANCE = 6 #inches
TANK_LOW_WATERMARK_DISTANCE = 25 #inches
python salt_monitor.py