Motion Sensor work with Door Sensor

So I have a Kasa Motion Sensor Dimmer in my bathroom, I have a Kasa switch installed for my fan and an Aqara door sensor on my bathroom door.

I want to the light to turn on when I walk in and when I close the door, I want the fan to turn on as well. And when I open my door again, I need the light and fan both to be switched off at the same time.

I have tried a couple of solutions online but couldn’t get for it to work. The light keeps on switching off after no motion is detected (currently set to 15 sec for testing only)

Do you need the motion sensor?

When the door opens, if the light is off it turns on; if the light is on it turns off.

Yes, because that bathroom door is always open. So I installed a motion sensor in that one. Rest of the house, I installed pretty similar to a pantry one with open and close will turn on and off the lights. That one was pretty straight forward, this one has got to my nerve now

The other way round then? When the door closes… etc.