Self.listen_state from documentation throws TypeError: listen_state() missing 2 required positional arguments: 'cb' and 'entity'

Hello,
I just tried to play around AppDaemon and wanted to write my first app. However, I have came to a big problem with registering callback on state change. Could someone here help me with it?

Following some examples I was always getting following error:

2018-03-15 21:10:15.998168 WARNING AppDaemon: Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1927, in check_app_updates
    self.init_object(app)
  File "/usr/local/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1477, in init_object
    self.objects[name]["object"].initialize()
  File "/conf/apps/test.py", line 6, in initialize
    self.listen_state(self.motion, "binary_sensor.drive", new = "on")
TypeError: listen_state() missing 1 required positional argument: 'entity'

So I have turned back to API documentation, which claims I cane use listen_state with only callback as a parameter, but it still throws:

   2018-03-15 21:26:43.262855 WARNING AppDaemon: Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1927, in check_app_updates
    self.init_object(app)
  File "/usr/local/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1477, in init_object
    self.objects[name]["object"].initialize()
  File "/conf/apps/test.py", line 14, in initialize
    self.listen_state(self, self.my_callback)
TypeError: listen_state() missing 1 required positional argument: 'entity'

What do I do wrong about registering the callback?

  def initialize(self):
    self.log("init")
    self.log("init1")
    self.listen_state(self.my_callback)
    self.listen_state(self, cb=self.my_callback, entity="switch.s1")

its just 1 line:

self.listen_state(self.your_callback,“your_entity”,new=“something”)

to get on your way you can read the docs:
http://appdaemon.readthedocs.io/en/latest/index.html

or my tutorial:

Thank you for prompt reply!

I have actually followed your tutorial, but it seems, that someting stil goes wrong ;/

I have tried:

import appdaemon.appapi as appapi
class myapp(appapi.AppDaemon):
def initialize(self):
self.listen_state(self.my_callback,“switch.s1”,new=“1”)
def my_callback(self, entity, attribute, old, new, kwargs):
self.log(“callback”)

But I still get the same error:

2018-03-16 20:57:01.997066 WARNING AppDaemon: Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/appdaemon/appdaemon.py”, line 1927, in check_app_updates
self.init_object(app)
File “/usr/local/lib/python3.6/site-packages/appdaemon/appdaemon.py”, line 1477, in init_object
self.objects[name][“object”].initialize()
File “/conf/apps/test.py”, line 9, in initialize
self.listen_state(self.my_callback,“switch.s1”,new=“1”)
TypeError: listen_state() missing 1 required positional argument: ‘entity’
2018-03-16 20:57:01.997279 WARNING AppDaemon: ---------------------------

Is there any problem with the fact I try to listen to change of state of generic switch?

I run version:
AppDaemon Version 3.0.0b4

the first words from my tutorial:

This tutorial is written for appdaemon version 2. There have been some changes in appdaemon 3. That doesnt effect much from this tutotial, but 2 things should be changed if you use version 3: when you read the line:

import appdaemon.appapi as appapi
replace that with:

import appdaemon.plugins.hass.hassapi as hass
and when you see:

appapi.AppDaemon
replace that with:

hass.Hass
1 Like

mea culpa!

Thank you for your great answer and forgiveness for my ignorance on such important matter as version disclaimer.

no problem when AD 3 is officially released ill rewrite it all :wink: