Skip to content

Latest commit

 

History

History
55 lines (34 loc) · 2.23 KB

README.md

File metadata and controls

55 lines (34 loc) · 2.23 KB

windows_webcam_monitor

Abstract

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.

Features

No process using a webcam

example mqtt message when webcam is unused

Webcam used by a process

example mqtt message when webcam is used by Discord

Dependencies

How to install

  1. Install python on your windows machine
  2. pip install -r requirements.txt
  3. create your config.ini from config.ini.example
  4. python service.py

As a service

To run the script as windows service and start it automatically with windows, you could use nssm.

  1. Install nssm
  2. Run nssm install WindowsWebcamMonitor as administrator

example config for NSSM service installer

log on/user config for NSSM service installer

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