room_shelly_motion_sensor: logging and reliability improvements

This commit is contained in:
Dirk Alders 2022-12-25 23:33:54 +01:00
parent 6a7f17feff
commit bc1c30cd3f

View File

@ -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: