You can add as many (maybe not, but at least several dozens) variables as you wish.
In the driver editor, click on Add Input Variable and choose your second object. In my case, I used a suzanne and a cylinder. Set up the distance variable exactly as for the first object.
Mind the name of the variables; it is important for later.
Then it is just a matter of modifying your expression to take the new variable into account. In your case, you want the expression to detect the closest one, that is to say the smallest variable, since the variables represent the distance of each object to the barrier.
The expression then becomes:
pi/2 + (min(suz,cyl/15)<0.8)*(pi*3/4-min(suz,cyl)/5)
Side note: You can ditch the
abs. Distances are (normally) always positive numbers.