Have MQTT messages showing up as events

I have a mqtt broker defined in my configuration, and it receives data all right. Some ‘topics’ are ‘sent’ to sensors, which also works fine.

However, there are some messages (topics) that I’d like to have appear on the event bus. Is it possible to somehow “forward” these to the event bus?

In the meanwhile, I managed to achieve this with an automation:

- alias: ALIAS_NAME
  description: 'some desc'
  mode: single
  trigger:
    - platform: mqtt
      topic: 'abc/+/onoff'
  condition: []
  action:
    - event: event_name
      event_data:
        topic: "{{ trigger.topic }}"
        payload: "{{ trigger.payload }}"

Just for reference, if someone else stumbles across this post, here is the background of my problem:

I am using AppDaemon for all automations. The reason is that I feel comfortable programming in Python, and that it is quite easy to produce relatively complex automations with this. For me this is easier that writing complex yaml files.

AppDaemon runs in a separate docker container, and HomeAssistant already uses Mosquitto for some devices that are integrated using mqtt. So the link to the broker already is established in HA.

In principle, AppDaemon can access the Mosquitto broker directly. However, this requires multiple inheritance with its own complications, and the docker network configuration would become more complicated in my particular case (AD cannot access the broker as it is now). So listening to the HA-forwarded events (which I need to do anyways) is easier.

1 Like