milo526 / homebridge-tuya-web

Hoobs and Homebridge plugin for Tuya devices using Home Assistant Tuya Web Api
MIT License
219 stars 95 forks source link

Invalid Characteristics for Color Temp - Feit WiFi Color + TW Bulb #417

Closed ekobres closed 2 years ago

ekobres commented 2 years ago

Hello, I am receiving warnings from the platform about color temp ranges.

No matter how I set the color temp configuration for the bulb (either default, 0-1000, or 2700-6800), I seem to get either no ability to change color (won't use white mode) or the range is way off. When I leave the color temp ranges unconfigured (default), I get the following errors:

[3/9/2022, 11:59:36 AM] [TuyaWebPlatform] [Lamp] Characteristic.ColorTemperature - Characteristic 'ColorTemperature' will receive value higher than allowed mired (570) since provided Tuya kelvin value (1000) is lower then configured minimum Tuya kelvin value (7142.857142857143). Please update your configuration!
[3/9/2022, 11:59:36 AM] [@milo526/homebridge-tuya-web] This plugin generated a warning from the characteristic 'Color Temperature': characteristic was supplied illegal value: number 570 exceeded maximum of 500. See https://git.io/JtMGR for more info.
[3/9/2022, 11:59:51 AM] [TuyaWebPlatform] [Lamp] Characteristic.ColorTemperature - Characteristic 'ColorTemperature' will receive value higher than allowed mired (570) since provided Tuya kelvin value (1000) is lower then configured minimum Tuya kelvin value (7142.857142857143). Please update your configuration!
[3/9/2022, 11:59:51 AM] [@milo526/homebridge-tuya-web] This plugin generated a warning from the characteristic 'Color Temperature': characteristic was supplied illegal value: number 570 exceeded maximum of 500. See https://git.io/JtMGR for more info.

This is a Feit Color WiFi bulb (RGBWW) that ranges from 2700k-6500k color temp.

The color temp in 'white' mode ranges from 0 (2700k) to 1000 (6500k) in the Tuya API - so white mode with color 2700k looks like this in the tuya device debugger:

[
  {
    "code": "switch_led",
    "value": true
  },
  {
    "code": "work_mode",
    "value": "white"
  },
  {
    "code": "bright_value_v2",
    "value": 1000
  },
  {
    "code": "temp_value_v2",
    "value": 0
  },
  {
    "code": "colour_data_v2",
    "value": {
      "h": 30,
      "s": 750,
      "v": 1000
    }
  },
  {
    "code": "scene_data_v2",
    "value": {
      "scene_num": 1,
      "scene_units": [
        {
          "bright": 200,
          "h": 0,
          "s": 0,
          "temperature": 0,
          "unit_change_mode": "static",
          "unit_gradient_duration": 13,
          "unit_switch_duration": 14,
          "v": 0
        }
      ]
    }
  },
  {
    "code": "countdown_1",
    "value": 0
  },
  {
    "code": "control_data",
    "value": {}
  }
]

white mode with color 6500 looks lie this:

[
  {
    "code": "switch_led",
    "value": true
  },
  {
    "code": "work_mode",
    "value": "white"
  },
  {
    "code": "bright_value_v2",
    "value": 1000
  },
  {
    "code": "temp_value_v2",
    "value": 1000
  },
  {
    "code": "colour_data_v2",
    "value": {
      "h": 30,
      "s": 750,
      "v": 1000
    }
  },
  {
    "code": "scene_data_v2",
    "value": {
      "scene_num": 1,
      "scene_units": [
        {
          "bright": 200,
          "h": 0,
          "s": 0,
          "temperature": 0,
          "unit_change_mode": "static",
          "unit_gradient_duration": 13,
          "unit_switch_duration": 14,
          "v": 0
        }
      ]
    }
  },
  {
    "code": "countdown_1",
    "value": 0
  },
  {
    "code": "control_data",
    "value": {}
  }
]

Get Specifications and Properties for the device returns:

{
  "result": {
    "category": "dj",
    "functions": [
      {
        "code": "switch_led",
        "desc": "{}",
        "name": "开关",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "work_mode",
        "desc": "{\"range\":[\"white\",\"colour\",\"scene\",\"music\"]}",
        "name": "工作模式",
        "type": "Enum",
        "values": "{\"range\":[\"white\",\"colour\",\"scene\",\"music\"]}"
      },
      {
        "code": "bright_value_v2",
        "desc": "{\"min\":10,\"max\":1000,\"scale\":0,\"step\":1}",
        "name": "亮度",
        "type": "Integer",
        "values": "{\"min\":10,\"max\":1000,\"scale\":0,\"step\":1}"
      },
      {
        "code": "temp_value_v2",
        "desc": "{\"min\":0,\"max\":1000,\"scale\":0,\"step\":1}",
        "name": "色温",
        "type": "Integer",
        "values": "{\"min\":0,\"max\":1000,\"scale\":0,\"step\":1}"
      },
      {
        "code": "colour_data_v2",
        "desc": "{\"h\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":1000,\"step\":1},\"v\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":1000,\"step\":1}}",
        "name": "彩光模式值",
        "type": "Json",
        "values": "{\"h\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":1000,\"step\":1},\"v\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":1000,\"step\":1}}"
      },
      {
        "code": "scene_data_v2",
        "desc": "{\"scene_num\":{\"min\":1,\"scale\":0,\"max\":8,\"step\":1},\"scene_units\": {\"unit_change_mode\":{\"range\":[\"static\",\"jump\",\"gradient\"]},\"unit_switch_duration\":{\"min\":0,\"scale\":0,\"max\":100,\"step\":1},\"unit_gradient_duration\":{\"min\":0,\"scale\":0,\"max\":100,\"step\":1},\"bright\":{\"min\":0,\"scale\":0,\"max\":1000,\"step\":1},\"temperature\":{\"min\":0,\"scale\":0,\"max\":1000,\"step\":1},\"h\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":1000,\"step\":1},\"v\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":1000,\"step\":1}}}",
        "name": "场景模式值",
        "type": "Json",
        "values": "{\"scene_num\":{\"min\":1,\"scale\":0,\"max\":8,\"step\":1},\"scene_units\": {\"unit_change_mode\":{\"range\":[\"static\",\"jump\",\"gradient\"]},\"unit_switch_duration\":{\"min\":0,\"scale\":0,\"max\":100,\"step\":1},\"unit_gradient_duration\":{\"min\":0,\"scale\":0,\"max\":100,\"step\":1},\"bright\":{\"min\":0,\"scale\":0,\"max\":1000,\"step\":1},\"temperature\":{\"min\":0,\"scale\":0,\"max\":1000,\"step\":1},\"h\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":1000,\"step\":1},\"v\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":1000,\"step\":1}}}"
      },
      {
        "code": "countdown_1",
        "desc": "{\"unit\":\"s\",\"min\":0,\"max\":86400,\"scale\":0,\"step\":1}",
        "name": "倒计时",
        "type": "Integer",
        "values": "{\"unit\":\"s\",\"min\":0,\"max\":86400,\"scale\":0,\"step\":1}"
      },
      {
        "code": "control_data",
        "desc": "{\"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}}",
        "name": "调节模式值",
        "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}}"
      }
    ],
    "status": [
      {
        "code": "switch_led",
        "name": "开关",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "work_mode",
        "name": "模式",
        "type": "Enum",
        "values": "{\"range\":[\"white\",\"colour\",\"scene\",\"music\"]}"
      },
      {
        "code": "bright_value_v2",
        "name": "亮度",
        "type": "Integer",
        "values": "{\"min\":10,\"max\":1000,\"scale\":0,\"step\":1}"
      },
      {
        "code": "temp_value_v2",
        "name": "冷暖",
        "type": "Integer",
        "values": "{\"min\":0,\"max\":1000,\"scale\":0,\"step\":1}"
      },
      {
        "code": "colour_data_v2",
        "name": "彩光模式",
        "type": "Json",
        "values": "{\"h\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":1000,\"step\":1},\"v\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":1000,\"step\":1}}"
      },
      {
        "code": "scene_data_v2",
        "name": "情景模式",
        "type": "Json",
        "values": "{\"scene_num\":{\"min\":1,\"scale\":0,\"max\":8,\"step\":1},\"scene_units\": {\"unit_change_mode\":{\"range\":[\"static\",\"jump\",\"gradient\"]},\"unit_switch_duration\":{\"min\":0,\"scale\":0,\"max\":100,\"step\":1},\"unit_gradient_duration\":{\"min\":0,\"scale\":0,\"max\":100,\"step\":1},\"bright\":{\"min\":0,\"scale\":0,\"max\":1000,\"step\":1},\"temperature\":{\"min\":0,\"scale\":0,\"max\":1000,\"step\":1},\"h\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":1000,\"step\":1},\"v\":{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":1000,\"step\":1}}}"
      },
      {
        "code": "countdown_1",
        "name": "倒计时",
        "type": "Integer",
        "values": "{\"unit\":\"s\",\"min\":0,\"max\":86400,\"scale\":0,\"step\":1}"
      },
      {
        "code": "control_data",
        "name": "调节控制",
        "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}}"
      }
    ]
  },
  "success": true,
  "t": XXXX,
  "tid": "XXXX"
}
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ekobres commented 2 years ago

Bump

caver01 commented 2 years ago

I will second this issue. I have the same bulbs and I get the same messages filling up my logs. I have tried a bunch device configurations suggested here and there (brightness max min etc) but whatever I try I either get a different config error in the log, or half-broken functionality. It would really help if someone who knows better than me can look at ekobres notes here and suggest working configs for these bulbs.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ekobres commented 2 years ago

Bump again…

milo526 commented 2 years ago

Please post the result of the steps under "How to check whether the api this library uses can control your device".

Without this it is hard for me to help you with regards to this specific issue.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

madbanjoman commented 2 years ago

I am having the same problem. here is the output of the script:

Getting devices Got devices

{
   "header":{
      "code":"SUCCESS",
      "payloadVersion":1
   },
   "payload":{
      "devices":[
         {
            "data":{
               "brightness":"490",
               "color_mode":"white",
               "color_temp":18365,
               "online":true,
               "state":"false"
            },
            "dev_type":"light",
            "ha_type":"light",
            "icon":"https://images.tuyaus.com/smart/icon/ay1540090202974nPnzF/161544356620be39815e1.png",
            "id":"eb8f03375cd2af571fvalx",
            "name":"Color Lights 4"
         },
         {
            "data":{
               "brightness":"490",
               "color_mode":"white",
               "color_temp":18365,
               "online":true,
               "state":"false"
            },
            "dev_type":"light",
            "ha_type":"light",
            "icon":"https://images.tuyaus.com/smart/icon/ay1540090202974nPnzF/161544356620be39815e1.png",
            "id":"eb6302a19ea6361c9e7mzf",
            "name":"Color Lights"
         },
         {
            "data":{
               "brightness":"490",
               "color_mode":"white",
               "color_temp":18365,
               "online":true,
               "state":"false"
            },
            "dev_type":"light",
            "ha_type":"light",
            "icon":"https://images.tuyaus.com/smart/icon/ay1540090202974nPnzF/161544356620be39815e1.png",
            "id":"eb1df6929213bddf70jcjo",
            "name":"Color Lights 3"
         },
         {
            "data":{
               "brightness":"490",
               "color_mode":"white",
               "color_temp":18365,
               "online":true,
               "state":"false"
            },
            "dev_type":"light",
            "ha_type":"light",
            "icon":"https://images.tuyaus.com/smart/icon/ay1540090202974nPnzF/161544356620be39815e1.png",
            "id":"eb92b826165bfc6bf2kzl7",
            "name":"Color Lights 2"
         }
      ],
      "scenes":[

      ]
   }
}
madbanjoman commented 2 years ago

If I set the lights to dimmer, the errors go away from my log but I can no longer control brightness. I just get on or off in the smart life app or homekit.

madbanjoman commented 2 years ago

Actually, smart life can still completely control the lights, but homekit will only turn them on of off if they are set to dimmer.

milo526 commented 2 years ago

@madbanjoman

  1. Set one of your bulb to the most blueish tint (color temperature)
  2. Set another bulb to the most redish tint
  3. Run the script again and note the corresponding values for the color_temp belonging to these bulbs.
  4. Configure the plugin (ideally via Homebridge Config UI X) and set each light to the "light" device type, enable the brightness and color-temperature features, set the values as recorded from step 3 into the "minimum" and "maximum" kelvin values.
madbanjoman commented 2 years ago

I did the above and now homekit has no control over the lights. It still sees them as simple on off lights but nothing happens when I try to control them. no errors in the log on my hoobs homebridge server. Here is my plugin config:

tuya.txt

madbanjoman commented 2 years ago

Ugh, I just realized my error. I had one the brightness feature on dimmer and not light.

madbanjoman commented 2 years ago

I am not getting the color error anymore, but I am still getting a brightness error:

4/19/2022, 2:14:23 PMTuya Web BridgeERROR[Tuya Web Bridge FD03@Color Lights@Color Lights@Brightness] characteristic was supplied illegal value: number 1100 exceeded maximum of 100

4/19/2022, 2:14:23 PMTuya Web BridgeTuyaWebPlatformWARNING[Color Lights] Characteristic.Brightness - Characteristic 'Brightness' will receive value higher than allowed (1100) since provided Tuya value (1000) exceeds configured maximum Tuya value (100). Please update your configuration!

I removed the min and max brightness from my config. Should I be setting them to something?

milo526 commented 2 years ago

Just follow the same steps as with the color-temperature but now with the brightness.

Set one bulb to max brightness, one bulb to min brightness. Run the script, copy the respective values, and configure your bulbs accordingly.

ekobres commented 2 years ago

Well, that range (36294 - 1000) gets rid of the warning - but the Home app can't change the white temp at all now. It shows a reasonable range (top looks warm white, bottom looks cool white), but adjusting the white temp doesn't do anything (according to the Tuya app - which does reflect HSB changes from the home app immediately) or generate any log messages.

I used the Tuya app to set the warmest and coolest temp on a pair of identical Feit bulbs using the white color picker.

In summary - "Soft White (Min)" = 1000 "White" = 17941 "Daylight" = 23941 "Cool White (Max)" = 36294

Here's the debug output from the coolest light:

{   'data': 
                                     {   
                                            'brightness': '1000',
                                            'color_mode': 'white',
                                            'color_temp': 36294,
                                            'online': True
                                            'state': 'true'
                                      },
                                      'dev_type': 'light',
                                      'ha_type': 'light',
                                      'icon': 'https://images.tuyaus.com/smart/icon/...16e.png',
                                      'id': 'xxxzqa',
                                      'name': 'Coolest Color'
}

And the warmest:

{   'data': 
                                      {   
                                                  'brightness': '1000',
                                                  'color_mode': 'white',
                                                  'color_temp': 1000,
                                                  'online': True,
                                                  'state': 'true'
                                      },
                                      'dev_type': 'light',
                                      'ha_type': 'light',
                                      'icon': 'https://images.tuyaus.com/smart/icon/...16e.png',
                                      'id': 'xxxbqy',
                                      'name': 'Warmest Color'
}

And here's the config I'm using:

                {
                    "id": "xxxbqy",
                    "device_type": "light",
                    "min_brightness": "10",
                    "max_brightness": "1000",
                    "min_kelvin": "1000",
                    "max_kelvin": "36294",
                    "light_characteristics": [
                        "Brightness",
                        "Color",
                        "Color Temperature"
                    ]
                }

To add - with these settings I can also not set the brightness from the Home app with the bulb in white mode - I do get an error when I try:

[4/19/2022, 2:51:39 PM] [TuyaWebPlatform] [Coolest Color] Characteristic.Brightness - Tried to set brightness but failed to parse data. 
 {
  brightness: 10,
  color_mode: 'color',
  online: true,
  state: false,
  color_temp: 36294,
  color: { hue: 290, saturation: 100 }
}

In color mode I can set the brightness without a problem. Seems something internal hates that high color temp value... perhaps it's important that the color temp range is larger than a max INT16 value? (36294-1000 = 35294)

madbanjoman commented 2 years ago

Mine is doing the same thing with similar settings. I don't have color mode turned on. Other than that, mine is identical to the above.

ekobres commented 2 years ago

Color mode works fine. If I turn off color in the config, it still behaves badly with the “correct” white temp ranges from debug. With default values it sort of works - at least you can set the brightness and color temp - but the temps are way off of the mired values.

It seems that to actually fully support all RGBTW bulbs you would actually need 4 pieces of information:

  1. Min color temp
  2. Kelvin/Mired at min temp
  3. Max color temp
  4. Kelvin/Mired at max temp.

For example I know my bulbs can go from 2700K (Tuya min 1000) to 6800K (Tuya Max 36294.)

But I have other bulbs that can go from 2000K to 6800K - but with a min/max range of 0-255 - so this plugin has to make some sort of assumption about what those min and max values correspond to in Kelvin or mired.

I feel like Apple really screwed up the specs and guidelines for Homekit bulbs - technically they don’t even support a bulb that does color and temp if you read their Homekit accessory developer documentation. They expect the accessory to map HSB values the appropriate color temp - which is kind of a sick joke considering using RGB/HSB to create white is universally horrible. It’s the whole reason RGBTW hardware is built with 5 colors (Red, Green, Blue, Warm White, Cool White) instead of just Red, Green, Blue.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ekobres commented 2 years ago

Bump

milo526 commented 2 years ago

This plugin tries to be as plug-and-play as possible. I try to make sure that the plugin works without any configuration (except for username + password). As far as I'm aware Tuya bulb are supposed to expose their brightness through the color property when they are in color mode. I have seen a lot of different bulb which expose their brightness twice, once for color mode and once for white mode.

I would welcome a PR to make this configurable but I do not expect to fix this quickly myself.

ekobres commented 2 years ago

This plugin tries to be as plug-and-play as possible. I try to make sure that the plugin works without any configuration (except for username + password). As far as I'm aware Tuya bulb are supposed to expose their brightness through the color property when they are in color mode. I have seen a lot of different bulb which expose their brightness twice, once for color mode and once for white mode.

I would welcome a PR to make this configurable but I do not expect to fix this quickly myself.

This issue is about color temperature - not brightness. The problem is that there are 3 scales of color temperature for any bulb - and only 2 of them are represented in the configuration:

  1. min/max physical kelvin color range of light.
  2. min/max mired value of light (derived from and mapped to kelvin range)
  3. min/max color temp api values for light - not considered with this plugin. This range should be mapped to either the mired or kelvin range by the plugin. It would not break backward compatibility if these values default to the kelvin range since many/most accessories seem to use those. So it would still be plug-n-play for most bulbs.
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ekobres commented 2 years ago

Bump

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ekobres commented 2 years ago

Still active.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ekobres commented 2 years ago

Bump

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.