diff --git a/main.py b/main.py index cb928b3..9f13b38 100644 --- a/main.py +++ b/main.py @@ -18,11 +18,11 @@ def on_message(client, userdata, msg): print(topic, file=sys.stderr) print(payload, file=sys.stderr) - if topic.endswith("/relay/0/command") and payload.decode("UTF-8") == "on": + if topic.endswith("/relay/0") and payload.decode("UTF-8") == "on": if LAST_TIME == None: LAST_TIME = datetime.datetime.now() print("UPDATE TIME", file=sys.stderr) - if topic.endswith("/relay/0/command") and payload.decode("UTF-8") == "off": + if topic.endswith("/relay/0") and payload.decode("UTF-8") == "off": LAST_TIME = None print("RESET TIME", file=sys.stderr) @@ -40,16 +40,14 @@ def on_message(client, userdata, msg): print("WAITING TIME", file=sys.stderr) sys.stderr.flush() -def ask_exit(*args): - STOP.set() - def main(host): client = client = mqtt.Client(f"shelly_client_{SHELLY_ID}") client.on_message = on_message client.connect(host) - client.subscribe(f"shellies/{SHELLY_ID}/relay/0/#") + client.subscribe(f"shellies/{SHELLY_ID}/relay/0") + client.subscribe(f"shellies/{SHELLY_ID}/relay/0/power") client.loop_forever()