Skip to main content

General purpose DBus to MQTT bridge - expose signals, methods and properties over MQTT - featuring jinja based templating, payload enrichment and MPRIS / BlueZ / Home Assistant ready examples

Project description

dbus2mqtt

dbus2mqtt is a Python application that bridges DBus with MQTT. It lets you forward Linux D-Bus signals and properties to MQTT topics, call D-Bus methods via MQTT messages, and shape payloads using flexible Jinja2 templating.

This makes it easy to integrate Linux desktop services or system signals into MQTT-based workflows - including Home Assistant.

Features

  • 🔗 Forward D-Bus signals to MQTT topics.
  • 🧠 Enrich or transform MQTT payloads using Jinja2 templates and additional D-Bus calls.
  • ⚡ Trigger message publishing via signals, timers, property changes, or startup events.
  • 📡 Expose D-Bus methods for remote control via MQTT messages.
  • 🏠 Includes example configurations for MPRIS and Home Assistant Media Player integration.

Project status

dbus2mqtt is considered stable for the use-cases it has been tested against, and is actively being developed. Documentation is continuously being improved.

Initial testing has focused on MPRIS integration. A table of tested MPRIS players and their supported methods can be found on Mediaplayer integration with Home Assistant

Getting started with dbus2mqtt

Create a config.yaml file with the contents shown below. This configuration will expose all bus properties from the org.mpris.MediaPlayer2.Player interface to MQTT on the dbus2mqtt/org.mpris.MediaPlayer2/state topic.

dbus:
  subscriptions:
    - bus_name: org.mpris.MediaPlayer2.*
      path: /org/mpris/MediaPlayer2
      interfaces:
        - interface: org.freedesktop.DBus.Properties
          methods:
            - method: GetAll

      flows:
        - name: "Publish MPRIS state"
          triggers:
            - type: object_added
            - type: schedule
              interval: {seconds: 5}
          actions:
            - type: context_set
              context:
                mpris_bus_name: '{{ dbus_list("org.mpris.MediaPlayer2.*") | first }}'
                path: /org/mpris/MediaPlayer2
            - type: mqtt_publish
              topic: dbus2mqtt/org.mpris.MediaPlayer2/state
              payload_type: json
              payload_template: |
                {{ dbus_call(mpris_bus_name, path, 'org.freedesktop.DBus.Properties', 'GetAll', ['org.mpris.MediaPlayer2.Player']) }}

MQTT connection details can be configured in that same config.yaml file or via environment variables. For now create a .env file with the following contents.

MQTT__HOST=localhost
MQTT__PORT=1883
MQTT__USERNAME=
MQTT__PASSWORD=

Install and run dbus2mqtt

python -m pip install dbus2mqtt
dbus2mqtt --config config.yaml

See setup for more installation options and configuration details.

Examples

More dbus2mqtt examples can be found in the examples section. The most complete one being Mediaplayer integration with Home Assistant

Exposing dbus methods, properties and signals

See subscriptions for documentation on calling methods, setting properties and exposing D-Bus signals to MQTT. When configured, D-Bus methods can be invoked by publishing a message like

{
    "method": "Play"
}

Flows and Jinja based templating

For more advanced use-cases, dbus2mqtt has support for flows and Jinja2 based templates. A reference of all supported flow triggers and actions can be found on flows

Jinja templating documentation can be found here: templating

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

dbus2mqtt-0.5.0.tar.gz (155.0 kB view details)

Uploaded Source

Built Distribution

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

dbus2mqtt-0.5.0-py3-none-any.whl (32.4 kB view details)

Uploaded Python 3

File details

Details for the file dbus2mqtt-0.5.0.tar.gz.

File metadata

  • Download URL: dbus2mqtt-0.5.0.tar.gz
  • Upload date:
  • Size: 155.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dbus2mqtt-0.5.0.tar.gz
Algorithm Hash digest
SHA256 5c314ad91353487df0174af203c541041a42aabd47ca8c64a32b28ff24229f66
MD5 b658c06a01a74fd3638eea9a9462b87c
BLAKE2b-256 35ebfd321f8d14da5c805410edf1b0768b5845251f44f1d2bba4015de1f8b228

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbus2mqtt-0.5.0.tar.gz:

Publisher: publish.yml on jwnmulder/dbus2mqtt

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

File details

Details for the file dbus2mqtt-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: dbus2mqtt-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 32.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dbus2mqtt-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94a30e9adb77dc28bcbf9b267b8ff7b6d82a02d9d6d2c0bd70611b3fcaa043f2
MD5 478418bb4a7ea84e9bd2a0ac0c174d70
BLAKE2b-256 ace6f63c057bce33d7c5d3d08ec12148b036db3355826be03f4b5a63f894bdba

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbus2mqtt-0.5.0-py3-none-any.whl:

Publisher: publish.yml on jwnmulder/dbus2mqtt

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