From 069e1484918fefdf409da09e88550251e919db4f Mon Sep 17 00:00:00 2001 From: jwansek Date: Fri, 17 Jan 2025 17:54:30 +0000 Subject: Added Zigbee button behaviours --- .gitignore | 1 + mqtt-client/mqtt-client.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/.gitignore b/.gitignore index 7de9703..ad2c630 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ db.env config.env influxdb-config/ influxdb-data/ +node-red-data/ # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/mqtt-client/mqtt-client.py b/mqtt-client/mqtt-client.py index a441e6d..c846578 100644 --- a/mqtt-client/mqtt-client.py +++ b/mqtt-client/mqtt-client.py @@ -54,6 +54,22 @@ class MQTTClient: print("Zigbee device '%s' reported: %s" % (friendlyname, str(fields))) self.append_influxdb(fields, "zigbee", {"friendlyname": friendlyname, "id": zigbee_id}) + if zigbee_id == "0x7327" and friendlyname == "TVButton" and "Power" in fields.keys(): + if fields["Power"] == 2: + print("TV Zigbee button pressed, toggling TasmotaTV Tasmota Plug") + self.toggle_plug("TasmotaTV") + + if zigbee_id == "0x74B3" and friendlyname == "HarveyButton" and "Power" in fields.keys(): + if fields["Power"] == 2: + print("Harvey's button pressed, toggling TasmotaHarveyPC Plug") + self.toggle_plug("TasmotaHarveyPC") + + def toggle_plug(self, friendlyname): + t = "cmnd/TasmotaPlug/%s/Power" % friendlyname + payload = "TOGGLE" + self.mqttc.publish(t, payload = payload) + print("Send payload '%s' to %s" % (payload, t)) + def append_influxdb(self, fields, measurement_name, tags): points = [{"measurement": measurement_name, "tags": tags, "fields": fields}] write_api = self.influxc.write_api(write_options = SYNCHRONOUS) -- cgit v1.2.3