Skip to main content

Automate your webcam light.

Project description

AutoCamLight

╔═══╗    ╖      ╔═══╕         ╖         ╖   ╖  
║   ║    ║      ║             ║    °    ║   ║  
╠═══╣╖  ╓╠═╛╔══╗║    ╒══╗╔═╦═╗║    ╖╔══╗╠══╗╠═╛
║   ║║  ║║  ║  ║║    ╔══╣║ ║ ║║    ║║  ║║  ║║  
╜   ╙╚══╝╚═╛╚══╝╚═══╛╚══╝╜ ╙ ╙╚═══╛╙╚══╣╜  ╙╚═╛
                                    ╓  ║  
AutoCamLight                        ╚══╝  

PyPI version Python Versions Downloads License: MIT Ruff GitHub issues GitHub stars Last CommitPayPal

A small linux utility to automate your webcam light via Home Assistant.

Monitors /dev/video* and sends a state update to HA via MQTT when it detects that video is being captured.

Usage

Install, configure and run in the background.

After the first time the webcam is used, the device & entity will be created in Home Assistant, so you can set up your automations.

Install

Use of uv is highly recommended:

uv tool install autocamlight

Configure

Create a autocamlight.toml file in one of the following locations:

  1. $XDG_CONFIG_HOME (or ~/.config if unset), or
  2. $XDG_CONFIG_DIRS (or /etc/xdg if unset), read as a list of folder split by :, as per the XDG specification, or
  3. the current working directory.

The files are read in the order they are listed, so you can override settings. But only top level keys can be overridden in their entirety, no table merging is performed.

Example configuration with some comments:

# Log level, one of: CRITICAL, ERROR, WARNING, INFO, DEBUG
log_level = "DEBUG"

# Time to wait for inotify events, in seconds.
# Longer times will reduce CPU usage, but will increase the delay and jitter of the state updates.
inotify_block_duration = 0.1

# Time to wait after before sending the state update, in seconds.
# If another event is received before this time, the timer is reset.
debounce_duration = 0.5

# MQTT settings from https://github.com/unixorn/ha-mqtt-discoverable
[mqtt]
host = "homeassistant.local"
username = "mqtt"
password = "Correct Horse Battery Staple"

# Entity settings from https://github.com/unixorn/ha-mqtt-discoverable
[entity]
name = "Webcam"
unique_id = "fe4bd497-7c2f-4f35-899f-f147f9f84738-capturing"

# Device settings from https://github.com/unixorn/ha-mqtt-discoverable
[entity.device]
name = "Webcam"
identifiers = "fe4bd497-7c2f-4f35-899f-f147f9f84738"

The file structure is dictated mostly by ha_mqtt_discoverable.

Auto-run on login

Create a new (user) unit file:

systemctl --user --force --full edit autocamlight

Add the following to the file, assuming uv is installed in /usr/bin:

[Unit]
Description=AutoCamLight
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/uv tool run autocamlight
Restart=on-failure
RestartSec=5
Environment=PYTHONUNBUFFERED=1

[Install]
WantedBy=default.target

Now enable & start the unit:

systemctl --user enable autocamlight
systemctl --user start autocamlight

You can monitor the service status with:

systemctl --user status autocamlight
journalctl --user -u autocamlight -f

Test

Open any program that uses the webcam, e.g. Cheese.

If you have the logs open, an INFO message should appear. The entity should be created in Home Assistant.

Support the Project

If you find this project useful, a tip is always welcome via PayPal:

PayPal

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autocamlight-0.2.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autocamlight-0.2.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file autocamlight-0.2.0.tar.gz.

File metadata

  • Download URL: autocamlight-0.2.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for autocamlight-0.2.0.tar.gz
Algorithm Hash digest
SHA256 93f085bea65e8f13e00ac6c3b43f2291af6ca046e382039f6617c9a29fe0e5ba
MD5 af880a11cb921b152561a79fa43b56a6
BLAKE2b-256 c13afc1eeb7ce5d251dab5fd105fa82c5ac55784b1ec9ed6a8e1af9f04a0494b

See more details on using hashes here.

Provenance

The following attestation bundles were made for autocamlight-0.2.0.tar.gz:

Publisher: ci.yml on dries007/AutoCamLight

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file autocamlight-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: autocamlight-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for autocamlight-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8aeed85389c2356aef11570088ce79aebad074252b6e48fbb39a53d2b2119a5
MD5 13eda3895c6467e1f36d706c4d8c3dd6
BLAKE2b-256 24a9ae286d6125fbf8568f6e2dc744f38ff4a8d25bcaf3d8fff5f66a936a6391

See more details on using hashes here.

Provenance

The following attestation bundles were made for autocamlight-0.2.0-py3-none-any.whl:

Publisher: ci.yml on dries007/AutoCamLight

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page