jdomeij / node-red-contrib-node-lifx

Node RED nodes for controlling Lifx lights
Apache License 2.0
7 stars 9 forks source link

Cannot get color to change on LIFX downlight 100mm #16

Open macinspak opened 5 years ago

macinspak commented 5 years ago

I have the nodes set up, but I have completely no luck setting payload for hue, sat, red, green, blue, hex, etc.

I can easily turn the light on and off and change brightness, with duration, but the light stubbornly stays white and keeps reporting back:

{"on":true,"reachable":true,"bri":100,"hsv":[27,5,100],"rgb":[255,248,242],"hex":"FFF8F2","color":"floralwhite","kelvin":3500,"mired":286}

No matter what color I try to change it to, it's stuck on white!

Any ideas?

cakefornoreason commented 5 years ago

I’ve run into something like this before. Some versions of the node-lifx package use an outdated product list and lights don’t respond properly if your light type isn’t in the included list. If you can locate products.json within the node-lifx package and replace it with the most current version, does that make a difference?

The most current version of the product list is here: https://github.com/LIFX/products/blob/master/products.json

macinspak commented 5 years ago

That fixes it, but it seems odd. So what's the permanent fix?

cakefornoreason commented 5 years ago

In short, it's an issue with the node-lifx dependency, not the node-red-contrib-node-lifx package itself.

The node-life package (https://github.com/MariusRumpf/node-lifx) hasn't been updated in about a year, but LIFX has released new products since its last update. You could open an issue on that package, but that's really what we're waiting on. I'm just happy this package works with the minor modification. Until node-lifx updates, doing an npm install of this package will always give you the "current" node-lifx, and thus the outdated product list.

I run my home lighting system on a Raspberry Pi and just keep a copy of the current products.json on the desktop, as I have to replace it if I ever need to reinstall, but it does work reliably. In my case, the missing products are my new LIFX mini bulbs, but my code always acts funny if I forget to update the products.json file, so that would seem to be the clear problem.

So it's definitely fiddly, but at least it works!

ristomatti commented 5 years ago

I have been considering forking node-lifx and publishing to npm with another name for some time as I've had a few pull requests open there for months.

But since this might not ever happen due to lack or time, for now I'd suggest forking both node-lifx and this repository. Then update the products.json on your node-lifx fork. Change your fork of this repo to use your GitHub repository as the source for node-lifx. Then finally install node-red-contrib-node-lifx to Node-RED from your GitHub fork. I've been using this approach for a long time to get to use my improved node-lifx version with Node-RED. It's a bit of a hassle but what can you do...

Thanks for the tip with the products.json! I've recently bought some GU10 downlights and a Tile set but haven't yet had time to setup them to my home automation system. I'll probably need to update the file myself.

cakefornoreason commented 5 years ago

Glad to help! I'm actually using your forked version of this package in my setup, but I've still been manually updating products.json. The weird thing is that the product list on LIFX's developer site isn't even fully current right now, only the GitHub version. I figure they'll update soon, but it was a lucky find on my part.

If you're bored, I'd love to see a version of this with multizone support, as I know it's there in the node-life package, but I have no idea how easy or hard it'd be to implement. I'm just not a good enough coder to add it myself, so I've been sticking with the cloud API for that. Again, not the most straightforward thing, but it does the job!

ristomatti commented 5 years ago

@cakefornoreason Good catch! Unfortunately I feel LIFX people have been more focused on getting new products out than on the developer community for quite some time. Adding multizone support would not be too difficult but a lot of work. There hasn't been too many updates on this repo either, I wonder if @jdomeij is planning on adding this? Anyway I'd reckon that better be reported as a separate feature request.

I've done some small changes for myself to node-red-contrib-node-lifx for my personal needs on my development branch but to be honest I didn't feel comfortable enough with the code base that I'd start working on that. I've got quite a bunch of LIFX products I use daily with Node-RED though, enough to feel the current approach of node for each light approach quite limiting. I'm thinking some day the frustration will overcome my lazyness to create a Node-RED module myself unless someone else does it first. :)

ristomatti commented 5 years ago

@cakefornoreason In case it's of any help, I've updated my node-lifx fork with the latest products.json, and updated my fork https://github.com/ristomatti/node-red-contrib-node-lifx so that it's master branch uses my node-lifx fork with the improvements I've done (faster updates on multiple lights for instance). I remember having issues with it's postinstall script on some Node.js version though. In case you want to try it out but encounter the issue, please report it to either of my forks and I'll see what I can do about it. Cheers!

macinspak commented 5 years ago

I am about to install around 130 LIFX 100mm downlights in my home (wish me luck), I am HOPING using my https://flows.nodered.org/node/node-red-contrib-light with the LIFX downlights, hue switches and motion sensors I can get it working well together with dimming, night lights, auto off and more.

Good to know you are using a number of LIFX lights so I'll keep you posted on my progress and may ask questions if somethings going weird.

My https://flows.nodered.org/node/node-red-contrib-light currently works very well for on/off with the hue switch and dimming is "ok" - though I think could be improved.

Oddly enough, if you use the hue dimmer with the hue app to dim a bunch of hue downlights and quickly dim up and down, the lights quickly get out of sync and may be at 10%, 30% and 60% brightness. So it appears they send individual up/down type commands to each light, so they somtimes miss out and get out of sync. My module works differently. It just takes the first brightness and modifies it, then sends that brightness to ALL globes. so they cannot get out of sync. I am actually contemplating removing the hue direct link from switches and motion sensors to lights and replacing with my approach through node-red.

By the way @ristomatti, using my library, you essentially wire each LIFX to a couple of nodes and name it (just on some other "catalog" flow in node red) and then you can address any collection as a grouping with one node on your main automation flows. Give it a try and let me know what you think. This is really flexible as you only need to set up the light nodes once, then you have complete flexibility to even programmatically address a bank of lights (via msg.payload.lights: ["light1", "light2",..]) or set them as a list of lights on the node to send instructions to all of them as a group.

ristomatti commented 5 years ago

Thanks for sharing, I wasn't aware of this node. Based on its description its suffering from the same issues being dependent of this repo which is dependent on the ever deprecating node-lifx. The developer seems to have some novel ideas, similar to what I have been doing through just plain function nodes currently. But it doesn't sound good if it's all based on the same deprecating structure.

I'll see tomorrow if I'll have time to try it out. If it seems something I like, maybe I could consider publishing node-lifx to npm under a different name. The problem is that although I've contributed to it, there's a lot of things I'm unsure about it's inner workings, and it almost feels like I'd rather do a complete rewrite than start maintaining it as such. Another problem is I'm currently working primarily with JavaScript as my day job. On my spare time I'd rather focus on my electronics hobby (mostly focused around home automation also)...

Or maybe I could see what's the status with node-lifx-lan. I've been following it and it's developer has seemed quite active. If it offers everything node-lifx does, possibly time would be better developing a Node-RED wrapped for it instead (with as much compatibility to node-red-contrib-lifx as possible).

But with that said, I'd rather hear someone else popping up and telling about yet another new Node-RED node I'm unaware of that already has all this sorted out! Or better yet @jdomeij taking note of this off topic issue thread and suggesting some other solution. :)

ristomatti commented 5 years ago

@macinspak oops sorry I must be too tired and answered midway of reading your comment, now realising it was developed by you. I'll try my best to get back to you tomorrow with fresh brain.

ristomatti commented 5 years ago

@macinspak Sorry I haven't had time to test node-red-contrib-light but I skimmed through the code on my tablet last night though. Initially I thought it'd be tightly coupled with node-red-contrib-node-lifx in some way but instead it's loosely coupled using just the JSON format, which I think is clever! This way you can easily adapt it to work with any other Node-RED node. Nice work!

I've actually done a very similar thing for the exact same purpose (as described on node-red-contrib-light README.md) but just using plain old function nodes (out of lazyness). I also had bought some Hue dimmer switches just for the purpose of using them to control my LIFX lights. I've set it up so that the states of the node-red-contrib-node-lifx output nodes are stored under a global state object. This way I am able to pick up the current color/brightness of the lights and control the brightness individually for each light without changing any other property. If I understood correctly this is one thing node-red-contrib-light makes possible right?

In case you're curious, the same state object also stores the values from all my other sensors, so it's easy for me to create interactions depending on certain conditions. At work we're using React and Redux so I've borrowed some ideas from there. The global state object is managed in an immutable fashion using setState and getState functions which are also stored in the global state. They're defined on three consecutive function nodes that are created on startup using an inject node:

Create and store global function object

const fn = {};

global.set('fn', fn);

return {fn};

Define getState function

const {isNil, isString, clone, get} = global.get('lodash');
const {fn} = msg;

/**
 * Get state by object path
 */
fn.getState = function(path, defaultValue) {
  const state = global.get('store');

  if (path === undefined) {
    return clone(state);
  }

  if (!isString(path)) {
    return node.warn('Parameter "path" invalid or missing');
  }

  return clone(
    get(state, path, defaultValue)
  );
};

return {fn};

Define setState function

const {isString, isObject, assign, merge} = global.get('lodash');
const {fn} = msg;

/**
 * Set global state
 */
fn.setState = function(key, data) {
  if (!isString(key)) {
    return node.warn('Parameter "key" invalid or missing');
  } else if (!isObject(data)) {
    return node.warn('Parameter "data" invalid or missing');
  }

  const oldState = getState();

  const state = assign(getState(), {
    [key]: merge(getState(key), data)
  });

  global.set('store', state);

  node.send({state});
};

The setState function sends the new global state on it's output so that I can either do stuff based on the changes whenever setState is called somewhere or can add derived values to the global state (e.g. if all the lights are on/off). To give you some idea what I have in the global state object, here's a screenshot of a debug node print off the object:

image

This allows me to just call getState('lifx.Bedroom') to get access to the state of the bedroom light. My Node-RED setup has grown so complex it's started to be a pain to manage it based on the visual nodes only, so this allows me to do quick hacks using just JavaScript. :)

jdomeij commented 5 years ago

Yooo, I have following this thread and only wanted to give some information about the current status of the project. As it is now this project is mostly unmaintained, I don't have any energy or hardware to maintain this project (my two Lifx lights that I use have stopped responding). Currently I use the Hue version for my small needs.

ristomatti commented 5 years ago

@jdomeij Sorry to hear that! And perfectly understandable. You've got bad luck with the bulbs then... I've bought 14 different lights during the last five years. Only one bulb has failed so far. The oldest one is still in use!

I guess someone ought to fork the project then...

ristomatti commented 5 years ago

@jdomeij BTW I think it would be worth the shot to contact LIFX support, and ask if they'd be willing to replace your broken bulbs. Even if they're likely out of their warranty period, they might want to support an active community member that way.