make-all / tuya-local

Local support for Tuya devices in Home Assistant
MIT License
1.22k stars 487 forks source link

Request support for lights that deliver all their parameters on a single line of json #2107

Closed fmonday closed 6 days ago

fmonday commented 2 months ago

Across various sites there has been confusion about Tuya devices that deliver all their configuration parameters on a single DP as a line of JSON-encoded data. My device is the Enbrighten Café premium string lights which, oddly, are using DP 26 (? or 106) for this. tuyalocal recognizes these and turns them on & off but all the other controls are non-functional; the core integration seems to recognize the limitation and only displays it as on/off.

Log Message

No errors in HA's log.

2024-07-12 16:53:06.713 DEBUG (MainThread) [custom_components.tuya_local.device] string_lights_48 new pending updates: {"24": {"value": "00de03e803e8", "updated_at": 1720817586.7129295, "sent": false}, "21": {"value": "colour", "updated_at": 1720817586.7129295, "sent": false}, "20": {"value": true, "updated_at": 1720817586.7129295, "sent": false}}
2024-07-12 16:53:07.714 DEBUG (MainThread) [custom_components.tuya_local.device] string_lights_48 sending dps update: {"20": true, "21": "colour", "24": "00de03e803e8"}
2024-07-12 16:53:07.950 DEBUG (MainThread) [custom_components.tuya_local.device] string_lights_48 received {"20": true, "full_poll": true}
2024-07-12 16:53:07.950 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] color_mode values: ['white', 'hs', 'Scene']
2024-07-12 16:53:07.950 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] color_mode values: ['white', 'hs', 'Scene']
2024-07-12 16:53:07.950 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] color_mode values: ['white', 'hs', 'Scene']
2024-07-12 16:53:07.950 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] color_mode values: ['white', 'hs', 'Scene']
2024-07-12 16:53:07.950 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] color_mode values: ['white', 'hs', 'Scene']
2024-07-12 16:53:07.950 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] LED strip: Mapped dps 21 value from colour to hs
2024-07-12 16:53:07.950 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] LED strip: Mapped dps 21 value from colour to hs
2024-07-12 16:53:07.950 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] LED strip: Mapped dps 21 value from colour to hs
2024-07-12 16:53:07.950 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] LED strip: Mapped dps 21 value from colour to hs
2024-07-12 16:53:07.950 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] LED strip: Mapped dps 21 value from colour to hs
2024-07-12 16:53:07.950 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] LED strip: Mapped dps 21 value from colour to hs
2024-07-12 16:53:07.950 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] format of >HHH found
2024-07-12 16:53:07.950 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] format of >HHH found
2024-07-12 16:53:07.950 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] color_mode values: ['white', 'hs', 'Scene']
2024-07-12 16:53:07.951 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] Considering mapping for range of value
2024-07-12 16:53:07.951 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] Considering mapping for range of value
2024-07-12 16:53:07.951 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] Considering mapping for step of value
2024-07-12 16:53:07.951 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] Step for value is 60 with scale 60
2024-07-12 16:53:07.951 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] LED strip: Mapped dps 26 value from 0 to 0.0
2024-07-12 16:53:07.951 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] LED strip: Mapped dps 26 value from 0 to 0.0
2024-07-12 16:53:08.062 DEBUG (MainThread) [custom_components.tuya_local.device] string_lights_48 received {"20": true, "26": 0, "104": "111111111111111111111111", "106": "0003e801f40#00ff4000", "full_poll": false}

Information about DPS mappings

my cloud dev plan expired, so this is from "smart home basic service":

"result": {
    "category": "dj",
    "functions": [
      {
        "code": "switch_led",
        "dp_id": 20,
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "countdown_1",
        "dp_id": 26,
        "type": "Integer",
        "values": "{\"unit\":\"s\",\"min\":0,\"max\":86400,\"scale\":0,\"step\":1}"
      },
      {
        "code": "control_data",
        "dp_id": 28,
        "type": "Json",
        "values": "{\"change_mode\":{\"range\":[\"direct\",\"gradient\"]}, \"bright\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":1000,\"step\":1}, \"temperature\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":1000,\"step\":1}, \"h\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"

However, when setting up localttuya it saw something different: DP 106 looks like the pattern for DP 28 per the platform.

Screenshot 2024-07-12 at 6 31 56 PM

Product ID

"model": "WB-57415",
"name": "enbrighten Café Lights- 48",
"online": true,
"owner_id": "xxxx",
"product_id": "irp66izb2pbedb4o",
"product_name": "enbrighten Café Lights ",
"status": [
  {
    "code": "switch_led",
    "value": true
  },
  {
    "code": "countdown_1",
    "value": 0
  },
  {
    "code": "control_data",
    "value": ""
  }

Thanks in advance

make-all commented 2 months ago

The log you have posted does not contain any "full_poll": true entries, so the full info that is received from the light is not visible. The information about DPS mappings also seems to be from one of the API calls intended for "standard" cloud API use, and not the full details that are available from the QueryThingsDataModel API call (albiet in a less human readable format).

fmonday commented 2 months ago

I do see "full_poll": true in the third line of the HA log that I posted, but here's the result of the QueryThingsDataModel API call:

{
  "result": {
    "model": "{\"modelId\":\"000002rvu5\",\"services\":[{\"actions\":[],\"code\":\"\",\"description\":\"\",\"events\":[],\"name\":\"默认服务\",\"properties\":[
{\"abilityId\":20,\"accessMode\":\"rw\",\"code\":\"switch_led\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-dp_power\",\"attribute\":\"515\"},\"name\":\"开关\",\"typeSpec\":{\"type\":\"bool\"}},
{\"abilityId\":26,\"accessMode\":\"rw\",\"code\":\"countdown\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-a_nav_timer\",\"attribute\":\"514\"},\"name\":\"倒计时\",\"typeSpec\":{\"type\":\"value\",\"max\":86400,\"min\":0,\"scale\":0,\"step\":1,\"unit\":\"s\"}},
{\"abilityId\":28,\"accessMode\":\"wr\",\"code\":\"control_data\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-dp_box2\",\"attribute\":\"608\"},\"name\":\"调节\",\"typeSpec\":{\"type\":\"string\",\"maxlen\":255}},
{\"abilityId\":104,\"accessMode\":\"rw\",\"code\":\"lightcustomization\",\"description\":\"bit 1:显示灯泡;bit 0:关闭灯泡;\\n如 0b101......表示第1个灯泡开,第2个灯泡关,第3个灯泡关....\",\"name\":\"灯串显示\",\"typeSpec\":{\"type\":\"string\",\"maxlen\":255}},
{\"abilityId\":106,\"accessMode\":\"rw\",\"code\":\"mode\",\"description\":\"模式字符串:012345555……5555\\n0:模式(单字符0-b):Fade、Blink、Twinkle、Rainbow、Red White Blue、Red Green White、Mardi Gras、Valentines Day、Autumn、St Patrick Day、Spring、UserColor1、UserColor2、UserColor3、UserColor4、UserColor5\\n1:效果(单字符0-7):Solid、Twinkle、Blink、Pulse、Wave Chase、Chase、Wave、Fase chase\\n2:速度(单字符0-f)\\n3:亮度(单字符0-f)\\n4:颜色个数(单字符0-2)\\n5:颜色值(HSV白光)\\n\",\"name\":\"模式\",\"typeSpec\":{\"type\":\"string\",\"maxlen\":255}},
{\"abilityId\":107,\"accessMode\":\"rw\",\"code\":\"lamp_number\",\"description\":\"默认值24\",\"name\":\"灯串头数\",\"typeSpec\":{\"type\":\"enum\",\"range\":[\"12\",\"18\",\"24\"]}}]}]}"
  },
  "success": true,
  "t": 1720883560691,
  "tid": "58cc7f61412a11ef8d05deff400716f1"
}

I think I can also eventually work out how to get a debug scan from tinytuya if you need it...

make-all commented 1 week ago

The format of dp 106 is not parsable, as it is not a true hex value, it contains garbage in the middle. It also looks like it may be variable length which would make it difficult to work with even if it was pure hex.

So the best I can do for now is just on/off switches.