aboutsummaryrefslogtreecommitdiffstats
path: root/mqtt-client/mqtt-client.py
diff options
context:
space:
mode:
authorjwansek <eddie.atten.ea29@gmail.com>2026-05-29 11:16:29 +0100
committerjwansek <eddie.atten.ea29@gmail.com>2026-05-29 11:16:29 +0100
commitae73799694b23cc0af558e2ed8bc9b77fd818c47 (patch)
treeb247953177610f3e58b3abcfaf8db5d589bcd027 /mqtt-client/mqtt-client.py
parent4d70420a0590cb6c00b70bd8082ce009f510d916 (diff)
downloadpower.eda.gay-ae73799694b23cc0af558e2ed8bc9b77fd818c47.tar.gz
power.eda.gay-ae73799694b23cc0af558e2ed8bc9b77fd818c47.zip
Started logging zigbee plugs in the same way as tasmota plugs
Diffstat (limited to 'mqtt-client/mqtt-client.py')
-rw-r--r--mqtt-client/mqtt-client.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/mqtt-client/mqtt-client.py b/mqtt-client/mqtt-client.py
index 9682dc9..f45fbf1 100644
--- a/mqtt-client/mqtt-client.py
+++ b/mqtt-client/mqtt-client.py
@@ -53,6 +53,13 @@ class MQTTClient:
labelnames = ["location"]
)
+ self.zigbee_plugs = {"MikroTikZigbeePlug"}
+ self.zigbee_to_tasmota_transformations = {
+ "RMSVoltage": "Voltage",
+ "ActivePower": "Power",
+ "RMSCurrent": "Current"
+ }
+
# print(self.send_raw_tasmota_http("192.168.5.6", os.environ["MQTT_PASSWD"], "Power"))
self.mqttc = paho.Client(mqtt_client_name, clean_session = True)
@@ -85,6 +92,14 @@ class MQTTClient:
elif type_ == "TasmotaZigbee":
self.handle_zigbee(msg_j)
+ def handle_zigbee_plug(self, friendlyname, fields):
+ fields2 = {}
+ for k, v in fields.items():
+ if k in self.zigbee_to_tasmota_transformations.keys():
+ fields2[self.zigbee_to_tasmota_transformations[k]] = v
+
+ self.append_influxdb(fields2, "tasmota_power", {"plug": friendlyname})
+
def handle_plug(self, msg_j, location):
print("'%s' is using %.1fw @ %s. %.1fkWh so far today, %.1fkWh yesterday" % (location, msg_j["ENERGY"]["Power"], msg_j["Time"], msg_j["ENERGY"]["Today"], msg_j["ENERGY"]["Yesterday"]))
fields = {k: v for k, v in msg_j["ENERGY"].items() if k not in {"TotalStartTime"}}
@@ -118,6 +133,9 @@ class MQTTClient:
del fields["Device"]
print("Zigbee device '%s' reported: %s" % (friendlyname, str(fields)))
+ if friendlyname in self.zigbee_plugs:
+ self.handle_zigbee_plug(friendlyname, fields)
+
if friendlyname == "DoorSensor":
with open(os.path.join(os.path.dirname(__file__), "door_log.csv"), "a") as f:
f.write("%s,%s,%s\n" % (datetime.datetime.now().astimezone().isoformat(), friendlyname, ",".join(sorted(["%s=%s" % (k, v) for k, v in fields.items()]))))