This project builds a room presence solution on top of my other recent project: Argos. I posted about that too in the community just yesterday. Using just a cheap raspberry pi zero w (plus an attached pi camera, or an RTMP enabled camera) in any room, this project provides a reliable, robust and efficient mechanism to detect if people are present in that room or not, allowing you to then use it as an MQTT sensor in HomeAssistant for automating lighting, media players, heating or what have you in that room, as a consequence.
Preface
For a long time, I’ve been trying to figure out a robust room presence solution for my home automation setup within HomeAssistant. I’ve tried everything from integrating simple battery operated wifi-connected PIR motion sensors to bluetooth LE based detection using a cluster of raspberry pi zero’s running room-assistant. It all works half of the time and then crumbles down like a house of cards rest of the time. After a lot of tinkering and tuning, I have now devised a solution, which I can confidently proclaim, is completely devoid of any false positives or false negatives, and works reliably in the real world. And trust me, when it comes to room presence, what matters is false negatives! Folks absolutely hate you when your fancy home automation turned off the TV and all the lights when everyone was tuned into that game/movie!
So, whats the secret sauce?
argos-presence provides reliable room presence by using computer vision . Forget all the thermal imaging sensors, PIR motion sensors and bluetooth scanning solutions. Raspberry Pi’s can now run sophisticated computer vision algorithms and even machine learning algorithms (thank you tensorflow lite!) thanks to all the performance advancements in both single board computers and advancements in OpenCV and tensorflow.
We dont simply set the presenceStatus based on motion. We have warmUp and coolDown periods.
When motion tries to switch presenceStatus from on to off, we have a coolDown period where the argos object detection service is called to figure out if there’s a person in the scene, and we keep extending the cool down till a person is detected. This is to avoid false negatives
When motion tries to switch presenceStatus from off to on, we have a warmUp period where, again we detect if a person is present or not. This is to avoid false positives . For example, if your presenceStatus recently went from on to off, your lights are in the process of turning off, which can be seen as motion by the detector. If we did not have a warmUp period, your room would keep flipping the lights on and off continuously.
The warmup and cooldown periods need to be configured (sensible tried and tested defaults are already set in the example config) to accommodate for your environment.
it is detecting movement (even the tiniest finger or facial movement), and then making sure the movement is actually a person when it matters (during warmup and cooldown). you don’t wait 30 seconds for the light to turn on. during warmup (default 30 seconds), it terminates the warmup and switches to presenceStatus ON immediately if a person is detected (and only if…). the reason to include a warmUp was to avoid the flipping effect - presence status became OFF, your lights began to turn off, then the motion detector picked that up a a motion and turned them on again. so it takes care of false positives.
during coolDown, even though there’s no motion, it keeps checking if there’s a human present in the seen (for 300 seconds by default).
in effect, your lights (or whatever you choose to turn on in your automation) will turn ON instantly, but they’ll take coolDown seconds (e.g. 5 minutes) to turn off and will ONLY turn off when there’s no computer vision detected human in the frame (so no false negatives - a big principle on which the project was built)
btw all of this is configurable - and you can even change the label of the tensorflow model to include “dog” or any of the other 90 classes of objects in the CoCo dataset
it just seems a misfit for this project doesn’t it? currently person detection happens only during the warmup and cool down periods of the motion detector. it is done only to weed out false positives and negatives. one possibility is that we could add a parallel face detection loop which runs once every X frames. could you talk a bit more about your use case for knowing exactly who came into the room?
I believe this approach to be the definitive solution to room presence though I’m having a hell of a time setting it up - I was initially installing to a Raspbian VM but couldn’t get tensorflow to install, and have so switched to a Debian VM where I’m trying to use the docker image. Would be great to get a full step by step guide - I feel like I’m missing something when it comes to the section in the readme about stream.py and serve.py…