Skip to content

Flows

dbus2mqtt allows you to add additional processing logic (flows) for when events occur. Configuration is done in yaml and a complete example can be found in home_assistant_media_player.yaml which is part of the MPRIS to Home Assistant Media Player integration example

Flows can be defined on a global or dbus subscription level and can be triggered by any of the following events:

  • schedule for cron based schedules
  • dbus_signal for when dbus signal occur
  • object_added when a new bus_name is registered on dbus
  • object_removed when a bus_name is removed from dbus

Within each flow a set of actions can be configured. These are executed in the order as defined in yaml

  • log for logging message
  • context_set to set variables
  • mqtt_publish to publish a mqtt message

Global flows are started even when dbus2mqtt is not subscribed to any dbus objects. An example for global flows:

Global flow
flows:
  - name: Example flow
    triggers:
      - type: schedule
        interval: {seconds: 5}
    actions:
      - type: log
        msg: hello from example flow

Subscription based flows are started when dbus2mqtt is subscribed to one or more dbus objects. No matter the number of dbus objects subscribed, there is at most one flow instance running.

Subscription based flows
dbus:
  subscriptions:
    - bus_name: org.mpris.MediaPlayer2.*
      path: /org/mpris/MediaPlayer2
      flows:
        - name: Example flow
          triggers:
            - type: schedule
              interval: {seconds: 5}
          actions:
            - type: log
              msg: hello from example flow

Some action parameters allow the use of templating. When supported, it is documented for each individual trigger and action. See templating for further templating details.

Contional flows

Flow actions can be conditionally executed. The conditions parameter accepts either a templated string or list of strings. When using a list of templated strings, all expressions must evaluate to True for actions to be executed.

Subscription based flows
dbus:
  subscriptions:
    - bus_name: org.mpris.MediaPlayer2.*
      path: /org/mpris/MediaPlayer2
      flows:
        - name: Example conditional flow
          triggers:
            - type: dbus_object_added
          conditions:
            - "{{ 'vlc' in bus_name }}"
          actions:
            - type: log
              msg: VLC player registered

Next: flow actions & flow triggers