Appdaemon class mqtt+hass = TypeError: listen_state() takes from 2 to 3 positional arguments but 4 were given

Hi all!

I updated Appdaemon and after that most of my apps doesnt work:

Error log:

2019-12-27 21:55:33.643391 WARNING AppDaemon: Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/appdaemon/", line 1581, in init_object
  File "/home/user/.homeassistant/conf/apps/PIRs/", line 7, in initialize
    self.listen_state(self.puck_living_room, "zigbee2mqtt/Kitchen PIR", new = "toggle")
  File "/usr/local/lib/python3.6/dist-packages/appdaemon/plugins/mqtt/", line 66, in listen_state
    return super(Mqtt, self).listen_state(namespace, cb, entity, **kwargs)
TypeError: listen_state() takes from 2 to 3 positional arguments but 4 were given

One of the app (simplified):

import appdaemon.plugins.mqtt.mqttapi as mqtt
import appdaemon.plugins.hass.hassapi as hass

class PIR_Living_Room(mqtt.Mqtt, hass.Hass):

def initialize(self):
		self.listen_state(self.pir_living_room, "zigbee2mqtt/Kitchen_PIR", new = "ON")
	def pir_living_room(self, entity, attribute, old, new, kwargs):
		self.turn_on("light.0x000b57fffe22d28c_light", brightness_pct = 85, transition = 3) 
		self.turn_on("light.0x000d6ffffea91d6e_light", brightness_pct = 95, transition = 3) 
		self.turn_on("light.0x000d6ffffec7c83d_light", brightness_pct = 95, transition = 3) 

It’s because theres two plugin in one class, right?
That worked before i updated, now it doesn’t. :frowning:
I saw posts about a fix (splitting it into two app), but thats kinda shitty ( i have 30-35 apps).

Is there a way to fix my apps without spitting them up?

Any help would be greatly appreciated!

My listen_event in a similar app is

        for atopic in self.args["motion_topics"]:
            self.listen_event(self.motion_detected, "MQTT_MESSAGE",
                    namespace = "mqtt", topic = atopic)

I also switched to the newest version and am now slowly migrating my apps. I use it like this, and I think it’s also a method recommened by the AppDaemon core team:

import adbase as ad

class AppBase(ad.ADBase):
    """Define a base automation object."""

    def initialize(self) -> None:
        self.adbase = self.get_ad_api()
        self.hass = self.get_plugin_api("HASS")
        self.mqtt = self.get_plugin_api("MQTT")


See the comment here:

1 Like

Right now i’m just service calling mqtt thru hass, but this definetly the way i will migrate to.

Thank you!!

i think the biggest problem is this line:

		self.listen_state(self.pir_living_room, "zigbee2mqtt/Kitchen_PIR", new = "ON")

the second position should be an entity and an entity always contains a dot like
its possible that you get a misleading error because of that.
inheriting from more then 1 plugin was never working correct, and you probably have had problems that you didnt notice. (it also was never needed to inherit from more then 1 plugin)

in the case from this app you dont need the mqtt plugin at all, so why do you use it there?

in case you really want to use more then 1 plugin, then indeed you can do it like @Burningstone suggests.

its the new app style. old app style apps (inheriting from a plugin, will still be supported, like they were supported)