AppDaemon + MQTT?

SIAP…What is the proper way to integrate AppDaemon and MQTT?

Publish - I assume just call HASS mqtt.publish service
Subscribe - ? Setup a sensor in HASS then have AppDaemon listen for it? Anyway to eliminate the HASS step?


Thanks in advance.

AppDaemon currently does not have the code to integrate directly with MQTT, although it might make sense to do that at some point.

You can certainly call the MQTT publish service in HASS, and I guess your idea of setting up an MQTT sensor then listen for state changes should work well.

i like going sidesteps to.
for instance using tts in appdaemon for a hassversion that doesnt support tts.

but why cutting out hass when it does the function?

eliminate hass from communicating with sensors, switches, etc. and all thats left is python.

You can listen for mqtt_message_received on the event bus, but I think you have to have a sensor defined to subscribe to the topic.
Here is something I use to subscribe to the mqtt message of my motion sensors.

        self.listen_event(self.motion_started, "mqtt_message_received",
                topic = self.args["sensor_topics"],
                payload = self.args["on_payload"],
                constrain_presence = "someone",
                constrain_start_time = "sunset - 00:05:00",
                constrain_end_time = "sunrise")

Hi Andrew,
Does newer version of AD supports MQTT integration?

Hi there - it will soon. I have a pull request for an MQTT plugin that I’ll be merging soon after the beta ends this week so stay tuned!

1 Like


It will really open many new possibilities altogether for home automation using MQTT.

Yaml automation scripts are good but i feel bit too cumbersome many atimes to create complex automation.

If you don’t want to wait for the plugin, you can send mqtt messages to AD now, be sending events from HA. Here is my automation to send OpenMQTT gateway messages

  - alias: Four33 Button
      platform: mqtt
      topic: home/433toMQTT
      event: Four33Button
        payload: '{{ trigger.payload }}'


Is there are PR we can reference. I’m also looking for this.

Edit: Found it. Added mqtt plugin by tschmidty69 · Pull Request #238 · AppDaemon/appdaemon · GitHub

I’m planning on taking a look at this at the weekend.

Does it support certificates? I didn’t notice that option in the pull request.

My mqtt server/broker uses certificates instead of passwords which is why I’m interested.

It doesn’t. Do you use them as client certificates or do you mean it is just using TLS?

As client certificates.

Roger, I’ll give it a poke

MikeA, I added the cert options but don’t really have the time to set something up to test it out.

Thanks for taking the time to work on this. I appreciate it.

I also understand limited time. I’ll try to test your changes this weekend.

I did some testing using the files attached to the pull request on github. I had some initial errors that I was able to resolve but for some reason the mqtt plugin doesn’t try to connect to my local mqtt broker. (It’s not the built-in broker that comes with Homeassistant.)

After an hour or so other responsibilities called…

There was a mqtt error in the appdaemon.log which required that I:

  • comment out lines 45 and 46.
    • line 46 needed to start with self. mqtt_client…
  • I then copied those two lines down to line 60, after the “self.mqtt_client.tls_set” function call because:
    • the mqtt_client object didn’t exist at lines 45/46
    • the tls_insecure_set() function couldn’t be called until the client’s certificate had been added to the mqtt_client object.

After those changes there weren’t anymore errors.

I setup a demo app that runs without errors. It’s basically the demo app that’s with the pull request without the jarvis code. The app is created and enters data into the log file.

As mentioned above, for some reason the mqtt server never receives a connection request.

  • The mqtt server’s logs show a connection from Homeassistant and will show mqtt data posted throught the Homeassistant front end, but nothing from Appdaemon seems to try and connect to it.

This is the the mqtt section from the appdaemon config file:

  type: mqtt
  verbose: True
  mqtt_client_host: ''
  mqtt_client_port: 1883
  mqtt_client_user: mqtt_client
  # mqtt_client_password: !secret mqtt_password -> isn't being used...
  mqtt_client_cert: /home/homeassistant/conf/ca/mqtt_client.crt
  mqtt_client_key:  /home/homeassistant/conf/ca/mqtt_client.key
  mqtt_verify_cert: false
    - $SYS/broker/version

The client password isn’t supplied because certificates are being used.
I don’t know a lot about mqtt but it seems that there’s a broker certificate missing.

  • The mqtt section from the Homeassistnat configuration file has 3 lines:
    certificate: /home/homeassistant/.homeassistant/certs/ca.crt
    client_key: /home/homeassistant/.homeassistant/certs/hass.key
    client_cert: /home/homeassistant/.homeassistant/certs/hass.crt

The first certificate doesn’t seem to be required by the Appdaemon mqtt plugin. My guess is that it verifies the broker to the client. Which made me think that mqtt_verify_cert needs to be “true” - but changing it to true and restarting Appdaemon didn’t change the results.

Hopefully this is of some help.

This is a busy time for our business so I won’t have time to work on this until (maybe) next weekend. Focus on getting the mqtt plugin into Appdaemon without certificates. They can be added later.

Thanks again for trying.

1 Like

Certificate in that case is the ca certificates used to verify trust with the broker. I’t implemented a little odd in HA but in any case I added the option mqtt_ca_certs to configure it. I assume you are not using a standard letsencrypt or otherwise standard trusted certificate? But in any case that should get to the same place as the HA connection.

Unfortunately, there doesn’t seem to be a way to test if the connection is actually made, just the fact that it did not actually make the connection!

i am interested in this. Is it going to work with ?

With hassio, you can install the mosquitto plugin directly. This is more meant to allow appdaemon to be a standalone app without Home Assistant.

Tell us your exact thoughts on how to use this and I am sure we can give you pointers