I have done this using a PLC ($$), But it can be done with a microcontroller.
It counted the number of people in the room as long as there were 1 or more the light would be turned On. By keeping track of the entrance/exit.
A PLC is just a glorified microcontroller, and a microcontroller would be alot cheaper than a PLC.
The problem with motion is that if you don't move every so-long the light would turn Off; not fun when your in the shower or on the jhon.
Code example for a microcontroller.
Place two sensors (IR) at every entrance/exit;
If "Sensor One" is triggered before "Sensor Two" then someone is entering.
while ( (sensor_one==1)&(enable==1) )
{
if (sensor_two == 1 ) { hall_count++; enable==0;}
}
If "Sensor Two" is triggered before "Sensor One" then someone is exiting.
while ( (sensor_two==1)&(enable==1) )
{
if (sensor_one == 1 ) { hall_count--; enable==0;}
}
if ( (sensor_one==0)&(sensor_two==0)) { enable==1; } // Reset Sensor Inputs
What you do is, Increment a counter when a person enters and Decrement the counter when they exit.
if (hall_count >= 1 ) { hall_light = On; } else { hall_light = Off; }