I've disassembled a Brother printer and I found a sensor that determines whether the tray is open/close.
It looks like a pretty straight-forward sensor with 3 pins, so I tried to figure out how to use it although I don't have the datasheet, but couldn't
I tried all combinations of 5v, GND and input pin. None worked.
I'm attaching two images of the sensor. You'll notice 2 little "bumps" with a small distance between them. When something comes in between, the sensor should detect that the tray is "closed", otherwise it's "open".