Basic API question

I’m working on basic scripts with version 3.0 following the tutorial but am having problems.

Here is my apps.yaml file:

curio:
  module: curio
  class: Curio_cabinet_light

Here is the python script:

import appdaemon.plugins.hass.hassapi as hass
import datetime

class Curio_cabinet_light(hass.Hass):

  def initialize(self):
    #
    # Configure two callbacks.  The first occurs 30 minutes after sunset.  The
    # second occurs at 10PM tonight (this assumes that sunset + 30 minutes always
    # occurs before 10PM.
    #
    self.run_at_sunset(self.light_on, offset = 30 * 60)
    when = datetime.datetime.combine(datetime.date.today(), datetime.time(22, 0, 0))
    self.run_at(self.light_off, when)

  def light_on(self, entity, attribute, old, new, kwargs):
    """
    Post-sunset callback
    """
    self.turn_on("light.curio_cabinet_light")

  def light_off(self, entity, attribute, old, new, kwargs):
    """
    Time to turn off the light callback
    """
    self.turn_off("light.curio_cabinet_light")

Here is the error message I get:

2018-03-23 20:10:59.011623 WARNING AppDaemon: ------------------------------------------------------------
2018-03-23 22:00:00.004370 WARNING AppDaemon: ------------------------------------------------------------
2018-03-23 22:00:00.005004 WARNING AppDaemon: Unexpected error in worker for App curio:
2018-03-23 22:00:00.005533 WARNING AppDaemon: Worker Ags: {'kwargs': {}, 'name': 'curio', 'function': <bound method Curio_cabinet_light.light_off of <curio.Curio_cabinet_light object at 0x5e7952d0>>, 'type': 'timer', 'id': UUID('be782a26-2fce-4285-9bae-8237326d0dc1')}
2018-03-23 22:00:00.005960 WARNING AppDaemon: ------------------------------------------------------------
2018-03-23 22:00:00.006681 WARNING AppDaemon: Traceback (most recent call last):
  File "/srv/appdaemon/lib/python3.5/site-packages/appdaemon/appdaemon.py", line 529, in worker
    funcref(self.sanitize_timer_kwargs(app, args["kwargs"]))
TypeError: light_off() missing 4 required positional arguments: 'attribute', 'old', 'new', and 'kwargs'

Is there something obvious I’m doing wrong?

I also have an unrelated question about appdaemon in general. I like the HA card that shows the automations and has switches for each one. Is there a way to present the appdaemon apps in a similar card with switches?

You have the wrong signature for your callbacks - they need to be scheduler style callbacks rather than state style callbacks

My simple module is a lot like this example from the documentation:

import appdaemon.plugins.hass.hassapi as hass
import datetime

# Declare Class
class NightLight(hass.Hass):
  #initialize() function which will be called at startup and reload
  def initialize(self):
    # Create a time object for 7pm
    time = datetime.time(19, 00, 0)
    # Schedule a daily callback that will call run_daily() at 7pm every night
    self.run_daily(self.run_daily_callback, time)

   # Our callback function will be called by the scheduler every day at 7pm
  def run_daily_callback(self, kwargs):
    # Call to Home Assistant to turn the porch light on
    self.turn_on("light.porch")
'''
Can you give me an example of how to use the proper call please?

change that to

def light_on(self, kwargs):

and you are good to go.
but in stead off

    when = datetime.datetime.combine(datetime.date.today(), datetime.time(22, 0, 0))
    self.run_at(self.light_off, when)

you want probably a run_daily.
this will run only once (if you initialise the app before 22:00 ) or not at all (if you initialise the app after 22:00 )
initialise happens only at restart from appdaemon or when you edit the app.

Thanks for the suggestion. That’s what I’ll do.