I believe (what with not being an expert at all) that the energy release upon annihilation is directly related to how positive or negative the person is.
My guess: a count increments upward when the entrance door swings open and downward when the exit door swings. If one person holds the door for a few people but they exit individually, the count gets messed up.
You can't go by doors opening or light barriers because of the issue you mentioned.
Using e.g. cameras mounted on the ceiling kinda works, as long as you have a small area to cover, but they use a lot of processing power and are still not accurate.
Going by CO2 counts or VOCs is possible, but lags behind and has to be calibrated per room (and is still inaccurate without good ventilation).
I wish there was an easy solution, especially for smart homes.