Hi,
I have a very simple AD script that turns lights on + timer for turning off when a binary sensor changes its state from off to on.
It works as expected but the AD log is full of errors I have never seen before - about recursive call to the turn off method. I cannot figure why.
This is the code:
def initialize (self):
self.utils = self.get_app('utils')
self.show_log = True
self.listen_state(self.state_callback, "binary_sensor.door_main_sensor")
self.utils.mylog("test" , True, False)
def state_callback (self, entity, attribute, old, new, kwargs):
if new == "on" and old == "off":
self.turn_on("light.shelly_light_external_stairs")
self.utils.mylog("inside external_stairs -> new=on & old=off" , True, False) # my own log func
if self.get_state("sun.sun") == "above_horizon": # I have another script in AD that sets timers to turn off lights. It has a default of 2 hours to turn off light.shelly_light_external_stairs.
self.utils.mylog("inside sun->above_horizon" , True, False) # my own log func
self.run_in(self.turn_off, 120)
def turn_off(self, kwargs):
self.turn_off("light.shelly_light_external_stairs")
the error I see on the log is
2020-07-23 09:20:51.878812 INFO utils: <<<< inside external_stairs -> new=on & old=off >>>>
2020-07-23 09:20:51.883153 INFO utils: <<<< inside sun->above_horizon >>>>
2020-07-23 09:22:51.089613 WARNING AppDaemon: ------------------------------------------------------------
2020-07-23 09:22:51.091180 WARNING AppDaemon: Unexpected error in worker for App external_light_lights_external_stairs:
2020-07-23 09:22:51.092049 WARNING AppDaemon: Worker Ags: {'name': 'external_light_lights_external_stairs', 'id': UUID('5ae3a599-e04a-47ce-879d-fa40e819eb53'), 'type': 'timer', 'function': <bound method external_light_lights_external_stairs.turn_off of <external_light_lights_external_stairs.external_light_lights_external_stairs object at 0x74ead118>>, 'kwargs': {}}
2020-07-23 09:22:51.092736 WARNING AppDaemon: ------------------------------------------------------------
2020-07-23 09:22:51.144824 WARNING AppDaemon: Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/appdaemon/appdaemon.py", line 586, in worker
funcref(self.sanitize_timer_kwargs(app, args["kwargs"]))
File "/config/appdaemon/apps/external_light_lights_external_stairs.py", line 19, in turn_off
self.turn_off("light.shelly_light_external_stairs")
File "/config/appdaemon/apps/external_light_lights_external_stairs.py", line 19, in turn_off
self.turn_off("light.shelly_light_external_stairs")
File "/config/appdaemon/apps/external_light_lights_external_stairs.py", line 19, in turn_off
self.turn_off("light.shelly_light_external_stairs")
[Previous line repeated 993 more times]
RecursionError: maximum recursion depth exceeded
2020-07-23 09:22:51.148395 WARNING AppDaemon: ------------------------------------------------------------
Any hint or help will be appreciated.