First, the disappointing news - I definitely don't have the answers! But shall we have a brainstorm about what could be done?
The Problem
It seems to me that all attempts to trigger lights etc based on activating a PIR and then messing around with timers etc are doomed to failure. There's just too many situations where it doesn't work well, the timer can go wrong etc. This either results in the lights going off while you're motionless in the room or having the lights stay on too long even when the room becomes unoccupied. Carrying some kind of token, phone or watch etc are okay but not practical for general implementation and probably not rapid-acting enough for general use.
The Solution?
For rooms with a defined entry/exit boundary ie typically a door, it seems to me that the best method is to people count those entering or exiting the room. By maintaining an accurate count of people entering/exiting a room you could truly tell whether a room is occupied or not. Of course for rooms with multiple entry/exit points one would have to link matrix all the counts together to establish a true count. Relatively achievable with software, I'd have thought.
People counting systems are a thing and can be bought off the shelf but they come with a high price tag of 400-500 notes. This does show that this is a solved problem though and the technology and sensors obviously do exist.
Finding the Right Sensor
The real problem I think lies in getting the right sensor. We'd need to trigger on movements into and out of the zone/door boundary. So a dual beam or dual wave sensor is probably necessary to show directionality for entry and exit. PIRs are not really suitable as they lag too much to be accurate. So using two PIRs and then polling them for directional count is probably not accurate enough. It seemed that one company did start making these for the smart home market - http://www.hiome.com - and their web page gives a good idea of how their implementation works including with Homekit. Unfortunately, it seems like they're not responding and they have no stock so perhaps they're no longer in business. A shame as their product looks like it would have been perfect.
Any Ideas?
What do you think? Any ideas for sensors that we could use or possible implementations? If we got this reliably implemented switching logic just got a whole lot simpler and more dependable!