|
@@ -56,26 +56,46 @@ class room_shelly(room):
|
56
|
56
|
self.last_flash_data = data
|
57
|
57
|
|
58
|
58
|
|
59
|
|
-class room_shelly_auto_off(room_shelly):
|
60
|
|
- def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, timer_value=30):
|
|
59
|
+class room_shelly_motion_sensor(room_shelly):
|
|
60
|
+ def __init__(self, mqtt_client, topic_shelly, topic_gui_switch, topic_motion_sensor_1, topic_motion_sensor_2=None, timer_value=30):
|
61
|
61
|
super().__init__(mqtt_client, topic_shelly, topic_gui_switch)
|
62
|
62
|
self.timer_value = timer_value
|
63
|
|
- self.main_light_timer = None
|
64
|
63
|
#
|
65
|
64
|
self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.reload_timer, True)
|
66
|
65
|
#
|
|
66
|
+ self.motion_sensor_silvercrest_1 = devices.silvercrest_motion_sensor(mqtt_client, topic_motion_sensor_1)
|
|
67
|
+ self.motion_sensor_silvercrest_1.add_callback(devices.silvercrest_motion_sensor.KEY_OCCUPANCY, None, self.set_motion_detected)
|
|
68
|
+ #
|
|
69
|
+ if topic_motion_sensor_2 is not None:
|
|
70
|
+ self.motion_sensor_silvercrest_2 = devices.silvercrest_motion_sensor(mqtt_client, topic_motion_sensor_2)
|
|
71
|
+ self.motion_sensor_silvercrest_2.add_callback(devices.silvercrest_motion_sensor.KEY_OCCUPANCY, None, self.set_motion_detected)
|
|
72
|
+ #
|
|
73
|
+ self.motion_detected_1 = False
|
|
74
|
+ self.motion_detected_2 = False
|
|
75
|
+ self.main_light_timer = None
|
|
76
|
+ #
|
67
|
77
|
cyclic_task = task.periodic(1, self.cyclic_task)
|
68
|
78
|
cyclic_task.run()
|
69
|
79
|
|
|
80
|
+ def set_motion_detected(self, device, key, data):
|
|
81
|
+ if device == self.motion_sensor_silvercrest_1:
|
|
82
|
+ self.motion_detected_1 = data
|
|
83
|
+ elif device == self.motion_sensor_silvercrest_2:
|
|
84
|
+ self.motion_detected_2 = data
|
|
85
|
+ if data is True:
|
|
86
|
+ self.main_light_shelly.set_output_0(True)
|
|
87
|
+
|
70
|
88
|
def reload_timer(self, device, key, data):
|
71
|
89
|
self.main_light_timer = self.timer_value
|
72
|
90
|
|
73
|
91
|
def cyclic_task(self, cyclic_task):
|
74
|
92
|
if self.main_light_timer is not None:
|
75
|
|
- self.main_light_timer -= cyclic_task.cycle_time
|
76
|
93
|
if self.main_light_timer <= 0:
|
77
|
|
- self.main_light_shelly.set_output_0(False)
|
78
|
|
- self.main_light_timer = None
|
|
94
|
+ if not self.motion_detected_1 and not self.motion_detected_2:
|
|
95
|
+ self.main_light_shelly.set_output_0(False)
|
|
96
|
+ self.main_light_timer = None
|
|
97
|
+ else:
|
|
98
|
+ self.main_light_timer -= cyclic_task.cycle_time
|
79
|
99
|
|
80
|
100
|
|
81
|
101
|
class room_shelly_tradfri_light(room_shelly):
|