aboutsummaryrefslogtreecommitdiffstats
path: root/mqtt-client/mqtt-client.py
diff options
context:
space:
mode:
authorjwansek <eddie.atten.ea29@gmail.com>2026-02-25 19:50:32 +0000
committerjwansek <eddie.atten.ea29@gmail.com>2026-02-25 19:50:32 +0000
commit064733b679af245bf257fd53805b2a5a8394389d (patch)
treeca978bf82bfc6ed0384f333907b3461f96f23b3a /mqtt-client/mqtt-client.py
parent0751f6f2a58bde3e2756058f4a127a04b11d4b46 (diff)
downloadpower.eda.gay-064733b679af245bf257fd53805b2a5a8394389d.tar.gz
power.eda.gay-064733b679af245bf257fd53805b2a5a8394389d.zip
Switched to toggling the firestick with the Omada POE API instead of tasmota plugs
Diffstat (limited to 'mqtt-client/mqtt-client.py')
-rw-r--r--mqtt-client/mqtt-client.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/mqtt-client/mqtt-client.py b/mqtt-client/mqtt-client.py
index cd38944..8c7bd23 100644
--- a/mqtt-client/mqtt-client.py
+++ b/mqtt-client/mqtt-client.py
@@ -14,6 +14,9 @@ sys.path.insert(1, os.path.join(os.path.dirname(__file__), "TasmotaCLI"))
import tasmotaMQTTClient
import tasmotaHTTPClient
+sys.path.insert(2, os.path.join(os.path.dirname(__file__), "omada-api"))
+from omada import Omada
+
class MQTTClient:
def __init__(self, mqtt_client_name = "reg.reaweb.uk/mqtt-client", loop_forever = True):
self.influxc = InfluxDBClient(
@@ -95,17 +98,18 @@ class MQTTClient:
if status_before == "OFF":
print("TV was formerly off, so its being turned on, so we're going to turn the firestick on.")
- tasmotaMQTTClient.MQTTClient(MQTT_HOST, "TasmotaFirestick", os.environ["MQTT_USER"], os.environ["MQTT_PASSWD"], "OFF")
+
+ set_omada_poe("Firestick", 0)
print("Waiting...")
time.sleep(8)
- tasmotaMQTTClient.MQTTClient(MQTT_HOST, "TasmotaFirestick", os.environ["MQTT_USER"], os.environ["MQTT_PASSWD"], "ON")
+ set_omada_poe("Firestick", 1)
print("Turned firestick on.")
else:
print("TV was formerly on, so its being turned off, so we're going to turn the firestick off.")
- tasmotaMQTTClient.MQTTClient(MQTT_HOST, "TasmotaFirestick", os.environ["MQTT_USER"], os.environ["MQTT_PASSWD"], "ON")
+ set_omada_poe("Firestick", 1)
print("Waiting...")
time.sleep(8)
- tasmotaMQTTClient.MQTTClient(MQTT_HOST, "TasmotaFirestick", os.environ["MQTT_USER"], os.environ["MQTT_PASSWD"], "OFF")
+ set_omada_poe("Firestick", 0)
print("Turned firestick off.")
zigbee_id = list(msg_j["ZbReceived"].keys())[0]
@@ -114,7 +118,7 @@ class MQTTClient:
del fields["Device"]
print("Zigbee device '%s' reported: %s" % (friendlyname, str(fields)))
- if zigbee_id == "0x7327" and friendlyname == "TVButton" and "Power" in fields.keys():
+ if zigbee_id == "0x0A05" and friendlyname == "TVButton2" and "Power" in fields.keys():
if fields["Power"] == 2:
print("TV Zigbee button pressed, toggling TasmotaTV Tasmota Plug")
status_before = self.get_http_power_status("192.168.5.6", os.environ["MQTT_PASSWD"])
@@ -171,6 +175,20 @@ class MQTTClient:
write_precision = WritePrecision.S
)
+def set_omada_poe(profile, status):
+ o = Omada(os.path.join(os.path.dirname(__file__), "omada.cfg"))
+ o.login()
+
+ profileId = o.getProfileId(profile)
+ settings = o.getProfileSettings(profileId)
+ settings['poe'] = status
+ o.setProfileSettings(profileId, settings)
+
+ settings = o.getProfileSettings(profileId)
+
+ print("Sent POE setting '%d' to profile '%s'" % (settings["poe"], settings["name"]))
+ o.logout()
+
if __name__ == "__main__":
env_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "config.env")
if os.path.exists(env_path):