How will you determine that opening and closing the switch happens because someone is entering the room, as opposed to a person leaving the room?
How will you distinguish between someone opening the door, and looking in the room, without entering, from someone actually entering the room?
How will you deal with two people in the room?
A single switch is not sufficient. Look at all the places where it is important to know how many people have passed a particular point. All of those places make sure that a person MUST pass two points. The points are set up to not allow more than one person at a time to pass. The order that the two points are passed defines whether the person is entering or exiting.
An IR sensor is easier, but it detects motion. If the person enters the room and stays very still, such as while sleeping, the IR sensor will stop detecting the person.