From bc1c30cd3fcb8373ce527325a9519264c9fb2b88 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Sun, 25 Dec 2022 23:33:54 +0100 Subject: [PATCH] room_shelly_motion_sensor: logging and reliability improvements --- function/rooms.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/function/rooms.py b/function/rooms.py index 472f7ab..3d832be 100644 --- a/function/rooms.py +++ b/function/rooms.py @@ -62,6 +62,7 @@ class room_shelly_motion_sensor(room_shelly): self.timer_value = timer_value # self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.reload_timer, True) + self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, False, self.reset_timer, True) # self.motion_sensor_silvercrest_1 = devices.silvercrest_motion_sensor(mqtt_client, topic_motion_sensor_1) self.motion_sensor_silvercrest_1.add_callback(devices.silvercrest_motion_sensor.KEY_OCCUPANCY, None, self.set_motion_detected) @@ -70,9 +71,7 @@ class room_shelly_motion_sensor(room_shelly): self.motion_sensor_silvercrest_2 = devices.silvercrest_motion_sensor(mqtt_client, topic_motion_sensor_2) self.motion_sensor_silvercrest_2.add_callback(devices.silvercrest_motion_sensor.KEY_OCCUPANCY, None, self.set_motion_detected) # - self.motion_detected_1 = False - self.motion_detected_2 = False - self.main_light_timer = None + self.reset_timer() # cyclic_task = task.periodic(1, self.cyclic_task) cyclic_task.run() @@ -83,15 +82,22 @@ class room_shelly_motion_sensor(room_shelly): elif device == self.motion_sensor_silvercrest_2: self.motion_detected_2 = data if data is True: + logger.info("%s: Motion detected - Switching on main light %s", device.topic, self.main_light_shelly.topic) self.main_light_shelly.set_output_0(True) def reload_timer(self, device, key, data): self.main_light_timer = self.timer_value + def reset_timer(self, device=None, key=None, data=None): + self.main_light_timer = None + self.motion_detected_1 = False + self.motion_detected_2 = False + def cyclic_task(self, cyclic_task): if self.main_light_timer is not None: if self.main_light_timer <= 0: if not self.motion_detected_1 and not self.motion_detected_2: + logger.info("No motion and time ran out - Switching off main light %s", self.main_light_shelly.topic) self.main_light_shelly.set_output_0(False) self.main_light_timer = None else: