diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | mqtt-client/mqtt-client.py | 16 | 
2 files changed, 17 insertions, 0 deletions
| @@ -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) | 
