Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json format for lightstrips #14

Open
dedelajoie opened this issue Nov 20, 2022 · 13 comments
Open

Json format for lightstrips #14

dedelajoie opened this issue Nov 20, 2022 · 13 comments

Comments

@dedelajoie
Copy link

Hello,
I am sorry to bother you with such a small detail but I cannot get the HSV part of my lightstrip working. Power and brightness are working when I choose "custom json" in my MIIOSendCommand but I cannot have the Color HUE part.
I followed the instructions given there though : https://github.com/stason325/node-red-contrib-miio-localdevices/blob/master/DEVICES.md
but it is just not working whatever are the values I put after "hue" and "saturation".

Here si the Jsin I send as my payload :
{
"Power": "on",
"Brightness": 100,
"Color_Temp": 4000,
"Color_HUE": {
"hue": 100,
"saturation": 200
}
}

thank you

@stason325
Copy link
Owner

Hello,

I am sorry to bother you with such a small detail but I cannot get the HSV part of my lightstrip working. Power and brightness are working when I choose "custom json" in my MIIOSendCommand but I cannot have the Color HUE part.

I followed the instructions given there though : https://github.com/stason325/node-red-contrib-miio-localdevices/blob/master/DEVICES.md

but it is just not working whatever are the values I put after "hue" and "saturation".

Here si the Jsin I send as my payload :

{

"Power": "on",

"Brightness": 100,

"Color_Temp": 4000,

"Color_HUE": {

    "hue": 100,

    "saturation": 200

}

}

thank you

Hi there.
What device are you talking about?
Regards

@stason325
Copy link
Owner

I think you've got a mistake here ... you need to set hsv instead of hue

The correct json should be like

{ Power: "on",
Brightness: 100,
ColorTemperature: 4000,
ColorHSV:
{"hue": 100,
"saturation": 200
}
}

@dedelajoie
Copy link
Author

thank you
But it still doesnt work
I guess there is a problem in my set up

@stason325
Copy link
Owner

thank you

But it still doesnt work

I guess there is a problem in my set up

Check and come back with results👍🏻
By the way, please check whether separate HSV command (not custom json) works

@stason325
Copy link
Owner

thank you

But it still doesnt work

I guess there is a problem in my set up

Hello there.
Have you had a chance to fix your set up? Could we consider this issue as closed or is it something left undone on my nodes' side?

@Cjkeenan
Copy link

Cjkeenan commented Dec 28, 2022

I am having this same issue now as well with both custom and separate HSV commands.

This is my msg.payload:
{"Power":true,"Brightness":1,"ColorHSV":{"hue":50,"saturation":50}}

I have tested on/off, color temp, and brightness and they all work (only tested custom with those, but I can try individually if you think that will help). HSV is the only one not working (neither custom nor individual).

By the way, please check whether separate HSV command (not custom json) works

image

I was looking through the code, and did not see anything related to my device directly (strip2), but the color3.js file appears to be the same capability.

Is this a bug in the setter for HSV?
yeelink.light.color3.js:

...
    setPower(v) {
        return this.miioCall('set_power', withLightEffect(v ? 'on' : 'off'));
    }

    setBrightness(v) {
        return this.miioCall('set_bright', withLightEffect(v));
    }

    setColorTemperature(v) {
        return this.miioCall('set_ct_abx', withLightEffect(v));
    }

    setColorHSV(v) {
        this._miioCall('set_hsv', withLightEffect([v.hue, v.saturation]));
    }
...

Notice the difference between setColorHSV and the other setters (no return statement and _miioCall vs just miioCall). Again, I am not even sure if this is relevant to the issue at hand, but it is something I noticed when perusing around. Where are the functions for getting and setting the values for yeelink.light.strip2? Are they baked into some imported library or package or does it just use the yeelink.light.color3.js file?

P.S. There is also a typo in the DEVICES.md that might be a source of confusion going forward even if this issue gets resolved: yeelink.light.strip1, yeelink.light.strip2, and yeelink.light.color3 have a typo in the Values for Commands column, where saturation is misspelled as satuartion.
#17

@dedelajoie
Copy link
Author

js

unfortunately not

@stason325
Copy link
Owner

@Cjkeenan thanks for your research

First of all, it doesn't matter how to test HSV (separate command or complex JSON).The result would be the same.

I've checked syntax for set "set_hsv" command in spec-paper at www.yeelight.com. Everything seems to be done correctly. Please see page 12 of this file: Yeelight_Inter-Operation_Spec.pdf

Thus, I think that your suggestion to change "_miioCall" to "miioCall" in setColorHSV(v) setter could be the cure for the whole issue.

What I propose: make that change in your local yeelink.light.color3.js file, reboot NR and test HSV command once again.

If everything works correctly, I'll update yeelink.light.color3.js file in the next 0.5.13cversion + merge your PR about typos in devices.md.

Regards

@Cjkeenan
Copy link

Cjkeenan commented Dec 28, 2022

No luck unfortunately, this is the location of the file I would have to modify right?
./node-red/node_modules/node-red-contrib-miio-localdevices/defFiles/yeelink.light.color3.js

Also does any recompilation need to happen or is a reboot of NR sufficient?

Does the yeelink.light.strip2 device reference the yeelink.light.color3.js file or does it use something else?

It looks like the same "issue" is here so I am thinking it really is not an issue:
https://github.com/maxinminax/node-mihome/blob/master/lib/devices/yeelink.light.strip2.js

Also found this:
maxinminax/node-mihome#19

Do you know if that underlying node module is still being maintained?

I think I may just switch to using this since everything is working out of the box even if these nodes have not been updated in a while and only apply to yeelight lights versus the variety of devices your nodes support.
https://github.com/mattmattmatt/node-red-contrib-yeelight-compat-hue

@stason325
Copy link
Owner

No luck unfortunately, this is the location of the file I would have to modify right? ./node-red/node_modules/node-red-contrib-miio-localdevices/defFiles/yeelink.light.color3.js

Yes, this is it

Also does any recompilation need to happen or is a reboot of NR sufficient?

No, NR reboot after making changes is enough

Does the yeelink.light.strip2 device reference the yeelink.light.color3.js file or does it use something else?

These are separate defFiles: yeelink.light.color3.js is for Mi LED Smart Bulb and yeelink.light.strip2 is for Strips (strip 2, 6 and 8), that supports HSV. Please refer to devices.md to see which defFile is for which device.

It looks like the same "issue" is here so I am thinking it really is not an issue: https://github.com/maxinminax/node-mihome/blob/master/lib/devices/yeelink.light.strip2.js

Also found this: maxinminax/node-mihome#19

Do you know if that underlying node module is still being maintained?

I saw that issue from @Pittini... Well, node-mihome hasn't been updated for quite a while, but main functionality (establishing connection and polling the device) works good. All the rest is about making correct defFile for certain device according with Xiaomi specs and testing.

I think I may just switch to using this since everything is working out of the box even if these nodes have not been updated in a while and only apply to yeelight lights versus the variety of devices your nodes support. https://github.com/mattmattmatt/node-red-contrib-yeelight-compat-hue

Yes, these nodes are good alternative for Yeelights, but it will be appreciated if we could make some more tests with my nodes to make setting colour finally work. I think the solution is not far.

So, let's try following options:

1) according to Yeelight specs Yeelight_Inter-Operation_Spec.pdf let's push full json to set_hsv function.

Here you need to:
a) change defFile like that:

setColorHSV(v) {
    this.miioCall('set_hsv', withLightEffect([v.hue, v.saturation, v.effect, v.duration]));
}

b) reboot NR
c) push to ColorHSV node full JSON {"hue": 50,"saturation": 50, "effect": "smooth", "duration": 500}

...if it doesn't work => option 2

2) getting rid of "withLightEffect":

a) change defFile like that:

setColorHSV(v) {
    this.miioCall('set_hsv', [v.hue, v.saturation]);
}

b) reboot NR
c) push to ColorHSV node short JSON {"hue": 50,"saturation": 50}

...if it doesn't work => option 3

3) getting rid of "withLightEffect" + full JSON:

a) change defFile like that:

setColorHSV(v) {
    this.miioCall('set_hsv', [v.hue, v.saturation, v.effect, v.duration]);
}

b) reboot NR
c) push to ColorHSV node short JSON {"hue": 50,"saturation": 50, "effect": "smooth", "duration": 500}

...if it doesn't work => option 4

4) migrating from set_hsv to set_rgb:

a) change defFile like that:

setColorHSV(v) {
    this.miioCall('set_rgb', [v.rgb, v.effect, v.duration]);
}

b) reboot NR
c) push to ColorHSV node short JSON {"rgb": 150, "effect": "smooth", "duration": 500}

I hope, at least one of these options could work. :)
Come back with the results of your tests, please.

Regards

Repository owner deleted a comment from Cjkeenan Dec 30, 2022
@stason325
Copy link
Owner

@Cjkeenan , hello again.
... I accidentally deleted your comment🥴 could you please write it again)

The main thing here: you should make and test changes in defFile NOT at the source directory, but at the target directory (the directory of node-mihome lib).

Please, test changes again there and come back with the results 👍🏻

@stason325
Copy link
Owner

@Cjkeenan hello.
Did you have a chance to test the changes to defFile?

@pepijnmm
Copy link

pepijnmm commented May 21, 2023

@stason325 I had the same problem. I first thought I calculated HSV wrong, but it seemed to me that "ColorHSV" just didn't get sent to the setColorHSV function(after some console logs). it's because of the eval function.(took me a while to find how setPower etc. were executed XD).
when I did a console log in devices.js, I got back ColorHSV([object Object]). this was what eval was trying to execute. it could not get the data because it was stringified and summarized as "object Object".

so problem one I solved by making it:
await device['set'+key](CustomJsonCMD[key]);

this way the data won't get changed.

problem two. as you and Cjkeenan both already noticed this._miioCall isn't correct.
so making it
return this.miioCall
or just
this.miioCall

solves the color problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants