mirror of
https://gitlab.com/fabinfra/fabaccess/initiators/shelly-timeout.git
synced 2025-03-12 14:51:51 +01:00
Update main.py
This commit is contained in:
parent
7c149da375
commit
f5dcd13357
14
main.py
14
main.py
@ -19,23 +19,25 @@ def on_message(client, topic, payload, qos, properties):
|
|||||||
print(topic)
|
print(topic)
|
||||||
print(payload)
|
print(payload)
|
||||||
|
|
||||||
if topic.endswith("/relay/0") and int(payload) == 1:
|
if topic.endswith("/relay/0") and payload.decode("UTF-8") == "on":
|
||||||
if LAST_TIME == None:
|
if LAST_TIME == None:
|
||||||
LAST_TIME = datetime.datetime.now()
|
LAST_TIME = datetime.datetime.now()
|
||||||
print("UPDATE TIME")
|
print("UPDATE TIME")
|
||||||
if topic.endswith("/relay/0") and int(payload) == 0:
|
if topic.endswith("/relay/0") and payload.decode("UTF-8") == "off":
|
||||||
LAST_TIME = None
|
LAST_TIME = None
|
||||||
print("RESET TIME")
|
print("RESET TIME")
|
||||||
|
|
||||||
if topic.endswith("/relay/0/energy") and LAST_TIME != None:
|
if topic.endswith("/relay/0/power") and LAST_TIME != None:
|
||||||
if int(payload) > POWER_THRESHOLD:
|
if float(payload.decode("UTF-8")) > POWER_THRESHOLD:
|
||||||
LAST_TIME = None
|
LAST_TIME = None
|
||||||
print("RESET POWER")
|
print("RESET POWER")
|
||||||
elif (datetime.datetime.now() - LAST_TIME).total_seconds() > TIME_THRESHOLD:
|
elif (datetime.datetime.now() - LAST_TIME).total_seconds() > TIME_THRESHOLD:
|
||||||
client.publish(f"shellies/{SHELLY_ID}/relay/0", "off")
|
#client.publish(f"shellies/{SHELLY_ID}/relay/0", "off")
|
||||||
print('{ "state": { "1.3.6.1.4.1.48398.612.2.4": { "state": "Free" } } }')
|
print('{ "state": { "1.3.6.1.4.1.48398.612.2.4": { "state": "Free" } } }')
|
||||||
LAST_TIME = None
|
LAST_TIME = None
|
||||||
print("RESET STATE")
|
print("RESET STATE")
|
||||||
|
else:
|
||||||
|
print("WAITING TIME")
|
||||||
|
|
||||||
def ask_exit(*args):
|
def ask_exit(*args):
|
||||||
STOP.set()
|
STOP.set()
|
||||||
@ -62,4 +64,4 @@ if __name__ == '__main__':
|
|||||||
loop.add_signal_handler(signal.SIGINT, ask_exit)
|
loop.add_signal_handler(signal.SIGINT, ask_exit)
|
||||||
loop.add_signal_handler(signal.SIGTERM, ask_exit)
|
loop.add_signal_handler(signal.SIGTERM, ask_exit)
|
||||||
|
|
||||||
loop.run_until_complete(main(host))
|
loop.run_until_complete(main(host))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user