Exemplo n.º 1
0
def tuya_dimmer_response(self, Devices, _ModelName, NwkId, srcEp, ClusterID,
                         dstNWKID, dstEP, dp, datatype, data):
    #             cmd | status | transId | dp | DataType | fn | len | Data
    # Dim Down:     01     00        01     02      02      00    04   00000334
    # Dim Up:       01     00        01     02      02      00    04   0000005a
    # Switch Off:   01     00        01     01      01      00    01   00
    # Dim Up  :     01     00        01     01      01      00    01   01

    if dp == 0x01:  # Switch On/Off
        MajDomoDevice(self, Devices, NwkId, srcEp, "0006", data)
        self.log.logging(
            "Tuya", "Debug", "tuya_dimmer_response - Nwkid: %s/%s On/Off %s" %
            (NwkId, srcEp, data), NwkId)

    elif dp == 0x02:  # Dim Down/Up
        # As MajDomoDevice expect a value between 0 and 255, and Tuya dimmer is on a scale from 0 - 1000.
        analogValue = int(data, 16) / 10  # This give from 1 to 100
        level = int((analogValue * 255) / 100)

        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_dimmer_response - Nwkid: %s/%s Dim up/dow %s %s" %
            (NwkId, srcEp, int(data, 16), level),
            NwkId,
        )
        MajDomoDevice(self, Devices, NwkId, srcEp, "0008", "%02x" % level)
    else:
        attribute_name = "UnknowDp_0x%02x_Dt_0x%02x" % (dp, datatype)
        store_tuya_attribute(self, NwkId, attribute_name, data)
Exemplo n.º 2
0
def tuya_smart_motion_all_in_one(self, Devices, _ModelName, NwkId, srcEp,
                                 ClusterID, dstNWKID, dstEP, dp, datatype,
                                 data):

    if dp == 0x6b:  # Temperature
        self.log.logging(
            "Tuya", "Debug",
            "tuya_smart_motion_all_in_one - Temperature %s" % int(data, 16),
            NwkId)
        MajDomoDevice(self, Devices, NwkId, "02", "0402", (int(data, 16) / 10))
        store_tuya_attribute(self, NwkId, "Temperature", data)

    elif dp == 0x6c:  # Humidity
        self.log.logging(
            "Tuya", "Debug",
            "tuya_smart_motion_all_in_one - Humidity %s" % int(data, 16),
            NwkId)
        MajDomoDevice(self, Devices, NwkId, "02", "0405", (int(data, 16)))
        store_tuya_attribute(self, NwkId, "Humidity", data)

    else:
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_smart_motion_all_in_one - Model: %s Unknow Nwkid: %s/%s dp: %02x data type: %s data: %s"
            % (_ModelName, NwkId, srcEp, dp, datatype, data),
            NwkId,
        )
Exemplo n.º 3
0
def tuya_garage_door_response(self, Devices, _ModelName, NwkId, srcEp,
                              ClusterID, dstNWKID, dstEP, dp, datatype, data):

    if dp == 0x01:
        # Switch
        self.log.logging(
            "Tuya", "Debug",
            "tuya_garage_door_response - Switch %s" % int(data, 16), NwkId)
        MajDomoDevice(self, Devices, NwkId, "01", "0006",
                      "%02x" % (int(data, 16)))
        store_tuya_attribute(self, NwkId, "Door", data)

    elif dp == 0x03:
        # Door: 0x00 => Closed, 0x01 => Open
        self.log.logging("Tuya", "Debug",
                         "tuya_garage_door_response - Door %s" % int(data, 16),
                         NwkId)
        MajDomoDevice(self, Devices, NwkId, "01", "0500",
                      "%02x" % (int(data, 16)))
        store_tuya_attribute(self, NwkId, "Door", data)

    else:
        store_tuya_attribute(self, NwkId, "dp:%s-dt:%s" % (dp, datatype), data)
Exemplo n.º 4
0
def tuya_siren_response(self, Devices, _ModelName, NwkId, srcEp, ClusterID, dstNWKID, dstEP, dp, datatype, data):

    self.log.logging("Tuya", "Debug", "tuya_siren_response - Nwkid: %s dp: %02x data: %s" % (NwkId, dp, data))

    if dp == 0x65:  # Power Mode ( 0x00 Battery, 0x04 USB )
        if data == "00":
            self.log.logging(
                "Tuya", "Log", "tuya_siren_response - Nwkid: %s/%s switch to Battery power" % (NwkId, srcEp), NwkId
            )

        elif data == "01":  # High
            self.ListOfDevices[NwkId]["Battery"] = 90
            Update_Battery_Device(self, Devices, NwkId, 90)

        elif data == "02":  # Medium
            self.ListOfDevices[NwkId]["Battery"] = 50
            Update_Battery_Device(self, Devices, NwkId, 50)

        elif data == "03":  # Low
            self.ListOfDevices[NwkId]["Battery"] = 25
            Update_Battery_Device(self, Devices, NwkId, 25)

        elif data == "04":
            self.log.logging(
                "Tuya", "Log", "tuya_siren_response - Nwkid: %s/%s switch to USB power" % (NwkId, srcEp), NwkId
            )

        store_tuya_attribute(self, NwkId, "PowerMode", data)

    elif dp == 0x66:
        self.log.logging("Tuya", "Debug", "tuya_siren_response - Alarm Melody 0x0473 %s" % int(data, 16), NwkId)
        MajDomoDevice(self, Devices, NwkId, srcEp, "0006", (int(data, 16)))
        store_tuya_attribute(self, NwkId, "SirenMelody", data)

    elif dp == 0x67:
        self.log.logging("Tuya", "Debug", "tuya_siren_response - Current Siren Duration %s" % int(data, 16), NwkId)
        store_tuya_attribute(self, NwkId, "SirenDuration", data)

    elif dp == 0x68:  # Alarm set
        # Alarm
        store_tuya_attribute(self, NwkId, "Alarm", data)
        if data == "00":
            MajDomoDevice(self, Devices, NwkId, srcEp, "0006", "00", Attribute_="0168")
        else:
            MajDomoDevice(self, Devices, NwkId, srcEp, "0006", "01", Attribute_="0168")

    elif dp == 0x69:  # Temperature
        self.log.logging("Tuya", "Debug", "tuya_siren_response - Temperature %s" % int(data, 16), NwkId)
        MajDomoDevice(self, Devices, NwkId, srcEp, "0402", (int(data, 16) / 10))
        store_tuya_attribute(self, NwkId, "Temperature", data)

    elif dp == 0x6A:  # Humidity
        self.log.logging("Tuya", "Debug", "tuya_siren_response - Humidity %s" % int(data, 16), NwkId)
        MajDomoDevice(self, Devices, NwkId, srcEp, "0405", (int(data, 16)))
        store_tuya_attribute(self, NwkId, "Humidity", data)

    elif dp == 0x6B:  # Min Alarm Temperature
        self.log.logging("Tuya", "Debug", "tuya_siren_response - Current Min Alarm Temp %s" % int(data, 16), NwkId)
        store_tuya_attribute(self, NwkId, "MinAlarmTemp", data)

    elif dp == 0x6C:  # Max Alarm Temperature
        self.log.logging("Tuya", "Debug", "tuya_siren_response - Current Max Alarm Temp %s" % int(data, 16), NwkId)
        store_tuya_attribute(self, NwkId, "MaxAlarmTemp", data)

    elif dp == 0x6D and _ModelName == "TS0601-sirene":  # AMin Alarm Humidity
        self.log.logging("Tuya", "Debug", "tuya_siren_response - Current Min Alarm Humi %s" % int(data, 16), NwkId)
        store_tuya_attribute(self, NwkId, "MinAlarmHumi", data)

    elif dp == 0x6E:  # Max Alarm Humidity
        self.log.logging("Tuya", "Debug", "tuya_siren_response - Current Max Alarm Humi %s" % int(data, 16), NwkId)
        store_tuya_attribute(self, NwkId, "MaxAlarmHumi", data)

    elif dp == 0x70:
        self.log.logging("Tuya", "Log", "tuya_siren_response - Temperature Unit: %s " % (int(data, 16)), NwkId)
        store_tuya_attribute(self, NwkId, "TemperatureUnit", data)

    elif dp == 0x71:  # Alarm by Temperature
        self.log.logging("Tuya", "Log", "tuya_siren_response - Alarm by Temperature: %s" % (int(data, 16)), NwkId)
        MajDomoDevice(self, Devices, NwkId, srcEp, "0006", data, Attribute_="0171")
        store_tuya_attribute(self, NwkId, "AlarmByTemp", data)

    elif dp == 0x72:  # Alarm by humidity
        self.log.logging("Tuya", "Log", "tuya_siren_response - Alarm by Humidity: %s" % (int(data, 16)), NwkId)
        MajDomoDevice(self, Devices, NwkId, srcEp, "0006", data, Attribute_="0172")
        store_tuya_attribute(self, NwkId, "AlarmByHumi", data)

    elif dp == 0x74:  # Current Siren Volume
        self.log.logging("Tuya", "Debug", "tuya_siren_response - Current Siren Volume %s" % int(data, 16), NwkId)
        store_tuya_attribute(self, NwkId, "SirenVolume", data)

    else:
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_siren_response - Unknown attribut Nwkid: %s/%s decodeDP: %04x data: %s" % (NwkId, srcEp, dp, data),
            NwkId,
        )
        attribute_name = "UnknowDp_0x%02x_Dt_0x%02x" % (dp, datatype)
        store_tuya_attribute(self, NwkId, attribute_name, data)
Exemplo n.º 5
0
def tuya_curtain_response(self, Devices, _ModelName, NwkId, srcEp, ClusterID,
                          dstNWKID, dstEP, dp, datatype, data):
    # dp 0x01 closing -- Data can be 00 , 01, 02 - Opening, Stopped, Closing
    # dp 0x02 Percent control - Percent control
    # db 0x03 and data '00000000'  - Percent state when arrived at position (report)
    # dp 0x05 and data - direction state
    # dp 0x07 and data 00, 01 - Opening, Closing
    # dp 0x69 and data '00000028'

    # 000104ef00010102 94fd 02 00000970020000 0202 0004 00000004

    self.log.logging(
        "Tuya", "Debug",
        "tuya_curtain_response - Nwkid: %s/%s dp: %s data: %s" %
        (NwkId, srcEp, dp, data), NwkId)

    if dp == 0x01:  # Open / Closing / Stopped
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_curtain_response - Open/Close/Stopped action Nwkid: %s/%s  %s"
            % (NwkId, srcEp, data),
            NwkId,
        )
        store_tuya_attribute(self, NwkId, "Action", data)

    elif dp == 0x02:
        # Percent Control
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_curtain_response - Percentage Control action Nwkid: %s/%s  %s"
            % (NwkId, srcEp, data),
            NwkId,
        )
        store_tuya_attribute(self, NwkId, "PercentControl", data)

    elif dp in (0x03, 0x07):
        # Curtain Percentage
        # We need to translate percentage into Analog value between 0 - 255
        level = ((int(data, 16)) * 255) // 100
        slevel = "%02x" % level
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_curtain_response - Curtain Percentage Nwkid: %s/%s Level %s -> %s"
            % (NwkId, srcEp, data, level),
            NwkId,
        )
        store_tuya_attribute(self, NwkId, "PercentState", data)
        MajDomoDevice(self, Devices, NwkId, srcEp, "0008", slevel)

    elif dp == 0x05:
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_curtain_response - Direction state Nwkid: %s/%s Action %s" %
            (NwkId, srcEp, data),
            NwkId,
        )
        store_tuya_attribute(self, NwkId, "DirectionState", data)

    elif dp in (0x67, 0x69):
        level = ((int(data, 16)) * 255) // 100
        slevel = "%02x" % level
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_curtain_response - ?????? Nwkid: %s/%s data %s --> %s" %
            (NwkId, srcEp, data, level),
            NwkId,
        )
        MajDomoDevice(self, Devices, NwkId, srcEp, "0008", slevel)
        store_tuya_attribute(self, NwkId, "dp_%s" % dp, data)

    else:
        attribute_name = "UnknowDp_0x%02x_Dt_0x%02x" % (dp, datatype)
        store_tuya_attribute(self, NwkId, attribute_name, data)
Exemplo n.º 6
0
def tuya_watertimer_response(self, Devices, _ModelName, NwkId, srcEp,
                             ClusterID, dstNWKID, dstEP, dp, datatype, data):

    self.log.logging(
        "Tuya",
        "Debug",
        "tuya_response - Model: %s Nwkid: %s/%s dp: %02x data type: %02x data: %s"
        % (_ModelName, NwkId, srcEp, dp, datatype, data),
        NwkId,
    )

    if dp == 0x01:
        # Openned
        # tuya_response - Model: TS0601-Parkside-Watering-Timer Nwkid: a82e/01 dp: 06 data type: 2 data: 00000001
        # tuya_response - Model: TS0601-Parkside-Watering-Timer Nwkid: a82e/01 dp: 01 data type: 1 data: 010502000400000001

        # tuya_response - Model: TS0601-Parkside-Watering-Timer Nwkid: a82e/01 dp: 06 data type: 2 data: 00000001
        # tuya_response - Model: TS0601-Parkside-Watering-Timer Nwkid: a82e/01 dp: 01 data type: 1 data: 010502000400000001

        # Closing via Button
        # tuya_response - Model: TS0601-Parkside-Watering-Timer Nwkid: a82e/01 dp: 01 data type: 1 data: 000502000400000001

        # tuya_response - Model: TS0601-Parkside-Watering-Timer Nwkid: a82e/01 dp: 06 data type: 2 data: 00000000
        # tuya_response - Model: TS0601-Parkside-Watering-Timer Nwkid: a82e/01 dp: 01 data type: 1 data: 000502000400000001

        store_tuya_attribute(self, NwkId, "Valve 0x01", data)

    elif dp == 0x05:  #
        store_tuya_attribute(self, NwkId, "Valve 0x05", data)

    elif dp == 0x06 and datatype == 0x02:  # Valve State
        state = "%02d" % int(data)
        store_tuya_attribute(self, NwkId, "Valve state", state)
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_response - ------ Request  MajDomoDevice(self, Devices, %s, %s, '0006', %s)"
            % (NwkId, srcEp, state),
        )
        MajDomoDevice(self, Devices, NwkId, srcEp, "0006", state)

    elif dp == 0x0B:
        store_tuya_attribute(self, NwkId, "Valve 0x0b", data)

    elif dp == 0x65:
        store_tuya_attribute(self, NwkId, "Valve 0x65", data)
    elif dp == 0x66:
        store_tuya_attribute(self, NwkId, "Valve 0x66", data)
    elif dp == 0x67:
        store_tuya_attribute(self, NwkId, "Valve 0x67", data)
    elif dp == 0x68:
        store_tuya_attribute(self, NwkId, "Valve 0x68", data)
    elif dp == 0x69:
        store_tuya_attribute(self, NwkId, "Valve 0x69", data)
    elif dp == 0x6A:
        store_tuya_attribute(self, NwkId, "Valve 0x6a", data)
    elif dp == 0x6B:
        store_tuya_attribute(self, NwkId, "Valve 0x6b", data)
Exemplo n.º 7
0
def tuya_switch_response(self, Devices, _ModelName, NwkId, srcEp, ClusterID,
                         dstNWKID, dstEP, dp, datatype, data):
    if dp == 0x01:
        # Switch 1 ( Right in case of 2gangs)
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_switch_response - Dp 0x01 Nwkid: %s/%s decodeDP: %04x data: %s"
            % (NwkId, srcEp, dp, data),
            NwkId,
        )
        MajDomoDevice(self, Devices, NwkId, "01", "0006", data)

    elif dp == 0x02:
        # Switch 2  (Left in case of 2 Gangs)
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_switch_response - Dp 0x02 Nwkid: %s/%s decodeDP: %04x data: %s"
            % (NwkId, srcEp, dp, data),
            NwkId,
        )
        MajDomoDevice(self, Devices, NwkId, "02", "0006", data)

    elif dp == 0x03:
        # Switch 3
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_switch_response - Dp 0x03 Nwkid: %s/%s decodeDP: %04x data: %s"
            % (NwkId, srcEp, dp, data),
            NwkId,
        )
        MajDomoDevice(self, Devices, NwkId, "03", "0006", data)

    elif dp == 0x0D:
        # All switches
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_switch_response - Dp 0x03 Nwkid: %s/%s decodeDP: %04x data: %s"
            % (NwkId, srcEp, dp, data),
            NwkId,
        )
        MajDomoDevice(self, Devices, NwkId, "01", "0006", data)
        MajDomoDevice(self, Devices, NwkId, "02", "0006", data)
        MajDomoDevice(self, Devices, NwkId, "03", "0006", data)

    elif dp == 0x0E:  # Relay Status
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_switch_response - Dp 0x0e Nwkid: %s/%s decodeDP: %04x data: %s"
            % (NwkId, srcEp, dp, data),
            NwkId,
        )
        store_tuya_attribute(self, NwkId, "RelayStatus", int(data, 16))

    elif dp == 0x0F:  # Light Indicator
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_switch_response - Dp 0x0f Nwkid: %s/%s decodeDP: %04x data: %s"
            % (NwkId, srcEp, dp, data),
            NwkId,
        )
        store_tuya_attribute(self, NwkId, "LightIndicator", int(data, 16))

    else:
        attribute_name = "UnknowDp_0x%02x_Dt_0x%02x" % (dp, datatype)
        store_tuya_attribute(self, NwkId, attribute_name, data)
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_switch_response - Unknown attribut Nwkid: %s/%s decodeDP: %04x data: %s"
            % (NwkId, srcEp, dp, data),
            NwkId,
        )
Exemplo n.º 8
0
def tuya_response(self, Devices, _ModelName, NwkId, srcEp, ClusterID, dstNWKID,
                  dstEP, dp, datatype, data):

    self.log.logging(
        "Tuya",
        "Debug",
        "tuya_response - Model: %s Nwkid: %s/%s dp: %02x dt: %02x data: %s" %
        (_ModelName, NwkId, srcEp, dp, datatype, data),
        NwkId,
    )

    if _ModelName in ("TS0202-_TZ3210_jijr1sss", ):
        tuya_smart_motion_all_in_one(self, Devices, _ModelName, NwkId, srcEp,
                                     ClusterID, dstNWKID, dstEP, dp, datatype,
                                     data)

    elif _ModelName in ("TS0601-switch", "TS0601-2Gangs-switch",
                        "TS0601-2Gangs-switch"):
        tuya_switch_response(self, Devices, _ModelName, NwkId, srcEp,
                             ClusterID, dstNWKID, dstEP, dp, datatype, data)

    elif _ModelName in ("TS0601-Parkside-Watering-Timer"):
        tuya_watertimer_response(self, Devices, _ModelName, NwkId, srcEp,
                                 ClusterID, dstNWKID, dstEP, dp, datatype,
                                 data)

    elif _ModelName == "TS0601-SmartAir":
        tuya_smartair_response(self, Devices, _ModelName, NwkId, srcEp,
                               ClusterID, dstNWKID, dstEP, dp, datatype, data)

    elif _ModelName == "TS0601-curtain":
        tuya_curtain_response(self, Devices, _ModelName, NwkId, srcEp,
                              ClusterID, dstNWKID, dstEP, dp, datatype, data)

    elif _ModelName == "TS0601-_TZE200_nklqjk62":
        tuya_garage_door_response(self, Devices, _ModelName, NwkId, srcEp,
                                  ClusterID, dstNWKID, dstEP, dp, datatype,
                                  data)

    elif _ModelName in ("TS0601-thermostat"):
        tuya_eTRV_response(self, Devices, _ModelName, NwkId, srcEp, ClusterID,
                           dstNWKID, dstEP, dp, datatype, data)

    elif _ModelName in (TUYA_eTRV_MODEL):
        tuya_eTRV_response(self, Devices, _ModelName, NwkId, srcEp, ClusterID,
                           dstNWKID, dstEP, dp, datatype, data)

    elif _ModelName == "TS0601-sirene":
        tuya_siren_response(self, Devices, _ModelName, NwkId, srcEp, ClusterID,
                            dstNWKID, dstEP, dp, datatype, data)

    elif _ModelName == "TS0601-dimmer":
        tuya_dimmer_response(self, Devices, _ModelName, NwkId, srcEp,
                             ClusterID, dstNWKID, dstEP, dp, datatype, data)

    elif _ModelName == "TS0601-Energy":
        tuya_energy_response(self, Devices, _ModelName, NwkId, srcEp,
                             ClusterID, dstNWKID, dstEP, dp, datatype, data)

    else:
        attribute_name = "UnknowDp_0x%02x_Dt_0x%02x" % (dp, datatype)
        store_tuya_attribute(self, NwkId, attribute_name, data)
        self.log.logging(
            "Tuya",
            "Log",
            "tuya_response - Model: %s UNMANAGED Nwkid: %s/%s dp: %02x data type: %s data: %s"
            % (_ModelName, NwkId, srcEp, dp, datatype, data),
            NwkId,
        )
Exemplo n.º 9
0
def tuyaReadRawAPS(self, Devices, NwkId, srcEp, ClusterID, dstNWKID, dstEP,
                   MsgPayload):

    # 19 79 06 00006c02000400000033

    if NwkId not in self.ListOfDevices:
        return
    if ClusterID != "ef00":
        return
    if "Model" not in self.ListOfDevices[NwkId]:
        return
    _ModelName = self.ListOfDevices[NwkId]["Model"]

    if len(MsgPayload) < 6:
        self.log.logging(
            "Tuya", "Debug2",
            "tuyaReadRawAPS - MsgPayload %s too short" % (MsgPayload), NwkId)
        return

    fcf = MsgPayload[0:2]  # uint8
    sqn = MsgPayload[2:4]  # uint8
    updSQN(self, NwkId, sqn)

    cmd = MsgPayload[4:6]  # uint8

    # Send a Default Response ( why might check the FCF eventually )
    if self.FirmwareVersion and int(self.FirmwareVersion, 16) < 0x031E:
        tuya_send_default_response(self, NwkId, srcEp, sqn, cmd, fcf)

    # https://developer.tuya.com/en/docs/iot/tuuya-zigbee-door-lock-docking-access-standard?id=K9ik5898uzqrk

    if cmd == "01":  # TY_DATA_RESPONE
        status = MsgPayload[6:8]  # uint8
        transid = MsgPayload[8:10]  # uint8
        dp = int(MsgPayload[10:12], 16)
        datatype = int(MsgPayload[12:14], 16)
        fn = MsgPayload[14:16]
        len_data = MsgPayload[16:18]
        data = MsgPayload[18:]
        self.log.logging(
            "Tuya",
            "Debug2",
            "tuyaReadRawAPS - command %s MsgPayload %s/ Data: %s" %
            (cmd, MsgPayload, MsgPayload[6:]),
            NwkId,
        )
        tuya_response(self, Devices, _ModelName, NwkId, srcEp, ClusterID,
                      dstNWKID, dstEP, dp, datatype, data)

    elif cmd == "02":  # TY_DATA_REPORT
        status = MsgPayload[6:8]  # uint8
        transid = MsgPayload[8:10]  # uint8
        dp = int(MsgPayload[10:12], 16)
        datatype = int(MsgPayload[12:14], 16)
        fn = MsgPayload[14:16]
        len_data = MsgPayload[16:18]
        data = MsgPayload[18:]
        self.log.logging(
            "Tuya",
            "Debug2",
            "tuyaReadRawAPS - command %s MsgPayload %s/ Data: %s" %
            (cmd, MsgPayload, MsgPayload[6:]),
            NwkId,
        )
        tuya_response(self, Devices, _ModelName, NwkId, srcEp, ClusterID,
                      dstNWKID, dstEP, dp, datatype, data)

    elif cmd == "06":  # TY_DATA_SEARCH
        status = MsgPayload[6:8]  # uint8
        transid = MsgPayload[8:10]  # uint8
        dp = int(MsgPayload[10:12], 16)
        datatype = int(MsgPayload[12:14], 16)
        fn = MsgPayload[14:16]
        len_data = MsgPayload[16:18]
        data = MsgPayload[18:]
        self.log.logging(
            "Tuya",
            "Debug2",
            "tuyaReadRawAPS - command %s MsgPayload %s/ Data: %s" %
            (cmd, MsgPayload, MsgPayload[6:]),
            NwkId,
        )
        tuya_response(self, Devices, _ModelName, NwkId, srcEp, ClusterID,
                      dstNWKID, dstEP, dp, datatype, data)

    elif cmd == "0b":  # ??
        pass

    elif cmd == "10":  # ???
        pass

    elif cmd == "11":  # MCU_VERSION_RSP ( Return version or actively report version )
        # Model: TS0601-switch UNMANAGED Nwkid: 92d9/01 fcf: 09 sqn: 6c cmd: 11 data: 02f840
        try:
            transid = MsgPayload[6:10]  # uint16
            version = MsgPayload[10:12]  # int8
            store_tuya_attribute(self, NwkId, "TUYA_MCU_VERSION_RSP", version)
        except:
            Domoticz.Error(
                "tuyaReadRawAPS - MCU_VERSION_RSP error on Payload: %s" %
                MsgPayload)

    elif cmd == "23":  # TUYA_REPORT_LOG
        pass

    elif cmd == "24":  # Time Synchronisation
        send_timesynchronisation(self, NwkId, srcEp, ClusterID, dstNWKID,
                                 dstEP, MsgPayload[6:])

    else:
        self.log.logging(
            "Tuya",
            "Log",
            "tuyaReadRawAPS - Model: %s UNMANAGED Nwkid: %s/%s fcf: %s sqn: %s cmd: %s data: %s"
            % (_ModelName, NwkId, srcEp, fcf, sqn, cmd, MsgPayload[6:]),
            NwkId,
        )
Exemplo n.º 10
0
def tuya_energy_response(self, Devices, _ModelName, NwkId, srcEp, ClusterID,
                         dstNWKID, dstEP, dp, datatype, data):

    if dp == 0x01 and datatype == 0x01:  # State On/Off
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_energy_response - Model: %s State Nwkid: %s/%s dp: %02x data type: %s data: %s"
            % (_ModelName, NwkId, srcEp, dp, datatype, data),
            NwkId,
        )
        store_tuya_attribute(self, NwkId, "State", data)
        MajDomoDevice(self, Devices, NwkId, "01", "0006", data)

    elif dp == 0x09:  # Countdown
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_energy_response - Model: %s State Nwkid: %s/%s dp: %02x data type: %s data: %s"
            % (_ModelName, NwkId, srcEp, dp, datatype, data),
            NwkId,
        )
        store_tuya_attribute(self, NwkId, "Countdown", data)

    elif dp == 0x11:  # Total Energy * 10
        analogValue = int(data, 16) * 10
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_energy_response - Model: %s Energy Nwkid: %s/%s dp: %02x data type: %s data: %s"
            % (_ModelName, NwkId, srcEp, dp, datatype, data),
            NwkId,
        )
        MajDomoDevice(self,
                      Devices,
                      NwkId,
                      "01",
                      "0702",
                      str(analogValue),
                      Attribute_="0000")
        checkAndStoreAttributeValue(self, NwkId, "01", "0702", "0000",
                                    analogValue)  # Store int
        store_tuya_attribute(self, NwkId, "Energy", str(analogValue))

    elif dp == 0x12:  # Current (Ampere) / 1000
        analogValue = int(data, 16) / 1000
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_energy_response - Model: %s Current Nwkid: %s/%s dp: %02x data type: %s data: %s"
            % (_ModelName, NwkId, srcEp, dp, datatype, data),
            NwkId,
        )
        MajDomoDevice(self,
                      Devices,
                      NwkId,
                      "01",
                      "0b04",
                      str(analogValue),
                      Attribute_="0508")
        store_tuya_attribute(self, NwkId, "Current", str(analogValue))

    elif dp == 0x13:  # Power / 10
        analogValue = int(data, 16) / 10
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_energy_response - Model: %s Power Nwkid: %s/%s dp: %02x data type: %s data: %s"
            % (_ModelName, NwkId, srcEp, dp, datatype, data),
            NwkId,
        )
        checkAndStoreAttributeValue(self, NwkId, "01", "0702", "0400",
                                    str(analogValue))
        MajDomoDevice(self, Devices, NwkId, "01", "0702", str(analogValue))
        store_tuya_attribute(self, NwkId, "InstantPower",
                             str(analogValue))  # Store str

    elif dp == 0x14:  # Voltage / 10
        analogValue = int(data, 16) / 10
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_energy_response - Model: %s Voltage Nwkid: %s/%s dp: %02x data type: %s data: %s"
            % (_ModelName, NwkId, srcEp, dp, datatype, data),
            NwkId,
        )
        MajDomoDevice(self, Devices, NwkId, "01", "0001", str(analogValue))
        store_tuya_attribute(self, NwkId, "Voltage", str(analogValue))

    elif dp == 0x0E:  # tuya_switch_relay_status
        store_tuya_attribute(self, NwkId, "RelayStatus", data)

    elif dp == 0x0F:  # Led Indicator
        store_tuya_attribute(self, NwkId, "LedIndicator", data)

    elif dp == 0x1D:
        store_tuya_attribute(self, NwkId, "ChildLock", data)

    else:
        self.log.logging(
            "Tuya",
            "Debug",
            "tuya_energy_response - Model: %s Unknow Nwkid: %s/%s dp: %02x data type: %s data: %s"
            % (_ModelName, NwkId, srcEp, dp, datatype, data),
            NwkId,
        )
Exemplo n.º 11
0
def tuya_smartair_response(self, Devices, _ModelName, NwkId, srcEp, ClusterID,
                           dstNWKID, dstEP, dp, datatype, data):

    #             cmd | status | transId | dp | DataType | fn | len | Data
    #              01     00        00     12     02        00   04    00000101   257   --- Temperature
    #              01     00        00     13     02        00   04    0000018d   397   --- Humidity  Confirmed
    #              01     00        01     16     02        00   04    00000002     2   --- 0.002 ppm Formaldéhyde détécté
    #              01     00        01     15     02        00   04    00000001     1   --- VOC 0.1 ppm - Confirmed
    #              01     00        01     02     02        00   04    00000172   370   --- CO2 - Confirmed

    # The device is flooding data every seconds. This could have the impact to flow the Domoticz database/
    if ("Param" in self.ListOfDevices[NwkId]
            and "AcquisitionFrequency" in self.ListOfDevices[NwkId]["Param"]
            and
            self.ListOfDevices[NwkId]["Param"]["AcquisitionFrequency"] > 0):
        previous_ts = get_tuya_attribute(self, NwkId, "TimeStamp_%s" % dp)
        if previous_ts and (previous_ts + self.ListOfDevices[NwkId]["Param"]
                            ["AcquisitionFrequency"]) > time.time():
            return
        store_tuya_attribute(self, NwkId, "TimeStamp_%s" % dp, time.time())

    # Temp/Humi/CarbonDioxyde/CH20/Voc
    if dp == 0x02:  # CO2 ppm
        co2_Attribute = "0005"
        co2_ppm = int(data, 16)
        store_tuya_attribute(
            self,
            NwkId,
            "CO2 ppm",
            co2_ppm,
        )
        MajDomoDevice(self,
                      Devices,
                      NwkId,
                      srcEp,
                      "0402",
                      co2_ppm,
                      Attribute_=co2_Attribute)

    elif dp == 0x12:  # Temperature
        temp = int(data, 16) / 10
        store_tuya_attribute(self, NwkId, "Temp", temp)
        MajDomoDevice(self, Devices, NwkId, srcEp, "0402", temp)

    elif dp == 0x13:  # Humidity %
        humi = int(data, 16) // 10
        store_tuya_attribute(self, NwkId, "Humi", humi)
        MajDomoDevice(self, Devices, NwkId, srcEp, "0405", humi)

    elif dp == 0x15:  # VOC ppm
        voc_Attribute = "0003"
        voc_ppm = int(data, 16) / 10
        store_tuya_attribute(self, NwkId, "VOC ppm", voc_ppm)
        MajDomoDevice(self,
                      Devices,
                      NwkId,
                      srcEp,
                      "0402",
                      voc_ppm,
                      Attribute_=voc_Attribute)

    elif dp == 0x16:  # Formaldéhyde µg/m3 ( Méthanal / CH2O_ppm)
        ch2O_Attribute = "0004"
        CH2O_ppm = int(data, 16)
        store_tuya_attribute(self, NwkId, "CH2O ppm", CH2O_ppm)
        MajDomoDevice(self,
                      Devices,
                      NwkId,
                      srcEp,
                      "0402",
                      CH2O_ppm,
                      Attribute_=ch2O_Attribute)