Skip to content

Commit

Permalink
seems working, let test it now
Browse files Browse the repository at this point in the history
  • Loading branch information
pipiche38 committed Oct 16, 2023
1 parent 6d3a256 commit 8178d8e
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 19 deletions.
53 changes: 53 additions & 0 deletions Conf/Local-Devices/TS0505A.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"_comment": "Tuya RR400ZB",
"_blakadder": "https://zigbee.blakadder.com/Lidl_HG06104A.html",
"_version": "1.0",
"Ep": {
"01": {
"0000": "",
"0003": "",
"0004": "",
"0005": "",
"0006": "",
"0008": "",
"0300": {
"Attributes": {
"f000": {"Enabled": true, "Name": "Tuya0300_f000", "DataType": "20", "ActionList": [ "check_store_value"] },
"f003": {"Enabled": true, "Name": "Tuya0300_f003", "DataType": "48", "ActionList": [ "check_store_value"] }
}
},
"000a": "",
"0019": "",
"1000": "",
"Type": "ColorControlRGBWW"
},
"f2": {
"0021": "",
"Type": ""
}
},
"Type": "",
"bindEp": "01",
"ClusterToBind": [ "0006", "0008", "0300" ],
"ConfigureReporting": {
"0006": { "Attributes": { "0000": { "DataType": "10", "MinInterval": "0001", "MaxInterval": "012C", "TimeOut": "0258", "Change": "01" } } },
"0008": { "Attributes": { "0000": { "DataType": "20", "MinInterval": "0005", "MaxInterval": "012C", "TimeOut": "0000", "Change": "05" } } },
"0300": {
"Attributes": {
"0003": { "DataType": "21", "MinInterval": "0001", "MaxInterval": "012C", "TimeOut": "0000", "Change": "0001"},
"0004": { "DataType": "21", "MinInterval": "0001", "MaxInterval": "012C", "TimeOut": "0000", "Change": "0001"},
"0007": { "DataType": "21", "MinInterval": "0001", "MaxInterval": "012C", "TimeOut": "0000", "Change": "0001"},
"0008": { "DataType": "30", "MinInterval": "0001", "MaxInterval": "012C", "TimeOut": "0000", "Change": "01" }
}
}

},
"ReadAttributes": {
"0000": [ "0000", "0001", "0002", "0003", "0004", "0005", "0006", "0007" ],
"0006": [ "0000", "4001", "4002" ],
"0008": [ "0000" ],
"0300": [ "f002", "f00d", "0000", "0001", "0003", "0004", "0007", "0008", "000f", "400a" ]
},
"TUYA_REGISTRATION": 19,
"TUYAColorControlRgbMode": true
}
33 changes: 18 additions & 15 deletions Modules/actuators.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
zcl_window_covering_on,
zcl_window_covering_percentage,
zcl_window_covering_stop)
from Modules.tuya import tuya_color_control_command_fe
from Modules.tuya import tuya_color_control_rgbMode, tuya_Move_To_Hue_Saturation_Brightness


def lightning_percentage_to_analog( percentage_value ):
Expand Down Expand Up @@ -248,7 +248,7 @@ def actuator_setcolor(self, nwkid, EPout, value, Color):
if Hue_List["m"] == 2:
handle_color_mode_2(self, nwkid, EPout, Hue_List)

elif Hue_List["m"] == 3 and force_color_command == "MovetoHueandSaturation":
elif Hue_List["m"] == 3 and force_color_command == "TuyaMovetoHueandSaturation":
handle_color_mode_9998( self, nwkid, EPout, Hue_List, value)

# ColorModeRGB = 3 // Color. Valid fields: r, g, b.
Expand All @@ -271,8 +271,6 @@ def handle_color_mode_2(self, nwkid, EPout, Hue_List):
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)
if get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "TUYA_Color_Control_Command_fe", return_default=None):
tuya_color_control_command_fe( self, nwkid, "00")
zcl_move_to_colour_temperature( self, nwkid, EPout, Hex_Format(4, TempMired), transitionTemp)


Expand All @@ -284,6 +282,8 @@ def handle_color_mode_3(self, nwkid, EPout, Hue_List):
#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)
if get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "TUYAColorControlRgbMode", return_default=None):
tuya_color_control_rgbMode( self, nwkid, "01")
zcl_move_to_colour(self, nwkid, EPout, Hex_Format(4, x), Hex_Format(4, y), transitionRGB)

def handle_color_mode_4(self, nwkid, EPout, Hue_List ):
Expand All @@ -299,8 +299,8 @@ def handle_color_mode_4(self, nwkid, EPout, Hue_List ):
TempMired = 1000000 // TempKelvin
self.log.logging( "Command", "Log", "handle_color_mode_4 Set Temp Kelvin: %s-%s" % (
TempMired, Hex_Format(4, TempMired)), nwkid )
if get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "TUYA_Color_Control_Command_fe", return_default=None):
tuya_color_control_command_fe( self, nwkid, "00")
if get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "TUYAColorControlRgbMode", return_default=None):
tuya_color_control_rgbMode( self, nwkid, "01")
zcl_move_to_colour_temperature( self, nwkid, EPout, Hex_Format(4, TempMired), transitionTemp)

# Process Colour
Expand All @@ -312,8 +312,8 @@ def handle_color_mode_4(self, nwkid, EPout, Hue_List ):

self.log.logging("Command", "Log", "handle_color_mode_4 Set Hue X: %s Saturation: %s" % (
hue, saturation), nwkid)
if get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "TUYA_Color_Control_Command_fe", return_default=None):
tuya_color_control_command_fe( self, nwkid, "01")
if get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "TUYAColorControlRgbMode", return_default=None):
tuya_color_control_rgbMode( self, nwkid, "01")
zcl_move_hue_and_saturation(self, nwkid, EPout, Hex_Format(2, hue), Hex_Format(2, saturation), transitionRGB)

def handle_color_mode_9998( self, nwkid, EPout, Hue_List, value):
Expand All @@ -325,13 +325,16 @@ def handle_color_mode_9998( self, nwkid, EPout, Hue_List, value):
hue = int(hue * 254 // 360)

self.log.logging("Command", "Debug", "handle_color_mode_9998 Set Hue X: %s Saturation: %s" % (hue, saturation), nwkid)
if get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "TUYA_Color_Control_Command_fe", return_default=None):
tuya_color_control_command_fe( self, nwkid, "01")
zcl_move_hue_and_saturation(self, nwkid, EPout, Hex_Format(2, hue), Hex_Format(2, saturation), transitionRGB)

value = lightning_percentage_to_analog( value )
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)
if get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "TUYAColorControlRgbMode", return_default=None):
tuya_color_control_rgbMode( self, nwkid, "01")

if get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "FORCE_COLOR_COMMAND", return_default=None) == "TuyaMovetoHueandSaturation":
tuya_Move_To_Hue_Saturation_Brightness( self, nwkid, hue, saturation, value)
else:
zcl_move_hue_and_saturation(self, nwkid, EPout, Hex_Format(2, hue), Hex_Format(2, saturation), transitionRGB)
value = lightning_percentage_to_analog( value )
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)

def actuator_identify(self, nwkid, ep, value=None):

Expand Down
25 changes: 21 additions & 4 deletions Modules/tuya.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import time
from datetime import datetime, timedelta
import struct

from Modules.basicOutputs import raw_APS_request, write_attribute
from Modules.bindings import bindDevice
Expand Down Expand Up @@ -1516,7 +1517,7 @@ def ts110e_switch_type( self, NwkId, EPout, mode):
mode = "%02x" %mode
write_attribute(self, NwkId, ZIGATE_EP, EPout, "0008", "0000", "00", "fc02", "20", mode, ackIsDisabled=False)

def tuya_lighting_color_control( self, NwkId, ColorCapabilities=29):
def tuya_lighting_color_control( self, NwkId, ColorCapabilities=25):
# The ColorCapabilities attribute specifies the color capabilities of the device supporting the color control clus-
# ter, as illustrated in Table 5.8. If a bit is set to 1, the corresponding attributes and commands SHALL become
# mandatory. If a bit is set to 0, the corresponding attributes and commands need not be implemented.
Expand All @@ -1525,8 +1526,24 @@ def tuya_lighting_color_control( self, NwkId, ColorCapabilities=29):
self.log.logging("Tuya", "Debug", "tuya_lighting_color_control - Color Capabilities %s completed" % ColorCapabilities, NwkId)


def tuya_color_control_command_fe( self, NwkId, svalue):
self.log.logging("Tuya", "Debug", "tuya_ltuya_color_control_command_fe", NwkId)
def tuya_color_control_rgbMode( self, NwkId, mode):
# Command 0xfe
# To switch between white mode and color mode
self.log.logging("Tuya", "Debug", "tuya_color_control_rgbMode", NwkId)
sqn = get_and_inc_ZCL_SQN(self, NwkId)
payload = "11" + sqn + "f0" + svalue
payload = "11" + sqn + "f0" + mode
raw_APS_request(self, NwkId, "01", "0300", "0104", payload, zigpyzqn=sqn, zigate_ep=ZIGATE_EP, ackIsDisabled=False)



def tuya_Move_To_Hue_Saturation_Brightness( self, NwkId, hue, saturation, brightness):
# Command 0xe1
self.log.logging("Tuya", "Debug", "tuya_Move_To_Hue_Saturation_Brightness", NwkId)

saturation = "%04x" % struct.unpack("H", struct.pack(">H", saturation))[0]
hue = "%04x" % struct.unpack("H", struct.pack(">H", hue, ))[0]
brightness = "%04x" % struct.unpack("H", struct.pack(">H", brightness))[0]
sqn = get_and_inc_ZCL_SQN(self, NwkId)
payload = "11" + sqn + "e1" + hue + saturation + brightness

raw_APS_request(self, NwkId, "01", "0300", "0104", payload, zigpyzqn=sqn, zigate_ep=ZIGATE_EP, ackIsDisabled=False)

0 comments on commit 8178d8e

Please sign in to comment.