I’ve had this problem for a long time, but have avoided it like the plague just using create_task & sleep(), but is now becoming too much hassle to avoid just using the features AppDaemon already has. My callbacks are structured accordingly to the scheduler callbacks, but the mentioned methods in the title never actually execute the callbacks.
class Tod(hass.Hass):
def initialize(self):
self.log("initializing ...")
try:
self.log(f'args: {self.args}')
# required args
self._night_input = self.args['night_input']
self._mode = self.args['mode_input']
# optional args
self._evening_start = self.args.get('evening_start', self.rpltime(hour=20, minute=30))
self._morning_start = self.args.get('morning_start', self.rpltime(hour=4))
self._day_start = self.args.get('day_start', self.rpltime(hour=8))
# handlers
h = self.run_in(self.mode_cb, 5) # this is merely for testing, but as with run_daily,
# it's never run. The log call is never called, and alas here I am.
self._tod_handle = self.run_daily(self.mode_cb, "00:00:01")
self._night_handle = self.listen_state(self.night_cb, self._night_input, new='on')
self._morning_handle = None
self._day_handle = None
self._evening_handle = None
# last registered goodnight
self._night_trigger_time = None
self.log(f'handle: {self.info_timer(h)}')
except (TypeError, ValueError) as e:
self.log('Incomplete configuration', level="ERROR")
raise e
def mode_cb(self, kwargs):
self.log(f'entered')
self.create_task(self.mode_cb_run(tod=self._morning_start, mode='morning'))
self.create_task(self.mode_cb_run(tod=self._day_start, mode='day'))
self.create_task(self.mode_cb_run(tod=self._evening_start, mode='evening'))
The reason for this is that my modes change depending on a lot of factors, such as sunset/sunrise with limits, if I have work to do etc.
Ive tried all kinds of setups, giving run_at specific datetime, run_in with seconds till the callback is supposed to be called and much more.
I cant even get run_daily to work. Ive resorted to HomeAssistant flipping an input_boolean once a day, which will then create the tasks, but I dont think I should have to resort to this.