Parcourir la source

sunrise and sunset depending motion sensor action for room_shelly_motion_sensor implemented

tags/v1.0.0
Dirk Alders il y a 2 ans
Parent
révision
73d6606902
5 fichiers modifiés avec 29 ajouts et 9 suppressions
  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 Voir le fichier

@@ -7,3 +7,6 @@
7 7
 [submodule "task"]
8 8
 	path = task
9 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 Voir le fichier

@@ -1,8 +1,10 @@
1 1
 #!/usr/bin/env python
2 2
 # -*- coding: utf-8 -*-
3 3
 #
4
-
4
+import config
5
+import geo
5 6
 import inspect
7
+import time
6 8
 
7 9
 
8 10
 class changed_value_indicator(dict):
@@ -16,3 +18,15 @@ class changed_value_indicator(dict):
16 18
         rv = self.get(key) != value
17 19
         self[key] = value
18 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 Voir le fichier

@@ -3,6 +3,7 @@
3 3
 #
4 4
 
5 5
 import devices
6
+from function.helpers import now, sunset_time, sunrise_time
6 7
 import logging
7 8
 import task
8 9
 
@@ -77,13 +78,14 @@ class room_shelly_motion_sensor(room_shelly):
77 78
         cyclic_task.run()
78 79
 
79 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 90
     def reload_timer(self, device, key, data):
89 91
         self.main_light_timer = self.timer_value

+ 1
- 0
geo

@@ -0,0 +1 @@
1
+Subproject commit 11166bb27ad2335f7812fcb88c788397f5106751

+ 1
- 1
smart_brain.py Voir le fichier

@@ -12,7 +12,7 @@ if __name__ == "__main__":
12 12
     if config.DEBUG:
13 13
         report.appLoggingConfigure(None, None, ((config.APP_NAME, logging.DEBUG), ), fmt=report.SHORT_FMT, host='localhost', port=19996)
14 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 17
     mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
18 18
                           password=config.MQTT_PASSWORD, name=config.APP_NAME)

Chargement…
Annuler
Enregistrer