Hello! I’ve been having issues trying to capture MQTT events from my Mosquitto broker. I can confirm messages are arriving by checking the Mosquitto configuration page. I also set up an external MQTT client app to listen for those topics. Publishing a test message straight from the configuration console generates a call_service response, but not the MQTT_MESSAGE event that I’m looking for. I’m thinking it’s related to a configuration issue, but I’ve had no luck getting past this point. Any thoughts or suggestions would be greatly appreciated.
Quick edit:
I’ve also tried listening to events with the appropriate event type and namespace specified for mqtt, however I’ve seen no responses whatsoever doing this. Sorry, should’ve made that clear in my initial post.
self.listen_event(self.msg_callback, "MQTT_MESSAGE", namespace = "mqtt")
appdaemon.yaml
secrets: /config/secrets.yaml
appdaemon:
plugins:
HASS:
type: hass
MQTT:
type: mqtt
namespace: mqtt
client_host: core-mosquitto
user_name: user
client_password: pass
event_name: MQTT_MESSAGE
http:
url: http://127.0.0.1:5050
admin:
api:
hadashboard:
logs:
main_log:
filename: /config/appdaemon/logs/appdaemon.log
error_log:
filename: /config/appdaemon/logs/error.log
access_log:
filename: /config/appdaemon/logs/access.log
diag_log:
filename: /config/appdaemon/logs/diag.log
lora.py
import hassapi as hass
import mqttapi as mqtt
class LoRaApp(mqtt.Mqtt, hass.Hass):
def initialize(self):
self.log("Initializing LoRa app")
self.call_service("mqtt/subscribe", namespace = "mqtt", topic = "application/#")
self.listen_event(self.msg_callback)
self.mqtt_publish("application/1/light", "ON")
self.log("Initialization complete")
def msg_callback(self, event_name, data, kwargs):
self.log("Test Message received " + event_name)
self.log(data)
def join_callback(self, event_name, data, kwargs):
self.log("Join message received")
appdaemon.log
2021-05-25 17:20:40.679037 INFO AppDaemon: Starting API
2021-05-25 17:20:40.700453 INFO AppDaemon: Starting Admin Interface
2021-05-25 17:20:40.705472 INFO AppDaemon: Starting Dashboards
2021-05-25 17:20:40.877127 INFO HASS: Connected to Home Assistant 2021.5.5
2021-05-25 17:20:40.995012 INFO MQTT: Connected to Broker at URL core-mosquitto:1883
2021-05-25 17:20:41.292628 INFO HASS: Evaluating startup conditions
2021-05-25 17:20:41.364217 INFO HASS: Startup condition met: hass state=RUNNING
2021-05-25 17:20:41.368526 INFO HASS: All startup conditions met
2021-05-25 17:20:41.805619 INFO AppDaemon: Got initial state from namespace mqtt
2021-05-25 17:20:41.823738 INFO MQTT: MQTT Plugin initialization complete
2021-05-25 17:20:41.828030 INFO AppDaemon: Got initial state from namespace default
2021-05-25 17:20:41.841452 INFO AppDaemon: App 'hello_world' added
2021-05-25 17:20:42.799457 INFO AppDaemon: App 'lora_app' added
2021-05-25 17:20:42.805265 INFO AppDaemon: Found 2 total apps
2021-05-25 17:20:42.808998 INFO AppDaemon: Starting Apps with 2 workers and 2 pins
2021-05-25 17:20:42.814690 INFO AppDaemon: Running on port 5050
2021-05-25 17:20:43.843105 INFO AppDaemon: Scheduler running in realtime
2021-05-25 17:20:43.856465 INFO AppDaemon: Adding /config/appdaemon/apps to module import path
2021-05-25 17:20:43.869543 INFO AppDaemon: Loading App Module: /config/appdaemon/apps/hello.py
2021-05-25 17:20:43.921649 INFO AppDaemon: Loading App Module: /config/appdaemon/apps/lora.py
2021-05-25 17:20:45.032799 INFO AppDaemon: Initializing app hello_world using class HelloWorld from module hello
2021-05-25 17:20:45.048854 INFO AppDaemon: Initializing app lora_app using class LoRaApp from module lora
2021-05-25 17:20:47.558678 INFO hello_world: Hello from AppDaemon
2021-05-25 17:20:47.566813 INFO hello_world: You are now ready to run Apps!
2021-05-25 17:20:47.583225 INFO lora_app: Initializing LoRa app
2021-05-25 17:20:47.696264 INFO lora_app: Initialization complete
2021-05-25 17:20:47.705482 INFO AppDaemon: App initialization complete
2021-05-25 17:20:48.773850 INFO lora_app: Test Message received call_service
2021-05-25 17:20:49.881943 INFO lora_app: {'domain': 'mqtt', 'service': 'publish', 'service_data': {'topic': 'application/1/light', 'payload': 'ON'}, 'metadata': {'origin': 'LOCAL', 'time_fired': '2021-05-26T00:20:47.648233+00:00', 'context': {'id': '8d59de088cf986252c45750c81415f13', 'parent_id': None, 'user_id': '6ecf68d6bc334414966220ca2358715e'}}}