Exemplo n.º 1
0
def handle_color_mode_4(self, nwkid, EPout, Hue_List):
    # Gledopto GL_008
    # Color: {"b":43,"cw":27,"g":255,"m":4,"r":44,"t":227,"ww":215}
    self.log.logging("Command", "Log", "Not fully implemented device color 4",
                     nwkid)
    transitionMoveLevel, transitionRGB, transitionMoveLevel, transitionHue, transitionTemp = get_all_transition_mode(
        self, nwkid)
    # Process White color
    cw = int(Hue_List["cw"])  # 0 < cw < 255 Cold White
    ww = int(Hue_List["ww"])  # 0 < ww < 255 Warm White
    if cw != 0 and ww != 0:
        TempKelvin = int(((255 - int(ww)) * (6500 - 1700) / 255) + 1700)
        TempMired = 1000000 // TempKelvin
        self.log.logging(
            "Command", "Log", "handle_color_mode_4 Set Temp Kelvin: %s-%s" %
            (TempMired, Hex_Format(4, TempMired)), nwkid)
        zcl_move_to_colour_temperature(self, nwkid, EPout,
                                       Hex_Format(4, TempMired),
                                       transitionTemp)

    # Process Colour
    h, s, l = rgb_to_hsl(
        (int(Hue_List["r"]), int(Hue_List["g"]), int(Hue_List["b"])))
    saturation = s * 100  # 0 > 100
    hue = h * 360  # 0 > 360
    hue = int(hue * 254 // 360)
    saturation = int(saturation * 254 // 100)
    self.log.logging(
        "Command", "Log",
        "handle_color_mode_4 Set Hue X: %s Saturation: %s" % (hue, saturation),
        nwkid)
    zcl_move_hue_and_saturation(self, nwkid, EPout, Hex_Format(2, hue),
                                Hex_Format(2, saturation), transitionRGB)
Exemplo n.º 2
0
def handle_color_mode_2(self, nwkid, EPout, Hue_List):
    # Value is in mireds (not kelvin)
    # Correct values are from 153 (6500K) up to 588 (1700K)
    # t is 0 > 255
    TempKelvin = int(((255 - int(Hue_List["t"])) * (6500 - 1700) / 255) + 1700)
    TempMired = 1000000 // TempKelvin
    self.log.logging(
        "Command", "Debug", "handle_color_mode_2 Set Temp Kelvin: %s-%s" %
        (TempMired, Hex_Format(4, TempMired)), nwkid)
    transitionMoveLevel, transitionRGB, transitionMoveLevel, transitionHue, transitionTemp = get_all_transition_mode(
        self, nwkid)
    zcl_move_to_colour_temperature(self, nwkid, EPout,
                                   Hex_Format(4, TempMired), transitionTemp)
Exemplo n.º 3
0
def handle_color_mode_3(self, nwkid, EPout, Hue_List):
    x, y = rgb_to_xy(
        (int(Hue_List["r"]), int(Hue_List["g"]), int(Hue_List["b"])))
    # Convert 0>1 to 0>FFFF
    x = int(x * 65536)
    y = int(y * 65536)
    #strxy = Hex_Format(4, x) + Hex_Format(4, y)
    self.log.logging("Command", "Debug",
                     "handle_color_mode_3 Set Temp X: %s Y: %s" % (x, y),
                     nwkid)
    transitionMoveLevel, transitionRGB, transitionMoveLevel, transitionHue, transitionTemp = get_all_transition_mode(
        self, nwkid)
    zcl_move_to_colour(self, nwkid, EPout, Hex_Format(4, x), Hex_Format(4, y),
                       transitionRGB)
Exemplo n.º 4
0
def set_rgb_color(self, mode, addr, EPin, EPout, r, g, b, transit="0000"):

    x, y = rgb_to_xy((int(r), int(g), int(b)))
    # Convert 0 > 1 to 0 > FFFF
    x = int(x * 65536)
    y = int(y * 65536)
    #strxy = Hex_Format(4, x) + Hex_Format(4, y)
    #zigate_cmd = "00B7"
    #zigate_param = strxy + transit
    #datas = "%02d" % mode + addr + ZIGATE_EP + EPout + zigate_param

    #self.logging("Debug", "Command: %s - data: %s" % (zigate_cmd, datas))
    #self.ZigateComm.sendData(zigate_cmd, datas)
    zcl_group_move_to_colour(self, addr, ZIGATE_EP, EPout, Hex_Format(4, x),
                             Hex_Format(4, y), transit)
Exemplo n.º 5
0
def handle_color_mode_9998(self, nwkid, EPout, Hue_List):
    transitionMoveLevel, transitionRGB, transitionMoveLevel, transitionHue, transitionTemp = get_all_transition_mode(
        self, nwkid)
    h, s, l = rgb_to_hsl(
        (int(Hue_List["r"]), int(Hue_List["g"]), int(Hue_List["b"])))
    saturation = s * 100  # 0 > 100
    hue = h * 360  # 0 > 360
    hue = int(hue * 254 // 360)
    saturation = int(saturation * 254 // 100)
    self.log.logging(
        "Command", "Debug",
        "handle_color_mode_9998 Set Hue X: %s Saturation: %s" %
        (hue, saturation), nwkid)
    zcl_move_hue_and_saturation(self, nwkid, EPout, Hex_Format(2, hue),
                                Hex_Format(2, saturation), transitionRGB)

    value = int(l * 254 // 100)
    OnOff = "01"
    self.log.logging(
        "Command", "Debug",
        "handle_color_mode_9998 Set Level: %s instead of Level: %s" %
        (value, value), nwkid)
    actuator_setlevel(self, nwkid, EPout, value, "Light", transitionMoveLevel)
Exemplo n.º 6
0
def set_hue_saturation(self, mode, addr, EPin, EPout, r, g, b, transit=None):

    h, s, l = rgb_to_hsl((int(r), int(g), int(b)))

    saturation = s * 100  # r
    hue = h * 360  # 0 > 360
    hue = int(hue * 254 // 360)
    saturation = int(saturation * 254 // 100)
    self.logging("Log",
                 "---------- Set Hue X: %s Saturation: %s" % (hue, saturation))
    #self.ZigateComm.sendData(
    #    "00B6",
    #    "%02d" % ADDRESS_MODE["group"]
    #    + addr
    #    + ZIGATE_EP
    #    + EPout
    #    + Hex_Format(2, hue)
    #    + Hex_Format(2, saturation)
    #    + transit,
    #)
    zcl_group_move_hue_and_saturation(self, addr, ZIGATE_EP, EPout,
                                      Hex_Format(2, hue),
                                      Hex_Format(2, saturation), transit)
    return l
Exemplo n.º 7
0
def set_kelvin_color(self, mode, addr, EPin, EPout, t, transit="0000"):
    # Value is in mireds (not kelvin)
    # Correct values are from 153 (6500K) up to 588 (1700K)
    # t is 0 > 255

    TempKelvin = int(((255 - int(t)) * (6500 - 1700) / 255) + 1700)
    TempMired = 1000000 // TempKelvin
    #zigate_cmd = "00C0"
    #zigate_param = Hex_Format(4, TempMired) + transit
    #datas = "%02d" % mode + addr + EPin + EPout + zigate_param

    #self.logging("Debug", "Command: %s - data: %s" % (zigate_cmd, datas))
    #self.ZigateComm.sendData(zigate_cmd, datas)
    zcl_group_move_to_colour_temperature(self, addr, EPin, EPout,
                                         Hex_Format(4, TempMired), transit)
Exemplo n.º 8
0
def actuator_setlevel(self,
                      nwkid,
                      EPout,
                      value,
                      DeviceType,
                      transition="0010"):

    if DeviceType == "ThermoMode":
        actuator_setthermostat(self, nwkid, EPout, value)
    elif DeviceType == "ThermoSetpoint":
        actuator_setpoint(self, nwkid, EPout, value)
    elif DeviceType == "AlarmWD":
        actuator_setalarm(self, nwkid, EPout, value)
    elif DeviceType == "WindowCovering":
        # https://github.com/fairecasoimeme/ZiGate/issues/125#issuecomment-456085847
        if value == 0:
            value = 1
        elif value >= 100:
            value = 99
        value = "%02x" % value
        self.log.logging(
            "Command",
            "Log",
            "WindowCovering - Lift Percentage Command - %s/%s value: 0x%s %s" %
            (nwkid, EPout, value, value),
        )
        zcl_window_coverting_level(self, nwkid, EPout, value)
    else:
        OnOff = "01"  # 00 = off, 01 = on
        if value == 100:
            value = 255
        elif value == 0:
            value = 0
        else:
            value = round((value * 255) / 100)
            if value > 0 and value == 0:
                value = 1

        value = Hex_Format(2, value)
        zcl_level_move_to_level(self, nwkid, EPout, OnOff, value, transition)
Exemplo n.º 9
0
def processCommand(self, unit, GrpId, Command, Level, Color_):

    # Begin
    self.logging(
        "Debug",
        "processGroupCommand - unit: %s, NwkId: %s, cmd: %s, level: %s, color: %s"
        % (unit, GrpId, Command, Level, Color_),
    )

    if GrpId not in self.ListOfGroups:
        return

    # Not sure that Groups are always on EP 01 !!!!!
    EPout = "01"

    if ("Cluster" in self.ListOfGroups[GrpId] and
            self.ListOfGroups[GrpId]["Cluster"] == "0102"):  # Venetian store
        #zigate_cmd = "00FA"
        if Command == "Off":
            zigate_param = "00"
            nValue = 0
            sValue = "Off"
            update_device_list_attribute(self, GrpId, "0102", 0)
            zcl_group_window_covering_on(self, GrpId, ZIGATE_EP, EPout)

        if Command == "On":
            zigate_param = "01"
            nValue = 1
            sValue = "Off"
            zcl_group_window_covering_off(self, GrpId, ZIGATE_EP, EPout)
            update_device_list_attribute(self, GrpId, "0102", 100)

        if Command == "Stop":
            zigate_param = "02"
            nValue = 2
            sValue = "50"
            zcl_group_window_covering_stop(self, GrpId, ZIGATE_EP, EPout)
            update_device_list_attribute(self, GrpId, "0102", 50)

        self.Devices[unit].Update(nValue=int(nValue), sValue=str(sValue))
        #datas = "%02d" % ADDRESS_MODE["group"] + GrpId + ZIGATE_EP + EPout + zigate_param
        #self.logging("Debug", "Group Command: %s %s-%s" % (Command, zigate_cmd, datas))
        #self.ZigateComm.sendData(zigate_cmd, datas, ackIsDisabled=True)
        resetDevicesHearttBeat(self, GrpId)
        return

    # Old Fashon
    if Command == "Off":
        if self.pluginconf.pluginConf["GrpfadingOff"]:
            if self.pluginconf.pluginConf["GrpfadingOff"] == 1:
                effect = "0002"  # 50% dim down in 0.8 seconds then fade to off in 12 seconds
            elif self.pluginconf.pluginConf["GrpfadingOff"] == 2:
                effect = "0100"  # 20% dim up in 0.5s then fade to off in 1 second
            elif self.pluginconf.pluginConf["GrpfadingOff"] == 255:
                effect = "0001"  # No fade

            #zigate_cmd = "0094"
            #datas = "%02d" % ADDRESS_MODE["group"] + GrpId + ZIGATE_EP + EPout + effect
            zcl_group_onoff_off_witheffect(self, GrpId, ZIGATE_EP, EPout,
                                           effect)
        else:
            #zigate_cmd = "0092"
            #datas = "%02d" % ADDRESS_MODE["group"] + GrpId + ZIGATE_EP + EPout + "00"
            zcl_group_onoff_off_noeffect(self, GrpId, ZIGATE_EP, EPout)

        #self.logging("Debug", "Command: %s %s" % (Command, datas))
        #self.ZigateComm.sendData(zigate_cmd, datas, ackIsDisabled=True)

        # Update Device
        nValue = 0
        sValue = "Off"
        self.Devices[unit].Update(nValue=int(nValue), sValue=str(sValue))

        update_device_list_attribute(self, GrpId, "0006", "00")
        update_domoticz_group_device(self, GrpId)

    elif Command == "On":
        #zigate_cmd = "0092"
        #zigate_param = "01"
        nValue = "1"
        sValue = "On"
        self.Devices[unit].Update(nValue=int(nValue), sValue=str(sValue))
        update_device_list_attribute(self, GrpId, "0006", "01")
        update_domoticz_group_device(self, GrpId)
        zcl_group_onoff_on(self, GrpId, ZIGATE_EP, EPout)

        #datas = "%02d" % ADDRESS_MODE["group"] + GrpId + ZIGATE_EP + EPout + zigate_param
        #self.logging("Debug", "Command: %s %s" % (Command, datas))
        #self.ZigateComm.sendData(zigate_cmd, datas, ackIsDisabled=True)
        # Update Device
        nValue = 1
        sValue = "On"
        self.Devices[unit].Update(nValue=int(nValue), sValue=str(sValue))

    elif Command == "Set Level":
        # Level: % value of move
        # Converted to value , raw value from 0 to 255
        # sValue is just a string of Level
        zigate_cmd = "0081"
        #OnOff = "01"
        # value = int(Level*255//100)
        value = "%02X" % int(Level * 255 // 100)
        #zigate_param = OnOff + value + "0010"
        #nValue = 1
        #sValue = str(Level)
        #self.Devices[unit].Update(nValue=int(nValue), sValue=str(sValue))
        update_device_list_attribute(self, GrpId, "0008", value)

        zcl_group_level_move_to_level(self, GrpId, ZIGATE_EP, EPout, "01",
                                      value, "0010")

        #datas = "%02d" % ADDRESS_MODE["group"] + GrpId + ZIGATE_EP + EPout + zigate_param
        #self.logging("Debug", "Command: %s %s" % (Command, datas))
        #self.ZigateComm.sendData(zigate_cmd, datas, ackIsDisabled=True)
        update_domoticz_group_device(self, GrpId)
        # Update Device
        nValue = 2
        sValue = str(Level)
        self.Devices[unit].Update(nValue=int(nValue), sValue=str(sValue))

    elif Command == "Set Color":
        Hue_List = json.loads(Color_)
        transitionRGB = "%04x" % self.pluginconf.pluginConf[
            "GrpmoveToColourRGB"]
        transitionMoveLevel = "%04x" % self.pluginconf.pluginConf[
            "GrpmoveToLevel"]
        transitionHue = "%04x" % self.pluginconf.pluginConf["GrpmoveToHueSatu"]
        transitionTemp = "%04x" % self.pluginconf.pluginConf[
            "GrpmoveToColourTemp"]

        # First manage level
        if Hue_List["m"] != 9998:
            # In case of m ==3, we will do the Setlevel
            #OnOff = "01"  # 00 = off, 01 = on
            value = Hex_Format(
                2, round(1 + Level * 254 / 100))  # To prevent off state
            #zigate_cmd = "0081"
            #zigate_param = OnOff + value + transitionMoveLevel

            #datas = "%02d" % ADDRESS_MODE["group"] + GrpId + ZIGATE_EP + EPout + zigate_param
            #self.logging("Debug", "Command: %s - data: %s" % (zigate_cmd, datas))
            update_device_list_attribute(self, GrpId, "0008", value)
            #self.ZigateComm.sendData(zigate_cmd, datas, ackIsDisabled=True)

            zcl_group_level_move_to_level(self, GrpId, ZIGATE_EP, EPout, "01",
                                          value, "0000")

        if Hue_List["m"] == 1:
            ww = int(
                Hue_List["ww"])  # Can be used as level for monochrome white
            self.logging("Debug", "Not implemented device color 1")

        # ColorModeTemp = 2   // White with color temperature. Valid fields: t
        if Hue_List["m"] == 2:
            set_kelvin_color(self,
                             ADDRESS_MODE["group"],
                             GrpId,
                             ZIGATE_EP,
                             EPout,
                             int(Hue_List["t"]),
                             transit=transitionTemp)

        elif Hue_List["m"] == 3:
            set_rgb_color(
                self,
                ADDRESS_MODE["group"],
                GrpId,
                ZIGATE_EP,
                EPout,
                int(Hue_List["r"]),
                int(Hue_List["g"]),
                int(Hue_List["b"]),
                transit=transitionRGB,
            )

        elif Hue_List["m"] == 4:
            # Gledopto GL_008
            # Color: {"b":43,"cw":27,"g":255,"m":4,"r":44,"t":227,"ww":215}
            self.logging("Log", "Not fully implemented device color 4")

            # Process White color
            cw = int(Hue_List["cw"])  # 0 < cw < 255 Cold White
            ww = int(Hue_List["ww"])  # 0 < ww < 255 Warm White
            if cw != 0 and ww != 0:
                set_kelvin_color(self,
                                 ADDRESS_MODE["group"],
                                 GrpId,
                                 ZIGATE_EP,
                                 EPout,
                                 int(ww),
                                 transit=transitionTemp)
            # Process Colour
            set_hue_saturation(
                self,
                ADDRESS_MODE["group"],
                GrpId,
                ZIGATE_EP,
                EPout,
                int(Hue_List["r"]),
                int(Hue_List["g"]),
                int(Hue_List["b"]),
                transit=transitionHue,
            )

        elif Hue_List["m"] == 9998:
            level = set_hue_saturation(
                self,
                ADDRESS_MODE["group"],
                GrpId,
                ZIGATE_EP,
                EPout,
                int(Hue_List["r"]),
                int(Hue_List["g"]),
                int(Hue_List["b"]),
                transit=transitionHue,
            )

            value = int(level * 254 // 100)
            OnOff = "01"
            self.logging(
                "Debug", "---------- Set Level: %s instead of Level: %s" %
                (value, Level))
            #self.ZigateComm.sendData(
            #    "0081",
            #    "%02d" % ADDRESS_MODE["group"]
            #    + GrpId
            #    + ZIGATE_EP
            #    + EPout
            #    + OnOff
            #    + Hex_Format(2, value)
            #    + transitionMoveLevel,
            #    ackIsDisabled=True,
            #)
            zcl_group_level_move_to_level(self, GrpId, ZIGATE_EP, EPout, "01",
                                          Hex_Format(2, value),
                                          transitionMoveLevel)

        # Update Device
        nValue = 1
        sValue = str(Level)
        self.Devices[unit].Update(nValue=int(nValue),
                                  sValue=str(sValue),
                                  Color=Color_)

    # Request to force ReadAttribute to each devices part of that group
    resetDevicesHearttBeat(self, GrpId)