urm i dont knw if the return is in analog value or digital value but my example should apply to your application what so ever
ok
first you should know how high the water is now,
then you need to set how high the water should be at its highest
then you should set how low the water could be b4 the water should be filling in to the tank
then it would be as a simple as
(return digital Value)
if (WaterNow==SetHighPoint)then shut valve;
if (WaterNow==SetLowPoint)then open valve;
(return analog value)
if (WaterNow(what analog value that you get for the sensor) is >= SetHighPoint(this is where you set the value of max water level)then shut valve ;
if (WaterNow is <= SetLowPoint(set the minimum value of water) ) then open valve;
this should point you to the rite direction