Announcement: AppDaemon 3.0.2!

Can you kindly post your plugin configuration in appdaemon.yaml?

Regards

MQTT:
      type: mqtt
      client_host: '192.168.2.116'
      client_user: 'xxxx'
      client_password: 'xxxx'
      namespace: mqtt
      client_topics:
         #- home/appdaemon
         - 'monitor/garage/58:C5:CB:A4:63:68'
         - monitor/gg-mon

Should actually be

self.mqtt_publish("monitor/gg-mon", "100", qos = 0, retain = True, namespace = "mqtt")

You spelt namespace wrong.

Also to avoid writing namespace everywhere, you could just use the self.set_namespace('mqtt') at the beginning of the initialise function.

Lastly if your system runs, you might create a loop in your system so be careful.

Regards

Thanks @Odianosen25, That was a silly mistake, It is working now

import appdaemon.plugins.mqtt.mqttapi as mqtt
class mqtttest(mqtt.Mqtt):

  def initialize(self):
       self.set_namespace('mqtt')
       self.handle = self.listen_event(self.mqtt_callback, 'MQTT_MESSAGE')
       
  def mqtt_callback(self, event_name, data, kwargs):
       # do something with the received payload
       self.log("Sending back to mqtt")
       self.mqtt_publish("monitor/gg-mon", "100", qos = 0, retain = True)

Lastly if your system runs, you might create a loop in your system so be careful.

:smile:Already did that

It happens, and glad I could help :slight_smile:

Hi guys, sorry to revive this old topic,

I copied and pasted @anilet code and it doesn’t seem to work for me,
It does connect properly to the mqtt broker but no message sent or received.

Here is my appdaemon log.

2019-08-25 07:25:32.874153 INFO AppDaemon Version 3.0.5 starting
2019-08-25 07:25:32.874331 INFO Configuration read from: /config/appdaemon/appdaemon.yaml
2019-08-25 07:25:32.874947 INFO AppDaemon: Starting Apps
2019-08-25 07:25:32.876810 INFO AppDaemon: Loading Plugin HASS using class HassPlugin from module hassplugin
2019-08-25 07:25:32.942734 INFO AppDaemon: HASS: HASS Plugin Initializing
2019-08-25 07:25:32.943012 INFO AppDaemon: HASS: HASS Plugin initialization complete
2019-08-25 07:25:32.943124 INFO AppDaemon: Loading Plugin MQTT using class MqttPlugin from module mqttplugin
2019-08-25 07:25:32.945427 INFO AppDaemon: MQTT: MQTT Plugin Initializing
2019-08-25 07:25:32.945563 INFO AppDaemon: MQTT: Using 'test status' as Will Topic
2019-08-25 07:25:32.945627 INFO AppDaemon: MQTT: Using 'test status' as Birth Topic
2019-08-25 07:25:32.946056 INFO Dashboards are disabled
2019-08-25 07:25:32.946142 INFO API is disabled
2019-08-25 07:25:32.950048 INFO AppDaemon: HASS: Connected to Home Assistant 0.97.2
2019-08-25 07:25:32.951688 INFO AppDaemon: MQTT: Connected to Broker at URL 192.168.68.102:1883
2019-08-25 07:25:32.953030 INFO AppDaemon: Got initial state from namespace mqtt
2019-08-25 07:25:32.953178 INFO AppDaemon: MQTT: MQTT Plugin initialization complete
2019-08-25 07:25:32.969788 INFO AppDaemon: Got initial state from namespace default
2019-08-25 07:25:34.980681 INFO AppDaemon: Reading config
2019-08-25 07:25:34.981559 INFO AppDaemon: /config/appdaemon/apps/Zwave to Mqtt/mqtttest.yaml added or modified
2019-08-25 07:25:34.981650 INFO AppDaemon: /config/appdaemon/apps/Zwave to Mqtt/mqtttest.yaml added or modified
2019-08-25 07:25:34.981709 INFO AppDaemon: App 'mqtttest' added
2019-08-25 07:25:34.981792 INFO AppDaemon: Adding /config/appdaemon/apps to module import path
2019-08-25 07:25:34.981883 INFO AppDaemon: Adding /config/appdaemon/apps/Zwave to Mqtt to module import path
2019-08-25 07:25:34.982019 INFO AppDaemon: Loading App Module: /config/appdaemon/apps/Zwave to Mqtt/mqtttest.py
2019-08-25 07:25:34.985070 INFO AppDaemon: Initializing app mqtttest using class mqtttest from module mqtttest
2019-08-25 07:25:34.985456 INFO AppDaemon: App initialization complete

this is what my config looks like.

secrets: /config/secrets.yaml
log:
  logfile: /config/appdaemon/logs/logfile.log
  errorfile: /config/appdaemon/logs/errorfile.log
  log_size: 100000
  log_generations: 2
appdaemon:
  threads: 10
  app_dir: /config/appdaemon/apps
  plugins:
    HASS:
      type: hass
      ha_url: http://hassio/homeassistant
      token: MYTOKEN
    MQTT:
      type: mqtt
      namespace: mqtt
      client_host: 192.168.68.102
      client_id: test
      client_password: MYPASSWORD
      namespace: mqtt
      client_topics:
      - monitor/#
      - monitor/gg-mon

mqtttest.yaml

mqtttest:
  module: mqtttest
  class: mqtttest

mqtttest.py

import appdaemon.plugins.mqtt.mqttapi as mqtt
class mqtttest(mqtt.Mqtt):

  def initialize(self):
       self.set_namespace('mqtt')
       self.handle = self.listen_event(self.mqtt_callback, 'MQTT_MESSAGE')
       
  def mqtt_callback(self, event_name, data, kwargs):
       # do something with the received payload
       self.log("Sending back to mqtt")
       self.mqtt_publish("monitor/gg-mon", "100", qos = 0, retain = True)

I don’t get any error message, but the app is not listening on the mqtt topic.
Ive tried just a simple app like this and doesn’t work either.

import appdaemon.plugins.mqtt.mqttapi as mqtt
class mqtttest(mqtt.Mqtt):

  def initialize(self):
       self.set_namespace('mqtt')
       self.mqtt_publish("monitor/gg-mon", "100", qos = 0, retain = True)

I have spent many hours trying to figure this out.
Does anyone have any idea what could be wrong?
Thanks for your help.

The client_topics indentation looks faulty. Can you take it in two steps or one step and try again.

Regards

Thank you @Odianosen25
but it didn’t work,

import appdaemon.plugins.mqtt.mqttapi as mqtt
class mqtttest(mqtt.Mqtt):

  def initialize(self):
     self.set_namespace('mqtt')
     self.handle = self.listen_event(self.mqtt_callback, 'MQTT_MESSAGE')

  def mqtt_callback(self, event_name, data, kwargs):
     # do something with the received payload
     self.log("Sending back to mqtt")
     self.mqtt_publish("monitor/gg-mon", "100", qos = 0, retain = True)

Mqtt broker
image
I published a message to trigger the callback but no success

Any other idea?
Thanks

You have double namespace set to mqtt. Not sure that affects it, but pls remove 1. Did you make the change in the appdaemon.yaml file?

Yes I changed it previously, and still not working.

   MQTT:
     type: mqtt
     namespace: mqtt
     client_host: 192.168.68.102
     client_id: test
     client_password: test
     client_topics:
     - monitor/#
     - monitor/gg-mon/#
     - monitor/
     - monitor/gg-mon/

I also did a fresh install of hassio and appdaemon on another pc and still couldn’t get it to work.
I appreciate your help.

No it’s still not indented. It should start from the hyphen and move two steps to the right

client_topics:
  - monitor/#

Regards

I did a 2 space indent, but after appdaemon restart, it moved back to no space automatically.
I have tried a 4 space indent also.

Automatically? Like seriously? That makes no sense. If it’s not indented, then I wouldn’t expect it to work.

Another option, comment out client_topics, which means it will subscribe to all topics and see if you get anything.

Regards

I commented out and still not working, I have tried to use a different editor to fix the indentation problem but it always change back after appdaemon restart, weird!!.

do you have a simple working app you can share,
I could just try copy and paste see if it works?

Thanks again

Hi @Odianosen25,
I found the problem, well, the source of the problem anyway.
I removed and reinstalled my mqtt broker addons and it worked.
I’m not sure what was wrong, maybe something to do with the with acl and access control list.

Anyways
Thanks for your help and your time.

Oh that’s great. Glad you sorted it out