forked from jalmeroth/homie-python
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrelay_switch.py
More file actions
executable file
·35 lines (28 loc) · 863 Bytes
/
relay_switch.py
File metadata and controls
executable file
·35 lines (28 loc) · 863 Bytes
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
#!/usr/bin/env python
import time
import homie
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
config = homie.loadConfigFile("homie-python.json")
Homie = homie.Homie(config)
switchNode = Homie.Node("switch", "switch")
def switchOnHandler(mqttc, obj, msg):
payload = msg.payload.decode("UTF-8").lower()
if payload == 'true':
logger.info("Switch: ON")
switchNode.setProperty("on").send("true")
else:
logger.info("Switch: OFF")
switchNode.setProperty("on").send("false")
def main():
Homie.setFirmware("relay-switch", "1.0.0")
switchNode.advertise("on").settable(switchOnHandler)
Homie.setup()
while True:
time.sleep(1)
if __name__ == '__main__':
try:
main()
except (KeyboardInterrupt, SystemExit):
logger.info("Quitting.")