magicmonkey / lifxjs

JS library for LIFX bulbs
MIT License
274 stars 62 forks source link

Can't target single bulb to change hue #35

Open WeeJeWel opened 9 years ago

WeeJeWel commented 9 years ago

Using lightsColour to set a bulb on or off works, when the last parameter is a bulb object. However, when changing the hue, it does not change. Omitting the bulb parameter (thus targeting all), the color changes.

MrRacoon commented 9 years ago

Yeah, I too have seemed to have a hard time targeting on bulb for specific changes. What am I missing? bulbs gives me an object:

obj = {"aaabbbcccddd":{
    "addr":[111,222,333,4,555,6],
    "name":"Desk",
    "state":{
        "hue":29,
        "saturation":65535,
        "brightness":65535,
        "kelvin":2500,
        "dim":0,
        "power":65535
    }
}}

I imagined that passing the key "aaabbbcccddd" would be the correct parameter for changing the values of a single bulb but I get no feedback. I've tried the name and even the entire obj.aaabbbcccddd object. to no avail.


EDIT: Awe. So then I read the code, and learned that you can dump in all of the above. herm... still having troubles targeting a single bulb though...

MrEggy commented 9 years ago

I have too found the same issue. I can call lightsOn using lightsOn() and individually turn lights on. However if I turn one light on with one set of properties and then turn a second one on using a different set of properties using LightsColour, the first light will change to the second set of properties. It seems that lightsColour works globally and there is no way of have lamps with different levels of luminance.

abalam666 commented 9 years ago

Does anyone found a solution on that ? I'm using ruby official code only because of this problem... and i don't like to code with ruby... :-/

MariusRumpf commented 9 years ago

The problem is that the packet headers are not implemented completely, they use some generic values that work in most cases. The problem is that a targeting of a single bulb is not possible with this generic values. You should consider searching for a library that supports the v2 protocol. https://www.npmjs.com/search?q=lifx

These to seem to work for me: https://www.npmjs.com/package/node-lifx https://www.npmjs.com/package/lifx-api

abalam666 commented 9 years ago

Thank you very much for your answer, i'll try your libs !

abalam666 commented 9 years ago

I confirm : node-lifx is working properly.

ghost commented 6 years ago

Modify the function as shown below. (lifx.js) Single bulb are controlled. (LightOn/LightOff/LightsColour) I hope this helps. .... Lifx.prototype._sendToOneOrAll = function(command, bulb) { var self = this; var bulbAddress = null; if (typeof bulb != 'undefined') { // Overwrite the bulb address here if (Buffer.isBuffer(bulb)) { bulbAddress = bulb; } else if (typeof bulb.addr != 'undefined') { bulbAddress = bulb.addr; } else { // Check if it's a hex string of a known bulb addr var b = self.bulbs[bulb] if (b) { bulbAddress = b.addr; } else { throw "Unknown bulb: " + bulb; } } // 2018.06.17 // bulbAddress.copy(command, 8); }

_(this.gateways).each(function(gw, ip) {
    var siteAddress = gw.site;
    siteAddress.copy(command, 16);
    // 2018.06.17
    if ( bulbAddress == null ) {
        self._sendPacket(gw.ip, gw.port, command);
    }
    else {
        if ( Buffer.isBuffer(bulbAddress) )
            bulbAddress = bulbAddress.toString('hex');
        if ( gw.bulbAddress == bulbAddress ) {
            self._sendPacket(gw.ip, gw.port, command);  
        }
    }
});

};

ryanmonro commented 4 years ago

@JungSungHeeK Thank you! That's working for me.