Turn a light off after a period of time with AppDaemon API


I tried to search for something like what I’m looking to do, unsuccessfully.
Just wants to turn a light off after a period of time (let’s say 10 sec).

The following is my code:

  module: lights
  class: TurnOffLights


import appdaemon.plugins.hass.hassapi as hass

# Turn Off Lights App
# Args:

class TurnOffLights(hass.Hass):

  def initialize(self):
    # Listen for a state change involving light.office1 changing to state on and remaining on for a minute
    # Trigger the delay immediately if the light is already on
    self.listen_state(self.light_off_from_on,"switch.47023800a4cf12b15cac_3",new='on', old='off')

  def light_off_from_on(self, entity, attribute, old, new, kwargs):
    self.run_in(self.light_off, 10)

  def light_off(self):

Try this.

self.run_in(self.light_off, seconds=10)

Although, yours should work. Your listener probably needs entity=.

self.listen_state(self.light_off_from_on, entity="switch.47023800a4cf12b15cac_3", new='on', old='off')

Thanks, but still not working :sob:

anything in your logs?

just noticed that your missing the required kwargs argument for callbacks

  def light_off(self, kwargs):

Thanks !!
It’s working now.

As for log file… where should I find the errors/info related to:

  1. Appdaemon ?
  2. Python syntax errors ?

In the Home Assistant log or here /config/appdaemon/info.log

The following is what I set in AppDaemon.yaml file:

  logfile: /config/appdaemon/info.log
  errorfile: /config/appdaemon/info.log

appdaemon info is in logfile
python errors will show up in error file.

Thank you very much Petro.

If I write something like that , the “Hello from AppDaemon” should appear in logfile: /config/appdaemon/info.log ?

class HelloWorld(hass.Hass):
  def initialize(self):
     self.log("Hello from AppDaemon")

Why don’t you just try it? :slight_smile: