Counting People using two Motion Sensors


The Fibaro Motion Sensor can be configured to detect motion with an accuracy of one second between movements. With two motion sensors working together on either side of a door, it is possible to count the number of people entering and leaving a room.

SOME THOUGHTS ON THIS


There is a limitation with this approach: because the minimum setting for the motion sensor is 1 second, if two people enter a room within 1 second of each other, there is no way of detecting the two people apart.

If you need accuracy like this, perhaps a better option is a universal sensor connected with two light beams in the door frame. This still won't detect two people walking through the door at the same time sideways, but the chances of this are much less – one would assume!

Some things that need to be considered when using two motion sensors:

  • The motion sensors need to be above the door frame so the frame acts as a filter – so the outside sensor doesn't detect the inside one and visa versa.
  • The sensors need to be rotated inwards so that only a very narrow beam of detection is looking straight down. This stops the movement in the room triggering the device.

In essence you are narrowing the beam to two areas just on either side of the door.

LET'S GO!


Making the sensors more sensitive

Change these parameters in both motion sensors:

Parameter 1 = 8
Parameter 2 = 0
Parameter 6 = 1s

Save this and wake up the device to let it know things have changed.

The global variable


We need a global variable to contain the count of people in the room. We have called ours PeopleCount, but feel free to change that – especially if you're counting more than one area.

The code


Don't forget to change the trigger device IDs and the two local variables motionInside and motionOutside to the IDs of the motion sensors you want to monitor!

THINGS TO TRY


Adjustments

See how it works. Adjust the height of the sensors if there is interference between inside and outside. Rotate them further in if there is interference from within the room.
The local variable debugLevel can be changed to give more debugging detail. Try values of 5, 10, 11 and 20.

Going further

If you have more than one access door in the room, you may want to add sensors to the other doors too. You will need to duplicate the scene so that each door will run independently of the other, but the global variable used for counting will remain the same.
If you have a door sensor, it would make sense to ignore movement unless the door is open – but don't ignore it completely, you may be wanting to go out through the door you just opened… or maybe you could ignore it completely – time to experiment some more

WHERE NOW?


For more information on programming the Home Center 2 in Lua, see our support page at lua