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:
schedulefor cron based schedulesdbus_signalfor when dbus signal occurobject_addedwhen a new bus_name is registered on dbusobject_removedwhen 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
logfor logging messagecontext_setto set variablesmqtt_publishto publish a mqtt message
Global flows are started even when dbus2mqtt is not subscribed to any dbus objects. An example for global flows:
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.
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.
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