Waalikumusalam ,
It is simple you will need an general purpose AC relay , i have used finder because they are of good quality, Also get a base along with it, there will be 8 pins but will be using just 4 , idea is that Relay will be powered by WAPDA (Pin 2 and Pin 10) and it will disconnect a connection through the relay (Pin 11 & Pin 8), fan will be off while there is no load shedding you can enjoy air conditioner and fan will be off, As soon as Grid will go off the relay will turn on and conection of UPS will be completed for fan and fan will turn on ,
I have placed a switch on relay so that i can turn of relay by my self i want to. I am not expert so sorry if i have not been able to explain well. But it is very simple , i did every thing my self