예제 #1
0
def tuya_siren_humi_alarm(self, nwkid, onoff):
    self.log.logging("Tuya", "Debug", "tuya_siren_humi_alarm - %s onoff: %s" % (nwkid, onoff))
    min_humi = 25
    max_humi = 75

    if onoff:
        if (
            "Param" in self.ListOfDevices[nwkid]
            and "HumidityMinAlarm" in self.ListOfDevices[nwkid]["Param"]
            and isinstance(self.ListOfDevices[nwkid]["Param"]["HumidityMinAlarm"], int)
        ):
            min_humi = self.ListOfDevices[nwkid]["Param"]["HumidityMinAlarm"]

        if (
            "Param" in self.ListOfDevices[nwkid]
            and "HumidityMaxAlarm" in self.ListOfDevices[nwkid]["Param"]
            and isinstance(self.ListOfDevices[nwkid]["Param"]["HumidityMaxAlarm"], int)
        ):
            max_humi = self.ListOfDevices[nwkid]["Param"]["HumidityMaxAlarm"]
        tuya_siren_alarm_humidity(self, nwkid, min_humi, max_humi)

    # determine which Endpoint
    EPout = "01"
    sqn = get_and_inc_SQN(self, nwkid)
    cluster_frame = "11"
    cmd = "00"  # Command
    action = "%04x" % struct.unpack("H", struct.pack(">H", 0x0172))[0]
    data = "%02x" % onoff
    tuya_cmd(self, nwkid, EPout, cluster_frame, sqn, cmd, action, data)
예제 #2
0
def tuya_watertimer_command(self, NwkId, onoff, gang=0x01):

    self.log.logging(
        "Tuya", "Debug", "tuya_switch_command - %s OpenClose: %s on gang: %s" %
        (NwkId, onoff, gang), NwkId)
    # determine which Endpoint
    if gang not in (0x01, 0x02, 0x03):
        self.log.logging("Tuya", "Error",
                         "tuya_switch_command - Unexpected Gang: %s" % gang)
        return
    if onoff not in ("00", "01"):
        self.log.logging("Tuya", "Error",
                         "tuya_switch_command - Unexpected OnOff: %s" % onoff)
        return

    EPout = "01"
    cluster_frame = "11"
    cmd = "00"  # Command

    if onoff == "01":
        sqn = get_and_inc_SQN(self, NwkId)
        action = "0b02"
        data = "0000012c"
        tuya_cmd(self, NwkId, EPout, cluster_frame, sqn, cmd, action, data)

    sqn = get_and_inc_SQN(self, NwkId)
    action = "%02x01" % gang  # Data Type 0x01 - Bool
    data = onoff
    self.log.logging(
        "Tuya", "Debug",
        "tuya_switch_command - action: %s data: %s" % (action, data))
    tuya_cmd(self, NwkId, EPout, cluster_frame, sqn, cmd, action, data)
예제 #3
0
def tuya_garage_door_action(self, NwkId, action):
    # 000f/0101/0001/00
    # 0010/0101/0001/01
    EPout = "01"
    sqn = get_and_inc_SQN(self, NwkId)
    cluster_frame = "11"
    cmd = "00"  # Command
    action = "0101"
    data = "%02x" % int(action)
    tuya_cmd(self, NwkId, EPout, cluster_frame, sqn, cmd, action, data)
예제 #4
0
def tuya_curtain_openclose(self, NwkId, openclose):
    self.log.logging(
        "Tuya", "Debug",
        "tuya_curtain_openclose - %s OpenClose: %s" % (NwkId, openclose),
        NwkId)
    # determine which Endpoint
    EPout = "01"
    sqn = get_and_inc_SQN(self, NwkId)
    cluster_frame = "11"
    cmd = "00"  # Command
    action = "0101"
    data = openclose
    tuya_cmd(self, NwkId, EPout, cluster_frame, sqn, cmd, action, data)
예제 #5
0
def tuya_dimmer_onoff(self, NwkId, srcEp, OnOff):

    self.log.logging("Tuya", "Debug",
                     "tuya_dimmer_onoff - %s OnOff: %s" % (NwkId, OnOff),
                     NwkId)
    # determine which Endpoint
    EPout = "01"
    sqn = get_and_inc_SQN(self, NwkId)
    cluster_frame = "11"
    cmd = "00"  # Command
    action = "0101"
    data = OnOff
    tuya_cmd(self, NwkId, EPout, cluster_frame, sqn, cmd, action, data)
예제 #6
0
def tuya_energy_childLock(self, NwkId, lock=0x01):
    # 0012 1d 01 0001 00 Child Unlock
    # 0011 1d 01 0001 01 Child Lock

    EPout = "01"
    sqn = get_and_inc_SQN(self, NwkId)
    cluster_frame = "11"
    cmd = "00"  # Command
    action = "1d01"
    data = "%02x" % lock
    self.log.logging(
        "Tuya", "Debug",
        "tuya_energy_childLock - action: %s data: %s" % (action, data))
    tuya_cmd(self, NwkId, EPout, cluster_frame, sqn, cmd, action, data)
예제 #7
0
def tuya_curtain_lvl(self, NwkId, percent):
    self.log.logging("Tuya", "Debug",
                     "tuya_curtain_lvl - %s percent: %s" % (NwkId, percent),
                     NwkId)

    level = percent
    # determine which Endpoint
    EPout = "01"
    sqn = get_and_inc_SQN(self, NwkId)
    cluster_frame = "11"
    cmd = "00"  # Command
    action = "0202"
    data = "%08x" % level
    tuya_cmd(self, NwkId, EPout, cluster_frame, sqn, cmd, action, data)
예제 #8
0
def tuya_siren_alarm_melody(self, nwkid, melody):
    # 18-Melodies 1 -> 18 ==> 0x00 -- 0x11
    # 1- 00 40 6604 0001 00
    # 2- 00 41 6604 0001 01

    self.log.logging("Tuya", "Debug", "tuya_siren_alarm_melody - %s onoff: %s" % (nwkid, melody))
    # determine which Endpoint
    EPout = "01"
    sqn = get_and_inc_SQN(self, nwkid)
    cluster_frame = "11"
    cmd = "00"  # Command
    action = "%04x" % struct.unpack("H", struct.pack(">H", 0x0466))[0]
    data = "%02x" % melody
    tuya_cmd(self, nwkid, EPout, cluster_frame, sqn, cmd, action, data)
예제 #9
0
def tuya_siren_alarm_volume(self, nwkid, volume):
    # 0-Max, 1-Medium, 2-Low
    # 0- 95db  00 3e 7404 0001 00
    # 1- 80db  00 3d 7404 0001 01
    # 2- 70db  00 3f 7404 0001 02
    self.log.logging("Tuya", "Debug", "tuya_siren_alarm_volume - %s volume: %s" % (nwkid, volume))
    # determine which Endpoint
    EPout = "01"
    sqn = get_and_inc_SQN(self, nwkid)
    cluster_frame = "11"
    cmd = "00"  # Command
    action = "%04x" % struct.unpack("H", struct.pack(">H", 0x0474))[0]
    data = "%02x" % volume
    tuya_cmd(self, nwkid, EPout, cluster_frame, sqn, cmd, action, data)
예제 #10
0
def tuya_siren_alarm_duration(self, nwkid, duration):
    # duration in second
    #     0s - 00 43 6702 0004 00000000
    #    10s - 00 44 6702 0004 0000000a
    #   250s - 00 45 6702 0004 000000fa
    #   300s - 00 46 6702 0004 0000012c

    self.log.logging("Tuya", "Debug", "tuya_siren_alarm_duration - %s duration: %s" % (nwkid, duration))
    # determine which Endpoint
    EPout = "01"
    sqn = get_and_inc_SQN(self, nwkid)
    cluster_frame = "11"
    cmd = "00"  # Command
    action = "%04x" % struct.unpack("H", struct.pack(">H", 0x0267))[0]
    data = "%08x" % duration
    tuya_cmd(self, nwkid, EPout, cluster_frame, sqn, cmd, action, data)
예제 #11
0
def tuya_energy_countdown(self, NwkId, timing):

    # Countdown is 0x09 for Energy device
    # Countdown is 0x42 for Multigang Switch : https://developer.tuya.com/en/docs/iot/tuya-zigbee-multiple-switch-access-standard?id=K9ik6zvnqr09m#title-15-Countdown

    self.log.logging("Tuya", "Debug",
                     "tuya_energy_countdown - %s timing: %s" % (NwkId, timing),
                     NwkId)

    EPout = "01"
    sqn = get_and_inc_SQN(self, NwkId)
    cluster_frame = "11"
    cmd = "00"  # Command
    action = "0902"
    data = "%08x" % timing
    tuya_cmd(self, NwkId, EPout, cluster_frame, sqn, cmd, action, data)
예제 #12
0
def tuya_siren_temp_unit(self, nwkid, unit="C"):
    # From °c to °F: 00 39 7001 0001 00
    #                00 3b 7001 0001 00

    # From °F to °c: 00 3a 7001 0001 01
    #                00 3c 7001 0001 01
    unit = 0x01 if unit != "F" else 0x00
    self.log.logging("Tuya", "Debug", "tuya_siren_temp_unit - %s Unit Temp: %s" % (nwkid, unit))
    # determine which Endpoint
    EPout = "01"
    sqn = get_and_inc_SQN(self, nwkid)
    cluster_frame = "11"
    cmd = "00"  # Command
    action = "%04x" % struct.unpack("H", struct.pack(">H", 0x0170))[0]
    data = "%02x" % unit

    tuya_cmd(self, nwkid, EPout, cluster_frame, sqn, cmd, action, data)
예제 #13
0
def tuya_siren_alarm_humidity(self, nwkid, min_humi_alarm, max_humi_alarm):
    #                  Max humi            Min humi
    # 00 34 6e02 00 04 00000058 6d02 00 04 0000000c
    # 00 36 7201 00 01 01
    self.log.logging(
        "Tuya",
        "Debug",
        "tuya_siren_alarm_min_humidity - %s Min Humi: %s Max Humid: %s" % (nwkid, min_humi_alarm, max_humi_alarm),
    )
    # determine which Endpoint
    EPout = "01"
    sqn = get_and_inc_SQN(self, nwkid)
    cluster_frame = "11"
    cmd = "00"  # Command
    action1 = "%04x" % struct.unpack("H", struct.pack(">H", 0x026E))[0]
    data1 = "%08x" % max_humi_alarm

    action2 = "%04x" % struct.unpack("H", struct.pack(">H", 0x026D))[0]
    data2 = "%08x" % min_humi_alarm
    tuya_cmd(self, nwkid, EPout, cluster_frame, sqn, cmd, action1, data1, action2, data2)
예제 #14
0
def tuya_energy_onoff(self, NwkId, OnOff):
    # 0013 01 01 0001 01 Power On
    # 0014 01 01 0001 00 Power Off
    self.log.logging("Tuya", "Debug",
                     "tuya_energy_onoff - %s OnOff: %s" % (NwkId, OnOff),
                     NwkId)

    if ("Param" in self.ListOfDevices[NwkId]
            and "Countdown" in self.ListOfDevices[NwkId]["Param"]
            and self.ListOfDevices[NwkId]["Param"]["Countdown"]):
        tuya_energy_countdown(
            self, NwkId, int(self.ListOfDevices[NwkId]["Param"]["Countdown"]))
    else:
        EPout = "01"
        sqn = get_and_inc_SQN(self, NwkId)
        cluster_frame = "11"
        cmd = "00"  # Command
        action = "0101"
        data = OnOff
        tuya_cmd(self, NwkId, EPout, cluster_frame, sqn, cmd, action, data)
예제 #15
0
def tuya_siren_alarm_temp(self, nwkid, min_temp_alarm, max_temp):
    # Enable Temp Alarm 18° <---> 33°c
    #                  Max temp                Min temp
    # 00 23 6c02 00 04 00000021     6b02 00 04 00000012
    # 00 24 7101 00 01 01
    #
    self.log.logging(
        "Tuya", "Debug", "tuya_siren_alarm_min_temp - %s Min Temp: %s Max Temp: %s" % (nwkid, min_temp_alarm, max_temp)
    )
    # determine which Endpoint
    EPout = "01"
    sqn = get_and_inc_SQN(self, nwkid)
    cluster_frame = "11"
    cmd = "00"  # Command
    action1 = "%04x" % struct.unpack("H", struct.pack(">H", 0x026C))[0]
    data1 = "%08x" % max_temp

    action2 = "%04x" % struct.unpack("H", struct.pack(">H", 0x026B))[0]
    data2 = "%08x" % min_temp_alarm

    tuya_cmd(self, nwkid, EPout, cluster_frame, sqn, cmd, action1, data1, action2, data2)
예제 #16
0
def tuya_siren_alarm(self, nwkid, onoff, alarm_num=1):

    self.log.logging("Tuya", "Debug", "tuya_siren_alarm - %s onoff: %s" % (nwkid, onoff))
    duration = 5
    volume = 2
    if onoff == 0x01:
        alarm_attr = get_alarm_attrbutes(self, nwkid, alarm_num)
        duration = alarm_attr["Duration"]
        volume = alarm_attr["Volume"]
        melody = alarm_attr["Melody"]

        tuya_siren_alarm_duration(self, nwkid, duration)
        tuya_siren_alarm_volume(self, nwkid, volume)
        tuya_siren_alarm_melody(self, nwkid, melody)

    # determine which Endpoint
    EPout = "01"
    sqn = get_and_inc_SQN(self, nwkid)
    cluster_frame = "11"
    cmd = "00"  # Command
    action = "%04x" % struct.unpack("H", struct.pack(">H", 0x0168))[0]
    data = "%02x" % onoff
    tuya_cmd(self, nwkid, EPout, cluster_frame, sqn, cmd, action, data)
예제 #17
0
def tuya_switch_indicate_light(self, NwkId, light=0x01):
    # 0005 0f 04 0001 00 -- Indicate Off
    # 0004 0f 04 0001 01 -- Indicate Switch ( On when On)
    # 0006 0f 04 0001 02 -- Indicate Position (on when Off )
    self.log.logging(
        "Tuya", "Debug",
        "tuya_switch_indicate_light - %s Light: %s" % (NwkId, light), NwkId)
    # determine which Endpoint
    if light not in (0x00, 0x01, 0x02):
        self.log.logging(
            "Tuya", "Error",
            "tuya_switch_indicate_light - Unexpected light: %s" % light)
        return

    EPout = "01"
    sqn = get_and_inc_SQN(self, NwkId)
    cluster_frame = "11"
    cmd = "00"  # Command
    action = "0f04"
    data = "%02x" % light
    self.log.logging(
        "Tuya", "Debug",
        "tuya_switch_indicate_light - action: %s data: %s" % (action, data))
    tuya_cmd(self, NwkId, EPout, cluster_frame, sqn, cmd, action, data)
예제 #18
0
def tuya_switch_relay_status(self, NwkId, gang=0x01, status=0xFF):
    # 00070 e04 0001 02  -- Remember last status
    # 00080 e04 0001 01  -- On
    # 00090 e04 0001 00  -- Off
    self.log.logging(
        "Tuya", "Debug",
        "tuya_switch_relay_status - %s Light: %s" % (NwkId, status), NwkId)
    # determine which Endpoint
    if status not in (0x00, 0x01, 0x02, 0xFF):
        self.log.logging(
            "Tuya", "Error",
            "tuya_switch_relay_status - Unexpected light: %s" % status)
        return

    EPout = "01"
    sqn = get_and_inc_SQN(self, NwkId)
    cluster_frame = "11"
    cmd = "00"  # Command
    action = "0e04"
    data = "%02x" % status
    self.log.logging(
        "Tuya", "Debug",
        "tuya_switch_relay_status - action: %s data: %s" % (action, data))
    tuya_cmd(self, NwkId, EPout, cluster_frame, sqn, cmd, action, data)