Browse Source

room_shelly_motion_sensor adapted to fit to silvercrest functionality

tags/v1.0.0
Dirk Alders 2 years ago
parent
commit
6a7f17feff
2 changed files with 29 additions and 11 deletions
  1. 3
    5
      function/first_floor_east.py
  2. 26
    6
      function/rooms.py

+ 3
- 5
function/first_floor_east.py View File

6
 import devices
6
 import devices
7
 import json
7
 import json
8
 import logging
8
 import logging
9
-from function.rooms import room_shelly, room_shelly_auto_off, room_shelly_tradfri_light
9
+from function.rooms import room_shelly, room_shelly_motion_sensor, room_shelly_tradfri_light
10
 from function.helpers import changed_value_indicator
10
 from function.helpers import changed_value_indicator
11
 try:
11
 try:
12
     from config import APP_NAME as ROOT_LOGGER_NAME
12
     from config import APP_NAME as ROOT_LOGGER_NAME
15
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
15
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
16
 
16
 
17
 
17
 
18
-class first_floor_east_floor(room_shelly_auto_off):
18
+class first_floor_east_floor(room_shelly_motion_sensor):
19
     def __init__(self, mqtt_client):
19
     def __init__(self, mqtt_client):
20
         # http://shelly1l-3C6105E4E629
20
         # http://shelly1l-3C6105E4E629
21
-        super().__init__(mqtt_client, "shellies/ffe/floor/main_light", "gui/ffe/floor/main_light/switch")
22
-        self.motion_sensor_silvercrest = devices.silvercrest_motion_sensor(mqtt_client, "zigbee/ffe/floor/motion_sensor")
23
-        self.motion_sensor_silvercrest.add_callback(devices.silvercrest_motion_sensor.KEY_OCCUPANCY, True, self.main_light_shelly.set_output_0_mcb)
21
+        super().__init__(mqtt_client, "shellies/ffe/floor/main_light", "gui/ffe/floor/main_light/switch", "zigbee/ffe/floor/motion_sensor")
24
 
22
 
25
 
23
 
26
 class first_floor_east_kitchen(room_shelly):
24
 class first_floor_east_kitchen(room_shelly):

+ 26
- 6
function/rooms.py View File

56
         self.last_flash_data = data
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
         super().__init__(mqtt_client, topic_shelly, topic_gui_switch)
61
         super().__init__(mqtt_client, topic_shelly, topic_gui_switch)
62
         self.timer_value = timer_value
62
         self.timer_value = timer_value
63
-        self.main_light_timer = None
64
         #
63
         #
65
         self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.reload_timer, True)
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
         cyclic_task = task.periodic(1, self.cyclic_task)
77
         cyclic_task = task.periodic(1, self.cyclic_task)
68
         cyclic_task.run()
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
     def reload_timer(self, device, key, data):
88
     def reload_timer(self, device, key, data):
71
         self.main_light_timer = self.timer_value
89
         self.main_light_timer = self.timer_value
72
 
90
 
73
     def cyclic_task(self, cyclic_task):
91
     def cyclic_task(self, cyclic_task):
74
         if self.main_light_timer is not None:
92
         if self.main_light_timer is not None:
75
-            self.main_light_timer -= cyclic_task.cycle_time
76
             if self.main_light_timer <= 0:
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
 class room_shelly_tradfri_light(room_shelly):
101
 class room_shelly_tradfri_light(room_shelly):

Loading…
Cancel
Save