This is a little windows service written in python to determine if any process uses a webcam in Windows 10 and publish the results via mqtt. I implemented this because I wanted to automate the lighting in my homeoffice during video calls.
The algorithm is based on registry keys in Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam\NonPackaged
, where each process that has a handle on a webcam is registered. If a process currently has a handle, its LastUsedTimeStop
key equals 0
.
I do not guarantee for this to work in the future but in my environment it works pretty well. As I did not find anything to do this I thought I'd share.
No process using a webcam
Webcam used by a process
- Windows 10
- python >= 3.5
- paho-mqtt
- Install python on your windows machine
pip install -r requirements.txt
- create your
config.ini
fromconfig.ini.example
python service.py
To run the script as windows service and start it automatically with windows, you could use nssm.
- Install nssm
- Run
nssm install WindowsWebcamMonitor
as administrator
Example: Integration in Home Assistant
Put this in your configuration.yaml
sensor:
- platform: mqtt
name: Webcam
state_topic: "windows_webcam_monitor/used_by" # this must match with "path" in config.ini
icon: mdi:webcam