Detect if an attached webcam is in use and optionally publish its status to an MQTT broker in a way Home Assistant understands.
$ on-air get
device: /dev/video0
name: Integrated RGB Camera: Integrat
status: streaming
device: /dev/video2
name: Integrated RGB Camera: Integrat
status: not streaming
This connects to an MQTT broker and publishes the status to a topic.
First, it publishes a retained "config" discovery message as described by Home
Assistant here:
https://www.home-assistant.io/integrations/mqtt/#discovery-topic. The component
type is binary_sensor
.
Next, it runs forever, polling the state of the attached webcams and publishing to the MQTT broker if anything changes.
$ on-air mqtt --broker mqtts://mqtt.snow.jflei.com --username jfly --password hunter2 --unique-id compy386
Run on-air mqtt --help
to discover some optional settings, including polling interval.
You can see this in action here: https://www.youtube.com/watch?v=9zsV41U3B2E. Details:
- I have systemd user targets configured for the various locations my laptop can be in.
- These targets are activated by a script that currently looks at attached monitors, but may use other heuristics in the future.
- When I'm in my office (the garage), a systemd unit runs that starts the
on-air
binary. - The rest is all in Home Assistant: a couple of automations ("garage on-air" and "garage off-air") that turn the "on air led" on/off when my laptop webcam appears/disappears.
- I built the on air display, which was a fun mix of woodworking and electronics. It has an ESP8266 running ESPHome. It's directly connected to mains electricity for power. Feel free to reach out if you'd like more details. It may motivate me to document the full build.