Browse Source

Auto-Off function added for Circulation pump

master
Dirk Alders 1 year ago
parent
commit
4a99c33b15
4 changed files with 27 additions and 2 deletions
  1. 3
    0
      .gitmodules
  2. 19
    2
      devices/shelly.py
  3. 4
    0
      home_emulation.py
  4. 1
    0
      task

+ 3
- 0
.gitmodules View File

@@ -10,3 +10,6 @@
10 10
 [submodule "devdi"]
11 11
 	path = devdi
12 12
 	url = https://git.mount-mockery.de/smarthome/smart_devdi.git
13
+[submodule "task"]
14
+	path = task
15
+	url = https://git.mount-mockery.de/pylib/task.git

+ 19
- 2
devices/shelly.py View File

@@ -32,6 +32,7 @@
32 32
 
33 33
 from devices.base import base
34 34
 import json
35
+import task
35 36
 
36 37
 
37 38
 class shelly_sw1(base):
@@ -49,6 +50,8 @@ class shelly_sw1(base):
49 50
         super().__init__(mqtt_client, topic)
50 51
         self["state"] = "off"
51 52
         #
53
+        self.__auto_off__ = None
54
+        #
52 55
         self.mqtt_client.add_callback(self.topic + '/relay/0/command', self.__rx_set__)
53 56
 
54 57
     def __rx_set__(self, client, userdata, message):
@@ -57,10 +60,24 @@ class shelly_sw1(base):
57 60
         self.logger.info("Received set data for %s: %s", key, repr(data))
58 61
         self.__set__(key, data)
59 62
         self.send_device_status(key)
60
-        if key == "relay/0" and data.lower() == "on":
61
-            self.power_on()
63
+        if key == "relay/0":
64
+            if data.lower() == "on":
65
+                self.power_on()
66
+                if self.__auto_off__ is not None:
67
+                    self.__auto_off__.run()
68
+            else:
69
+                if self.__auto_off__ is not None:
70
+                    self.__auto_off__.stop()
62 71
 
63 72
     def send_device_status(self, key):
64 73
         data = self[key]
65 74
         self.logger.info("Sending status for %s: %s", key, repr(data))
66 75
         self.mqtt_client.send(self.topic + '/' + key, data)
76
+
77
+    def auto_off(self, sec):
78
+        self.__auto_off__ = task.delayed(sec, self.__auto_off_func__)
79
+
80
+    def __auto_off_func__(self):
81
+        if self.get(self.PROPERTIES[0]).lower() != 'off':
82
+            self.__set__(self.PROPERTIES[0], "off")
83
+            self.send_device_status(self.PROPERTIES[0])

+ 4
- 0
home_emulation.py View File

@@ -78,6 +78,10 @@ if __name__ == "__main__":
78 78
     # FFE #
79 79
     #######
80 80
     loc = props.LOC_FFE
81
+    # KITCHEN
82
+    roo = props.ROO_KIT
83
+    sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_CIR)
84
+    sml.auto_off(600)
81 85
     # LIVINGROOM
82 86
     roo = props.ROO_LIV
83 87
     sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_MAL)

+ 1
- 0
task

@@ -0,0 +1 @@
1
+Subproject commit af35e83d1f07fd4cb9070bdb77cf1f3bdda3a463

Loading…
Cancel
Save