Open pekempy opened 5 years ago
When changing the HSV on the bulb, all 3 properties are updated simultaneously. Because of that, the setter on the HSV property is what controls execution of the change. So here, you'd want to create a new BulbHSV object with your preferred values, then use the setter:
var preferredHsv = new BulbHSV()
{
Hue = hue,
Saturation = sat,
Value = val
};
smartBulb.HSV = preferredHsv;
Now it's my turn to facepalm. I was looking at it for so long and didn't even think to create a BulbHSV obj. Thanks
Might have closed this prematurely.. I can see it's changing the HSV to 222/78/91 (as you see below) (roundh/rounds/roundv are rounded hue/sat/val in case that was the issue) But the HSV shown by the nodejs package (tplink-lightbulb) still shows the purple HSV? (it's a bulb at a friends house but he has confirmed it's still purple)
@TheBauwssss any ideas on the above?
I don't own one of these lights, so I can't test or try it for myself. I can see that in the Refresh()
method of the TPLinkSmartBulb
class the value returned for Brightness (in the BulbHSV
class called Value
) is not the raw JSON value returned by the Smart Light Bulb. The returned value is the JSON value modified like this:
When serializing the BulbHSV
object back to JSON the modification is undone by the opposite of the operation:
I think you need to modify your brightness value input in a similar way. If that does not work, off the top of my head I can think of two more possible things to try:
It is late and I am tired so my English might be severely compromised, or at least it feels like it is :D Anyhow, please accept my apologies for the grammatically questionable and weird English I might have used here and there. I can't think of a better way to put it into words without convoluting my sentences.
If this does not fix your issue, could you install Fiddler and send me a copy of the JSON payload your Smart Light Bulb returns to the API (through the Refresh()
method) and a copy of the JSON object the API send the Smart Light Bulb?
I did try using Fiddler but it wasn't finding anything from my server. This is the contents of the message sent to the bulb (this is equivalent to #ff5c40)
Following the code I can see the HSV is 240, 75, 100 in subResult after executing the code
I spent almost an hour researching and typing my previous reply, please read it carefully and follow the steps/possible solutions:
Did you try setting the brightness value mapped from 0 to 1 instead of 0 to 255?
Did you try possible solutions 1 and 2 from my previous reply?
If you're not seeing that JSON come along in Fiddler then something else is wrong. Please follow my possible solution 2 and send me a complete dump of the JSON message the APi is sending and the JSON response the bulb sends back.
@TheBauwssss , @pekempy FYI, the below linked library works, but it's in Java. Perhaps something can be learned from it, regarding this issue.
The issue is the "light_state" string being passed into the argument param here
It is totally unnecessary and infact stops the state change ever beinge executed. You need to pass just the JObject as the value with no argument.
is this project dead ? this bug has been opened for 5 years but hasn't been fixed. I'm also having problems changing the HSV of my KL125 bulb
Hey there! Unfortunately, I have stopped using these devices and therefore don't have a test unit to use when changing code on this project. I appreciate your (and others') use of this library over the years and am more than happy to accept pull requests to integrate upstream. I'd love to continue helping keep this library relevant by accepting others' contributions. I appreciate all the stars, forks, follows, and other means of support throughout the life of this library and want to continue to facilitate the use of this project as long as I can.
ah that's too bad, I really wanted to do this in C#. For now I'll be using https://github.com/python-kasa/python-kasa as the HSV setter works with my bulb. I'll try to see how they did it in the python project to see if it's easily fixable in the C# project, but I don't really know python :(
Prior to running any command this is what I get running tplight details [ip]
"light_state": {
"on_off": 1,
"mode": "normal",
"hue": 261,
"saturation": 43,
"color_temp": 0,
"brightness": 45
We can see the HSV is 261, 43, 45 here.
After running the following code:
smartBulb.HSV.Hue = 222;
smartBulb.HSV.Saturation = 78;
smartBulb.HSV.Value = 91;
(Which is #3369e8 hex code converted into HSV), if I check the details of the bulb again it's still the same colour
"light_state": {
"on_off": 1,
"mode": "normal",
"hue": 261,
"saturation": 43,
"color_temp": 0,
"brightness": 45
Am I using the command wrong to change values? here's the method
var smartBulb = new TPLinkSmartDevices.Devices.TPLinkSmartBulb(bulbIP);
smartBulb.HSV.Hue = hue;
smartBulb.HSV.Saturation = sat;
smartBulb.HSV.Value = val;
(hue, sat, val are rounded integers passed in after converting hex to hsv)