Owner refusing to give security deposit and advance rent back. Help!

Pg owner is refusing to give 1 month advance rent and security deposit as he claims I didn't give him 30 days notice. The reason I had to leave the pg is that they locked me out twice when I returned from work around 3 am. This was despite informing the caretaker beforehand to open the gates around the said time or to leave it unlocked. This caused grave pain and to me as I was left out alone in the middle of the night- exhausted and scared to death. On one such incident, the neighbours even assumed I was a thief banging on the door until the company cab driver told them that I was locked out by the pg caretakers. It was humiliating. They only opened the gates after I rang them up(owner and caretaker) repeatedly i.e around more than 10 times meanwhile banging on the gates. While I cited this as the reason to leave, the owner is still refusing to give my money back saying, "it's your choice to leave". He's asking me to get him a replacement to pay his rent and only then will give my money back. I requested him to keep the deposit money until he finds a replacement but he disagreed. Can someone please tell me if there's anything that can be done here to get my money back?