General purpose DBus to MQTT bridge - expose signals, methods and properties over MQTT
8.6K
dbus2mqtt is a Python application that bridges DBus with MQTT. It lets you forward Linux D-Bus signals and properties to MQTT topics, call DBus 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.
Create a config.yaml file with the contents shown below. The configuration example below exposes all bus properties from the org.mpris.MediaPlayer2.Player interface to MQTT on the dbus2mqtt/org.mpris.MediaPlayer2/state topic. Have a look at docs/examples for more examples
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']) | to_yaml }}
MQTT connection details can be configured via a .env file with the following contents.
MQTT__HOST=localhost
MQTT__PORT=1883
MQTT__USERNAME=
MQTT__PASSWORD=
python -m pip install dbus2mqtt
dbus2mqtt --config config.yaml
To run dbus2mqtt using Docker with the provided home_assistant_media_player.yaml example
# setup configuration
mkdir -p $HOME/.config/dbus2mqtt
cp docs/examples/home_assistant_media_player.yaml $HOME/.config/dbus2mqtt/config.yaml
cp .env.example $HOME/.config/dbus2mqtt/.env
# run image and automatically start on reboot
docker run --detach --name dbus2mqtt \
--volume "$HOME"/.config/dbus2mqtt:"$HOME"/.config/dbus2mqtt \
--volume /run/user:/run/user \
--env DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS" \
--env-file "$HOME"/.config/dbus2mqtt/.env \
--user $(id -u):$(id -g) \
--privileged \
--restart unless-stopped \
jwnmulder/dbus2mqtt \
--config "$HOME"/.config/dbus2mqtt/config.yaml
# view logs
sudo docker logs dbus2mqtt -f
Content type
Image
Digest
sha256:0b74fa26a…
Size
51 MB
Last updated
2 days ago
docker pull jwnmulder/dbus2mqtt