Browse Source

sunrise and sunset depending motion sensor action for room_shelly_motion_sensor implemented

tags/v1.0.0
Dirk Alders 2 years ago
parent
commit
73d6606902
5 changed files with 29 additions and 9 deletions
  1. 3
    0
      .gitmodules
  2. 15
    1
      function/helpers.py
  3. 9
    7
      function/rooms.py
  4. 1
    0
      geo
  5. 1
    1
      smart_brain.py

+ 3
- 0
.gitmodules View File

7
 [submodule "task"]
7
 [submodule "task"]
8
 	path = task
8
 	path = task
9
 	url = https://git.mount-mockery.de/pylib/task.git
9
 	url = https://git.mount-mockery.de/pylib/task.git
10
+[submodule "geo"]
11
+	path = geo
12
+	url = https://git.mount-mockery.de/pylib/geo.git

+ 15
- 1
function/helpers.py View File

1
 #!/usr/bin/env python
1
 #!/usr/bin/env python
2
 # -*- coding: utf-8 -*-
2
 # -*- coding: utf-8 -*-
3
 #
3
 #
4
-
4
+import config
5
+import geo
5
 import inspect
6
 import inspect
7
+import time
6
 
8
 
7
 
9
 
8
 class changed_value_indicator(dict):
10
 class changed_value_indicator(dict):
16
         rv = self.get(key) != value
18
         rv = self.get(key) != value
17
         self[key] = value
19
         self[key] = value
18
         return rv
20
         return rv
21
+
22
+
23
+def now():
24
+    return time.mktime(time.localtime())
25
+
26
+
27
+def sunrise_time(time_offs_min=30):
28
+    return time.mktime(geo.sun.sunrise(config.GEO_POSITION)) + time_offs_min * 60
29
+
30
+
31
+def sunset_time(time_offs_min=-30):
32
+    return time.mktime(geo.sun.sunset(config.GEO_POSITION)) + time_offs_min * 60

+ 9
- 7
function/rooms.py View File

3
 #
3
 #
4
 
4
 
5
 import devices
5
 import devices
6
+from function.helpers import now, sunset_time, sunrise_time
6
 import logging
7
 import logging
7
 import task
8
 import task
8
 
9
 
77
         cyclic_task.run()
78
         cyclic_task.run()
78
 
79
 
79
     def set_motion_detected(self, device, key, data):
80
     def set_motion_detected(self, device, key, data):
80
-        if device == self.motion_sensor_silvercrest_1:
81
-            self.motion_detected_1 = data
82
-        elif device == self.motion_sensor_silvercrest_2:
83
-            self.motion_detected_2 = data
84
-        if data is True:
85
-            logger.info("%s: Motion detected - Switching on main light %s", device.topic, self.main_light_shelly.topic)
86
-            self.main_light_shelly.set_output_0(True)
81
+        if now() < sunrise_time(60) or now() > sunset_time(-60):
82
+            if device == self.motion_sensor_silvercrest_1:
83
+                self.motion_detected_1 = data
84
+            elif device == self.motion_sensor_silvercrest_2:
85
+                self.motion_detected_2 = data
86
+            if data is True:
87
+                logger.info("%s: Motion detected - Switching on main light %s", device.topic, self.main_light_shelly.topic)
88
+                self.main_light_shelly.set_output_0(True)
87
 
89
 
88
     def reload_timer(self, device, key, data):
90
     def reload_timer(self, device, key, data):
89
         self.main_light_timer = self.timer_value
91
         self.main_light_timer = self.timer_value

+ 1
- 0
geo

1
+Subproject commit 11166bb27ad2335f7812fcb88c788397f5106751

+ 1
- 1
smart_brain.py View File

12
     if config.DEBUG:
12
     if config.DEBUG:
13
         report.appLoggingConfigure(None, None, ((config.APP_NAME, logging.DEBUG), ), fmt=report.SHORT_FMT, host='localhost', port=19996)
13
         report.appLoggingConfigure(None, None, ((config.APP_NAME, logging.DEBUG), ), fmt=report.SHORT_FMT, host='localhost', port=19996)
14
     else:
14
     else:
15
-        report.stdoutLoggingConfigure(((config.APP_NAME, logging.INFO), (config.APP_NAME+'.devices', logging.WARNING)), report.SHORT_FMT)
15
+        report.stdoutLoggingConfigure(((config.APP_NAME, logging.INFO)), report.SHORT_FMT)
16
     #
16
     #
17
     mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
17
     mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
18
                           password=config.MQTT_PASSWORD, name=config.APP_NAME)
18
                           password=config.MQTT_PASSWORD, name=config.APP_NAME)

Loading…
Cancel
Save