There is a system that could be put in place for this, like many public toilet facilities with lots of cubicles, a green/red lighting system above the cubicle. Similar to LGW car parking, I’m sure many other places. When searching for a parking bay a light indicator helps determine which bay is free or not. A sensor picks up whether someone is in there or not.
I’m sure I read somewhere recently of this happening in a public toilet area with cubicles. Can’t remember where...