I’m getting better at this, but… I have this script calling a function in another. It works, but fires immediately upon saving, not when the run_daily is set to
With these edits it runs, but immediately. If I remove kwargs, it doesn’t run, but throws the error below
timed_lights.py
import appdaemon.plugins.hass.hassapi as hass
import datetime
class TimedLights(hass.Hass):
#initialize() function which will be called at startup and reload
def initialize(self):
self.lights = self.get_app('Lights')
self.log(self.lights)
self.log("TimedLights Initialized!")
kwargs = {"light_device": "light.pedestal", "light_value": "on", "light_color": "255,0,0", "light_brightness":"255"}
time = datetime.time(13, 26, 10)
self.run_in(self.do_lights(kwargs), 20)
def do_lights(self, kwargs):
self.log("Do Lights")
self.log(self.lights)
self.lights.run_light(kwargs)
lights.py
import appdaemon.plugins.hass.hassapi as hass
class Lights(hass.Hass):
#initialize() function which will be called at startup and reload
def initialize(self):
self.log("Lights Initialized!")
def run_light(self, kwargs):
self.log("In Run_Light")
light_device = kwargs["light_device"]
light_value = kwargs["light_value"]
if "light_color" in kwargs:
light_color = kwargs["light_color"]
if "light_brightness" in kwargs:
light_brightness = kwargs["light_brightness"]
else:
light_brightness = 255
if light_value == "on":
self.turn_on(light_device, brightness = light_brightness)
elif light_value == "off":
self.turn_off(light_device)
Error Log
2018-02-23 15:36:32.733644 WARNING AppDaemon: Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1651, in read_app
self.init_object(name, class_name, module_name, self.app_config)
File "/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1446, in init_object
self.objects[name]["object"].initialize()
File "/config/appdaemon/apps/timed_lights.py", line 13, in initialize
self.run_in(self.do_lights(), 5)
File "/config/appdaemon/apps/timed_lights.py", line 19, in do_lights
self.lights.run_light()
File "/config/appdaemon/apps/lights.py", line 12, in run_light
light_device = kwargs["light_device"]
NameError: name 'kwargs' is not defined
Sorry, I was backtracking and trying to get it working moving forward. Without kwargs I get into run_light in lights.py, but it stops when reading kwargs[“light_device”]. The concept of kwargs is new to me, so I thinking I’m not actually passing or defining them correctly. Sorry, I’m coming from Windows programming land - lol
Error log shows:
2018-02-23 15:52:19.993990 WARNING AppDaemon: ------------------------------------------------------------
2018-02-23 15:53:19.884156 WARNING AppDaemon: ------------------------------------------------------------
2018-02-23 15:53:19.885567 WARNING AppDaemon: Unexpected error during loading of TimedLights:
2018-02-23 15:53:19.886767 WARNING AppDaemon: ------------------------------------------------------------
2018-02-23 15:53:19.890139 WARNING AppDaemon: Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1651, in read_app
self.init_object(name, class_name, module_name, self.app_config)
File "/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1446, in init_object
self.objects[name]["object"].initialize()
File "/config/appdaemon/apps/timed_lights.py", line 13, in initialize
self.run_in(self.do_lights(), 0)
File "/config/appdaemon/apps/timed_lights.py", line 19, in do_lights
self.lights.run_light()
File "/config/appdaemon/apps/lights.py", line 12, in run_light
light_device = kwargs["light_device"]
NameError: name 'kwargs' is not defined