konsumer / tplink-lightbulb

Control TP-Link smart lightbulbs from nodejs
MIT License
191 stars 32 forks source link

LB130 hex command doesn't change color #6

Closed danodemano closed 7 years ago

danodemano commented 7 years ago

Color change doesn't work, only changes the brightness:

root@ha:~# tplight hex 192.168.9.199 "#48258b"
{
  "on_off": 1,
  "mode": "normal",
  "hue": 260,
  "saturation": 57,
  "color_temp": 2500,
  "brightness": 34,
  "err_code": 0
}
root@ha:~# tplight hex 192.168.9.199 "#ff0000"
{
  "on_off": 1,
  "mode": "normal",
  "hue": 0,
  "saturation": 100,
  "color_temp": 2500,
  "brightness": 50,
  "err_code": 0
}
root@ha:~# tplight hex 192.168.9.199 "#000000"
{
  "on_off": 1,
  "mode": "normal",
  "hue": 0,
  "saturation": 0,
  "color_temp": 2500,
  "brightness": 0,
  "err_code": 0
}
root@ha:~# tplight hex 192.168.9.199 "#ffffff"
{
  "on_off": 1,
  "mode": "normal",
  "hue": 0,
  "saturation": 0,
  "color_temp": 2500,
  "brightness": 100,
  "err_code": 0
}
root@ha:~#
konsumer commented 7 years ago

What kind of bulb are you using? Are you sure it's a LB130? I am using a LB120, which doesn't have support for color (like the LB130), just "temperature". When this library sends a "color" (hex or hsb) it really is sending Hue, Saturation, and Brightness. My bulb doesn't support Hue and Saturation, so it only understands Brightness. I am guessing you have the same bulb because your responses look like mine, where it tracks Hue and Saturation, but they don't actually do anything. Bulbs that do support color will use the combination of those 3 values to make a color, but they also don't support "temperature" like my bulb.

danodemano commented 7 years ago

Are you sure it's a LB130?

Yup, changes colors fine from the app and by using the --hue and --saturation commands. Also works via raw (this turns it red):

tplight raw 192.168.9.199 '{"smartlife.iot.smartbulb.lightingservice":{"transition_light_state":{"ignore_default":1,"on_off":1,"color_temp":0,"hue":0,"saturation":100}}}'

konsumer commented 7 years ago

Interesting. It may be something funny with temperature, as the other people with LB130 got it working ok. Maybe I should zero that out for "color" commands. It's honestly all very hit-and-miss since I don't have the LB130, I just kinda have to guess 😄

konsumer commented 7 years ago

@DaveGut mentioned that my suspicions were correct on the other issue. 😄 I will add that.

danodemano commented 7 years ago

Sweet, thanks!

konsumer commented 7 years ago

Ok, published as v1.1.6. Give it a try and let me know!

Update with npm i -g tplink-lightbulb

Here is the most useful stuff to test:

# these should work on everyone's
tplight  scan -t 1 # does it find your bulbs?
tplight on <IP> # does it turn on the light?

# these work on LB120, but not yours
tplight temp <IP> 10000 # is it blue?
tplight temp <IP> 1 # is it orange?

# after those try these (only work on yours)
tplight hex <IP> '#ff0000' # is it red?
tplight hex <IP> '#00ff00' # is it green?
tplight hex <IP> '#0000ff' # is it blue?
tplight hsb <IP> 72 58 35 # is it purple?

<IP> should be an IP from tplight scan

konsumer commented 7 years ago

Sending unsupported commands (color for LB120, temp for LB130) should just silently fail but not hurt anything, as that's what the bulb does (and there is no way to detect a fail, other than model-numbers), but I'd prefer if the lib still worked for unsupported commands and didn't screw up supported ones. I think it supports that now, but as I said, I need testing to be sure.

danodemano commented 7 years ago

All of them work (even the middle ones that you said wouldn't) except for the HSB command.

root@ha:~# tplight hsb 192.168.9.199 72 58 35
{
  "on_off": 1,
  "mode": "normal",
  "hue": 72,
  "saturation": 58,
  "color_temp": 0,
  "brightness": 35,
  "err_code": 0
}

It's like a dull yellow-green

konsumer commented 7 years ago

Yeh, I got the color wrong somehow. that is actually what I would expect! I double-checked with a color-converter:

screen shot 2017-06-22 at 4 37 19 pm

Thanks for your testing, and @DaveGut for awesome bulb-hacking. Should I close this one?

danodemano commented 7 years ago

Sweet. And yep, go ahead and close it. Really appreciate you working so hard on this!

konsumer commented 7 years ago

Also, good to know your bulb supports temp.