From 0e383fd8f3ae8e3d4ef7abb8c548f93201f3feac Mon Sep 17 00:00:00 2001 From: jwansek Date: Sun, 8 Jun 2025 14:47:07 +0100 Subject: Toggling geoffery with HTTP instead of MQTT --- mqtt-client/mqtt-client.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'mqtt-client') diff --git a/mqtt-client/mqtt-client.py b/mqtt-client/mqtt-client.py index 602774b..00a808f 100644 --- a/mqtt-client/mqtt-client.py +++ b/mqtt-client/mqtt-client.py @@ -3,6 +3,7 @@ from influxdb_client import InfluxDBClient, Point, WritePrecision from influxdb_client.client.write_api import SYNCHRONOUS import prometheus_client import threading +import asyncio import time import json import sys @@ -10,6 +11,7 @@ import os sys.path.insert(1, os.path.join(os.path.dirname(__file__), "TasmotaCLI")) import tasmotaMQTTClient +import tasmotaHTTPClient class MQTTClient: def __init__(self, mqtt_client_name = "reg.reaweb.uk/mqtt-client", loop_forever = True): @@ -92,6 +94,7 @@ class MQTTClient: print("Waiting...") time.sleep(8) tasmotaMQTTClient.MQTTClient(MQTT_HOST, "TasmotaGeoffery", os.environ["MQTT_USER"], os.environ["MQTT_PASSWD"], "ON") + print("Toggled again.") zigbee_id = list(msg_j["ZbReceived"].keys())[0] fields = msg_j["ZbReceived"][zigbee_id] @@ -103,7 +106,12 @@ class MQTTClient: if fields["Power"] == 2: print("TV Zigbee button pressed, toggling TasmotaTV Tasmota Plug") self.toggle_plug("TasmotaTV") - threading.Thread(target = toggle_geoffery, args = ()).start() + # threading.Thread(target = toggle_geoffery, args = ()).start() + loop = asyncio.get_event_loop() + loop.run_until_complete(tasmotaHTTPClient.main(host = "geoffery.plug", username = "admin", password = os.environ["MQTT_PASSWD"], toggle = True)) + time.sleep(8) + loop.run_until_complete(tasmotaHTTPClient.main(host = "geoffery.plug", username = "admin", password = os.environ["MQTT_PASSWD"], toggle = True)) + if zigbee_id == "0x74B3" and friendlyname == "HarveyButton" and "Power" in fields.keys(): if fields["Power"] == 2: -- cgit v1.2.3