Skip to main content

Detects if the user is an online call, publishes gathered information to an MQTT broker

Project description

call_detector

call_detector listens to microphone and camera states to detect if the user is participating in an online call. Gathered information is being published to an MQTT broker.

Where it works

Currently only Linux is supported, I don't have plans to support other operating systems. If you're interested, feel free to open a PR.

In order to use call_detector you'll need pulseaudio or pipewire-pulse and libpulse.

How it works

call_detector listens to pulseadio events to detect apps which use the microphone and uses inotify with some /proc magic to find apps which use the camera.

MQTT

call_detector was only tested against mosquitto MQTT broker with login/password authentication and TLS enabled, however in therory it can work without TLS and authentication and against any broker supported by gmqtt.

Every time the call_detector detects an app which starts or stops using the microphone or the camera, it publishes a message to an MQTT topic with name of the format call_detector/<hostname> where hostname is the hostname of the machine where you run call_detector. Also it sends a message on start and every minute.

Message examples:

{"camera": [], "microphone": [], "call": false} when camera and microphone are not active.

{"camera": ["firefox"], "microphone": ["firefox"], "call": true} when user is in an online call using firefox.

Installation

pip install call_detector

Usage

Basic usage:

call_detector -H mqtt.example.com -U user -P password

More advanced options can be found in help

call_detector --help

Home Assistant

Binary sensor:

binary_sensor:
  - platform: mqtt
    name: "User in an online meeting"
    state_topic: "call_detector/<hostname>" # check call_detector --help to find the default topic for your computer
    value_template: "{{ 'ON' if value_json.call else 'OFF' }}"
    json_attributes_topic: "call_detector/<hostname>" # same as state_topic
    json_attributes_template: "{{ value_json | tojson }}"
    qos: 1

Automation example:

- alias: Pause music while User is in an online meting
  trigger:
    - platform: state
      entity_id: binary_sensor.user_in_an_online_meeting
      to: "on"

  condition:
    - condition: state
      entity_id: media_player.mpd
      state: "playing"

  action:
    - service: media_player.media_pause
      data:
        entity_id: media_player.mpd

    - wait_for_trigger:
        - platform: state
          entity_id: binary_sensor.user_in_an_online_meeting
          to: "off"

    - service: media_player.media_play
      data:
        entity_id: media_player.mpd

Contribution

You know;)

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

call_detector-0.2.4.tar.gz (5.9 kB view hashes)

Uploaded Source

Built Distribution

call_detector-0.2.4-py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 3

Supported by

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