-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-wallclock.py
executable file
·45 lines (34 loc) · 1.03 KB
/
start-wallclock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
import time
from mqttclient import MqttClient
import subprocess
someonehome = True
def residentsMessage(topic,msg):
global someonehome
if topic == None or msg == None:
return
v = msg.decode()
print("Presence:",v)
if v == "True":
someonehome = True
else:
someonehome = False
def motionMessage(topic,msg):
global someonehome
if topic == None or msg == None:
return
v = msg.decode()
print("Presence:",someonehome," Motion:",v)
if someonehome and v == "ON":
print("starting wall clock")
subprocess.run(["systemctl","start","wallclock"])
print("ending program")
subprocess.run(["systemctl","stop","start-wallclock"])
time.sleep(1)
sys.exit()
if __name__ == "__main__":
client = MqttClient()
client.subscribe("Chattenweg5/Residents",residentsMessage)
client.subscribe("Chattenweg5/2OG-Flur/sensor/binary_sensor/2og-flur_motion/state",motionMessage)
while True:
time.sleep(1)