Contrib-Fibaro_Devices

To the Node-RED dev team + some other people that seem to be on the forum all the time and know a lot about Node-RED - @knolleary @TotallyInformation @Steve-Mcl @dceejay @BartButenaers

I have been using the fibaro-devices contrib to integrate my Fibaro Home Centre 2 to Node-RED.

Until recently it has worked flawlessly, however I hit a critical point of "device" nodes where not all of the nodes are picking up the correct value on initialisation.

I know very little about this. The author of the contrib is @10der.

We and another forum member from the Fibaro forum, have been chatting about this issue and he has explained to me that when node-red initialises there is functionality that is built into Node-RED that allows you to run code for each and every node on your canvas. @10der has written his code such that each individual node requests it's value via the Fibaro API on initialisation.

Seems like a pretty neat idea and it has been working great until recently.

We have tried a few angles to figure out why devices are not updating their values past a certain count of nodes on canvases, but have failed.

Through discussions we have agreed a workaround, but it's probably not as elegant as the original solution. On initialization the home-centre node now requests the complete devices API from Fibaro. We have tested this concept tonight, and it from initial testing it works.

The workaround will use this API fetched JSON dataset to update ALL the device nodes on all canvases, however this solution does introduce an edge case where the time it takes to call the API and update an individual node may be preceded by an device update naturally passing through for a newer value, however this newer value will be overwritten by the ALL devices API call.

If this is even allowed, it is not a desirable outcome, so to the question:

Can you think of anything in the way that Node-RED is designed that would stop the initialisation code running through to completion e.g. a built-in timeout?

So I interpret your workaround edge case like this:

  1. When the node is intialized, the 'value' is null/undefined.
  2. Then you call the complete devices API
  3. Meanwhile a device update updates the 'value' to 'newValue'.
  4. Afterwards the callback handler of step 2 is executed, which overrides the 'newValue' of step 3 by an older value.

Can't you do something like this in your callback handler of step 2:

function someCallBackHandler(valueFromAllApi) {
   // Only use the value from the ALL API callback handler, when there is no value available yet in this node:
   if (node.newvalue == undefined) {
      node.newValue = valueFromAllApi;
   }
}

I assume I have misinterpreted your issue...
Bart

2 Likes

No you have not misinterpreted the issue.

I just didn't think it through and also don't really know how it works as I've never tried to build a node myself, but even without having done so, what you have said makes complete sense and seems very obvious now. Doh!

I'll talk to the author and see what he can do.

Thank you.

It would still be interesting to understand why the error was happening in the first place, assuming someone knows.

1 Like

tnx. on it.
probably will be implemented .75

2 Likes