AppDaemon with 0.83.3 with Python venv listen_state() missing 1 required positional argument: 'entity'

Dear,

I get an error message for a simple test app

2018-12-04 09:41:40.860812 INFO AppDaemon: App initialization complete
  File "/home/pi/appdaemon_venv/lib/python3.5/site-packages/appdaemon/appdaemon.py", line 1581, in init_object
  File "/home/pi/.homeassistant/apps/test2.py", line 15, in initialize
    init()
    self.listen_state(self.a_off, "input_boolean.motion", new="off")
TypeError: listen_state() missing 1 required positional argument: 'entity'


config:
    pi@raspberrypi-ibmas:~/appdaemon_venv/logs $ cat /home/pi/.homeassistant/appdaemon.yaml
    secrets: /home/pi/.homeassistant/secrets.yaml
    log:
      accessfile: /home/pi/appdaemon_venv/logs/access.log
      errorfile: /home/pi/appdaemon_venv/logs/error.log
      logfile: /home/pi/appdaemon_venv/logs/appdaemon.log
      log_generations: 3
      log_size: 1024
    appdaemon:
      logfile: STDOUT
      errorfile: STDERR
      threads: 10
      api_port: 5000
      api_key: !secret http_password
      app_dir: /home/pi/.homeassistant/apps
      plugins:
        HASS:
          type: hass
          ha_url: http://127.0.0.1:8123
          token: !secret appdaemon_token
    #      namespace: default

test2.py
pi@raspberrypi-ibmas:~/appdaemon_venv/logs $ cat /home/pi/.homeassistant/apps/test2.py
import appdaemon.appapi as appapi
#import homeassistant.appapi as appapi

#
# Hello World App
#
# Args:
#

class HelloWorld(appapi.AppDaemon):

  def initialize(self):
      self.log("Hello from AppDaemon")
      self.log("You are now ready to run Apps!")
      self.listen_state(self.a_off, "input_boolean.motion", new="off")
      self.listen_state( self.a_on , "input_boolean.motion", new="on" )
      self.listen_state(self.a_held, "input_boolean.motion", new="on", duration=1)

  def a_off(self, old, new ):
    self.log("Button A released")

  def a_on(self, new):
    self.log("Button A pressed")

  def a_held(self, new):
    self.log("Button A held")

Your callback functions need to match the signature defined here.

Edit: Fixed link

still the same error

i@raspberrypi-ibmas:~/appdaemon_venv/logs $ cat error.log
2018-12-04 10:12:03.966865 WARNING AppDaemon: Traceback (most recent call last):
File “/home/pi/appdaemon_venv/lib/python3.5/site-packages/appdaemon/appdaemon.py”, line 1581, in init_object
init()
File “/home/pi/.homeassistant/apps/test2.py”, line 15, in initialize
self.listen_state(self.a_off, “input_boolean.motion”, new=“off”)
TypeError: listen_state() missing 1 required positional argument: ‘entity’

2018-12-04 10:12:03.968194 WARNING AppDaemon: ------------------------------------------------------------

pi@raspberrypi-ibmas:~/.homeassistant/apps $ cat test2.py
import appdaemon.appapi as appapi
#import homeassistant.appapi as appapi

#
# Hello World App
#
# Args:
#

class HelloWorld(appapi.AppDaemon):

  def initialize(self):
      self.log("Hello from AppDaemon")
      self.log("You are now ready to run Apps!")
      self.listen_state(self.a_off, "input_boolean.motion", new="off")
      self.listen_state( self.a_on , "input_boolean.motion", new="on" )
      self.listen_state(self.a_held, "input_boolean.motion", new="on", duration=1)

  def a_off(self, entity, attribute, old, new, kwargs):
    self.log("Button A released")

  def a_on(self, entity, attribute, old, new, kwargs):
    self.log("Button A pressed")

  def a_held(self, entity, attribute, old, new, kwargs):
    self.log("Button A held")

Sorry, wrong error - you would find that problem later.

You don’t say which version of AD you are running, but my current base class (for AD 3.0.2) is

import appdaemon.plugins.hass.hassapi as hass

class BatteryLevel(hass.Hass):

Hej this app is just an example which I have found in a example blog,

so import appdaemon.appapi as appapi seems to be correct

2018-12-04 11:10:28.523101 INFO AppDaemon Version 3.0.2 starting
2018-12-04 11:10:28.523923 INFO Configuration read from: /home/pi/.homeassistant/appdaemon.yaml
2018-12-04 11:10:28.529100 INFO AppDaemon: Starting Apps
2018-12-04 11:10:28.530757 WARNING config_dir: /home exists, but is not writeable, owner: root
2018-12-04 11:10:28.538956 INFO AppDaemon: Loading Plugin HASS using class HassPlugin from module hassplugin
2018-12-04 11:10:28.738573 INFO AppDaemon: HASS: HASS Plugin Initializing
2018-12-04 11:10:28.739749 INFO AppDaemon: HASS: HASS Plugin initialization complete
2018-12-04 11:10:28.740663 INFO Dashboards are disabled
2018-12-04 11:10:28.741116 INFO Starting API
2018-12-04 11:10:28.770379 INFO AppDaemon: HASS: Connected to Home Assistant 0.83.3
2018-12-04 11:10:28.950481 INFO AppDaemon: Got initial state from namespace default
2018-12-04 11:10:30.987023 INFO AppDaemon: Reading config
2018-12-04 11:10:30.993148 INFO AppDaemon: /home/pi/.homeassistant/apps/apps.yaml added or modified
2018-12-04 11:10:30.993783 INFO AppDaemon: /home/pi/.homeassistant/apps/apps.yaml added or modified
2018-12-04 11:10:30.994884 INFO AppDaemon: App ‘test2’ added
2018-12-04 11:10:30.995521 INFO AppDaemon: Adding /home/pi/.homeassistant/apps to module import path
2018-12-04 11:10:30.997842 WARNING AppDaemon: No app description found for: /home/pi/.homeassistant/apps/hello.py - ignoring
2018-12-04 11:10:30.998364 WARNING AppDaemon: No app description found for: /home/pi/.homeassistant/apps/door_notifications.py - ignoring
2018-12-04 11:10:30.998815 WARNING AppDaemon: No app description found for: /home/pi/.homeassistant/apps/test.py - ignoring
2018-12-04 11:10:30.999241 WARNING AppDaemon: No app description found for: /home/pi/.homeassistant/apps/motion.py - ignoring
2018-12-04 11:10:30.999663 INFO AppDaemon: Loading App Module: /home/pi/.homeassistant/apps/test2.py
2018-12-04 11:10:31.023554 INFO AppDaemon: Initializing app test2 using class HelloWorld from module test2
2018-12-04 11:10:31.242458 INFO test2: Hello from AppDaemon
2018-12-04 11:10:31.246625 INFO test2: You are now ready to run Apps!
2018-12-04 11:10:31.251007 INFO AppDaemon: App initialization complete

But which version of AD was the example for? It looks familiar, so I suspect it was an earlier version.

You should check with the examples downloaded with the appdaemon.

Hej

thats it!

import appdaemon.appapi as appapi

class MyClass(appapi.AppDaemon):
...

to:

import appdaemon.plugins.hass.hassapi as hass

class MyClass(hass.Hass):
...

sorry for not reading carefully !!!!
2 Likes