TypeError: 'NoneType' object is not callable in appdaemon

Hi!

I’m trying my first appdaemon script and I get the following error:

Unexpected error in worker for App app_abshum:
Traceback (most recent call last):File "/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py", line 518, in worker
function(ha.sanitize_timer_kwargs(args["kwargs"]))
TypeError: 'NoneType' object is not callable

This is my script. It’s supposed to get some weather parameters, calculate the absolute humidity and set some sensors to the result.

import appdaemon.appapi as appapi
from atmos import calculate
import datetime

class App_Abshum(appapi.AppDaemon):
    def initialize(self):
        time = datetime.time(0,0,0)
        self.run_minutely(self.abshum(), time)
    
    def abshum(self):
        self.p_out  = float(self.get_state('sensor.yr_pressure'))
        self.T_out  = float(self.get_state('sensor.yr_temperature'))
        self.RH_out = float(self.get_state('sensor.yr_humidity'))
        self.p_in   = float(self.p_out)    # self.get_state('sensor.keller_pressure')
        self.T_in   = float(self.get_state('sensor.keller_temp'))
        self.RH_in  = float(self.get_state('sensor.keller_humid'))
        
        abshum_in  = calculate('AH', RH =self.RH_in,  p=self.p_in,  T=self.T_in +273.15, debug=True)[0]
        abshum_out = calculate('AH', RH =self.RH_out, p=self.p_out, T=self.T_out+273.15, debug=True)[0]
        
        self.set_state('sensor.abshum_in',  state=abshum_in)
        self.set_state('sensor.abshum_out', state=abshum_out)
        
        diff_abshum = abshum_in - abshum_out
        share_abshum = diff_abshum / abshum_in * 100.
        
        if diff_abshum > 0:
            self.set_state('binary_sensor.fenster_keller', state='off')
        else:
            self.set_state('binary_sensor.fenster_keller', state='on')
            
        self.set_state('sensor.share_abshum', state=share_abshum)

and this is my appdaemon.yaml

AppDaemon:
 app_dir: 
 errorfil: STDERR
 threads: 10
#  latitude = 
#  longitude = 
#  elevation =  
#  time_zone = 
 logfile:  appdaemon.log # '/home/pi/appdaemon/log/appdaemon.log'
 disable_apps: 0

HASS:
 ha_url: http://192.168.1.**********
 ha_key: ************

HADashboard:
 dash_url: http://192.168.1.*********

# Apps
hello_world:
 module: hello
 class: HelloWorld
 
app_abshum:
 module: app_abshum
 class: App_Abshum

Any idea? :grinning:

Hi there - can you post the whole error in the log please?

2017-07-30 21:06:00.011084 WARNING Unexpected error in worker for App app_abshum:
2017-07-30 21:06:00.011734 WARNING Worker Ags: {'function': None, 'kwargs': {'interval': 60}, 'type': 'timer', 'id': UUID('d188840a-3c0a-41fc-9a53-68c4af73b914'), 'name': 'app_abshum'}
2017-07-30 21:06:00.012247 WARNING ------------------------------------------------------------
2017-07-30 21:06:00.013105 WARNING Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py", line 518, in worker
function(ha.sanitize_timer_kwargs(args["kwargs"]))
TypeError: 'NoneType' object is not callable

That’s the wrong way to use a callback - try this:

self.run_minutely(self.abshum, time)

Ok I changed that. Now I get:

2017-07-30 21:42:00.010828 WARNING Unexpected error in worker for App app_abshum:
2017-07-30 21:42:00.011530 WARNING Worker Ags: {'type': 'timer', 'kwargs': {'interval': 60}, 'function': <bound method App_Abshum.abshum of <app_abshum.App_Abshum object at 0x75a82eb0>>, 'name': 'app_abshum', 'id': UUID('6d679d43-061e-4a0b-a260-c98b7ee47d6a')}
2017-07-30 21:42:00.012068 WARNING ------------------------------------------------------------
2017-07-30 21:42:00.017297 WARNING Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py", line 518, in worker
function(ha.sanitize_timer_kwargs(args["kwargs"]))
TypeError: abshum() takes 1 positional argument but 2 were given
2017-07-30 21:42:00.018159 WARNING ------------------------------------------------------------

I’m not really an objective oriented python programmer :grinning:

Ok I had to add @staticmethod before my def abshum(self).
I don’t understand but it calls the function now. Hint taken from here:

Now I get the following error:

2017-07-30 22:07:00.017443 WARNING Unexpected error in worker for App app_abshum:
2017-07-30 22:07:00.019214 WARNING Worker Ags: {'name': 'app_abshum', 'type': 'timer', 'kwargs': {'interval': 60}, 'function': <function App_Abshum.abshum at 0x7606a2b8>, 'id': UUID('102a8ce5-469a-4616-92e6-a93f7b686432')}
2017-07-30 22:07:00.019899 WARNING ------------------------------------------------------------
2017-07-30 22:07:00.026115 WARNING Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py", line 518, in worker
function(ha.sanitize_timer_kwargs(args["kwargs"]))
File "/home/pi/appdaemon/conf/apps/app_abshum.py", line 12, in abshum
self.p_out  = float(self.get_state('sensor.yr_pressure'))
AttributeError: 'dict' object has no attribute 'get_state'
2017-07-30 22:07:00.026881 WARNING ------------------------------------------------------------

I thought self.get_state() was the method to use here? Like shown here:
https://github.com/home-assistant/appdaemon/blob/dev/API.md#get_state

What am I doing wrong? Is it because of the @staticmethod that self.get_state can’t call the functions of appapi.AppDaemon anymore?

The 2nd error was because you passed a parameter time to ashbum but you didn;t declare that parameter in the definition ashbum. You do not need to use @static method - that just hides the problem.