I have an automation that turns a lamp on at sunset and turns off at 8:00pm. I’m trying to convert this to AD as my first test/learning script. Below is what I have and the message i get when starting AD.
Cheers,
Mike
import appdaemon.appapi as appapi
import datetime
class LRLampOn(appapi.AppDaemon):
def initialize(self):
self.run_at_sunset(self.lights_on)
time = datetime.time(20, 0, 0)
self.run_at(self.lights_off, time)
def lights_on(self, kwargs):
self.turn_on(self.args["lightID"])
def lights_off(self, kwargs):
self.turn_off(self.args["lightID"])
2017-03-04 17:41:01.094715 INFO AppDaemon Version 1.5.2 starting
2017-03-04 17:41:11.309488 INFO Got initial state
2017-03-04 17:41:11.313881 INFO Loading Module: /home/homeassistant/.homeassistant/apps/lampon.py
2017-03-04 17:41:11.319498 INFO Loading Object lamp_on using class LRLampOn from module lampon
2017-03-04 17:41:11.321804 WARNING ------------------------------------------------------------
2017-03-04 17:41:11.322503 WARNING Unexpected error during loading of lamp_on:
2017-03-04 17:41:11.323092 WARNING ------------------------------------------------------------
2017-03-04 17:41:11.330531 WARNING Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py", line 996, in read_app
init_object(name, class_name, module_name, config[name])
File "/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py", line 690, in init_object
conf.objects[name]["object"].initialize()
File "/home/homeassistant/.homeassistant/apps/lampon.py", line 11, in initialize
self.run_at(self.lights_off, time)
File "/usr/local/lib/python3.4/dist-packages/appdaemon/appapi.py", line 484, in run_at
if start < now:
TypeError: unorderable types: datetime.time() < datetime.datetime()
2017-03-04 17:41:11.331700 WARNING ------------------------------------------------------------
EDIT: I changed run_at
to run_daily
and the error is gone. After re-reading the command list provided by @ReneTode it looks like run_at
also requires a date? Will see what happens when the sun sets here soon.