Giter Site home page Giter Site logo

rdmtc / node-red-contrib-combine Goto Github PK

View Code? Open in Web Editor NEW
6.0 6.0 4.0 348 KB

Node-RED Nodes that outputs combinations of consecutive incoming messages

License: MIT License

JavaScript 77.77% HTML 22.23%
combine list logic node-red statistics

node-red-contrib-combine's People

Contributors

hobbyquaker avatar sineos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

node-red-contrib-combine's Issues

List Node Delay

Hello

I have got a problem with using List Node from your package.
The problem starts when I enable Timeout function

image
It is causing the following error:

image

Please help, as the Node output data in the format I want, just need to dump the stored information every 1 s.

Question about deferred sending mode in logic node

I have a question about the design of "deferred sending mode" in logic node.

Currently, deferred sending works in the following way:

  1. a message is received
  2. combine() is called on the array of current values - result is undefined as current values array is empty
  3. send() is scheduled to run in XX seconds; it is scheduled for sending the currently combined values (why?)
  4. ... incoming messages ...
  5. deferred timeout expires and stale combine() value from step 2 above is sent
  6. new message is received
  7. combine() is called on the array of current values
  8. ...
  9. deferred timeout expires and stale combine() value from step 7 above is sent

I am wondering what is the reason for scheduling deferred sending of stale combined values instead of sending the actual combined values? I have a case where this is causing some interesting problems. :-) Thermostat nodes for rooms in my house are emitting heating ON/heating OFF boolean values. Because heating must be turned ON when at least one room requires heat, I have to combine values from all rooms before enabling/disabling central heating. I was hoping to solve this by using deferred sending (i.e. collect values for 10 minutes, enable/disable heating afterwards). With current logic, it may take up to 20 minutes for heating to be turned on after one of the room requires heating.

Is there any way to implement "pooling" combine logic - i.e. to collect emitted values and send a combined value after a deferred/pooling timer expires?

"Reduce of empty array" exception in combine() when using timeout & deferred in logic node

combine() method of logic node may be invoked on an empty array when timeout functionality is used. This causes node-red to exit with unhandled exception.

node-red    | 13 Nov 15:18:32 - TypeError: Reduce of empty array with no initial value
node-red    |     at Array.reduce (<anonymous>)
node-red    |     at CombineLogicNode.combine (/data/node_modules/node-red-contrib-combine/nodes/combine-logic.js:71:31)
node-red    |     at CombineLogicNode.remove (/data/node_modules/node-red-contrib-combine/nodes/combine-logic.js:44:30)
node-red    |     at Timeout.timeouts.(anonymous function).setTimeout [as _onTimeout] (/data/node_modules/node-red-contrib-combine/nodes/combine-logic.js:37:26)
node-red    |     at ontimeout (timers.js:498:11)
node-red    |     at tryOnTimeout (timers.js:323:5)
node-red    |     at Timer.listOnTimeout (timers.js:290:5)

When an item times out, remove() is called. remove() removes the item from the payloads array and causes a new message to be sent with "recalculated" values in combine(). The payloads array may be empty if this was the last item to be removed, causing combine() to invoke Arrays.reduce() on an empty array without an initial accumulator value.

I suggest a guard is added to the code which prevents sending a new message when the payloads array is empty.

logic node question

I'm playing with the logic node, but I cannot achieve what I intend:

  • Multiple inputs
  • If any of the inputs is true then true --> Works with OR
  • If all inputs are false then false --> Should also work with OR (at least I think so, Boolean algebra isn't my big strength)

The OR function of the logic node results in undefined if the first arriving message is false or if all messages are false.

My test flow:

[{"id":"6158d3c1.0e4ddc","type":"combine-logic","z":"2808bf91.f42188","name":"","topic":"","operator":"or","defer":250,"timeout":0,"distinction":"topic","x":400,"y":1120,"wires":[["6a350ed2.d5472"]]},{"id":"b46b83c4.782ea8","type":"inject","z":"2808bf91.f42188","name":"","topic":"1","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":1140,"wires":[["6158d3c1.0e4ddc"]]},{"id":"6e01b5e8.d307c4","type":"inject","z":"2808bf91.f42188","name":"","topic":"2","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":1180,"wires":[["6158d3c1.0e4ddc"]]},{"id":"d74f57e5.605c08","type":"inject","z":"2808bf91.f42188","name":"","topic":"3","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":1220,"wires":[["6158d3c1.0e4ddc"]]},{"id":"6a350ed2.d5472","type":"debug","z":"2808bf91.f42188","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":560,"y":1120,"wires":[]},{"id":"5c40dde0.b8de4c","type":"inject","z":"2808bf91.f42188","name":"","topic":"1","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":1020,"wires":[["6158d3c1.0e4ddc"]]},{"id":"a5919e98.5f6458","type":"inject","z":"2808bf91.f42188","name":"","topic":"2","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":1060,"wires":[["6158d3c1.0e4ddc"]]},{"id":"fabb86e4.157198","type":"inject","z":"2808bf91.f42188","name":"","topic":"3","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":1100,"wires":[["6158d3c1.0e4ddc"]]}]

usage of if node

Hello,
could you provide an example for the if-node? setting msg.condition to true or false does not change the used output.

Or do I get the swithing behavior completely wrong?

Best regards

Object.values() gives an error - node.js version support?

Sorry if I'm not an expert in node.js or node-red, but tried installing this on node-red on ubuntu 17.10 which runs node.js 6.11.x - I then got errors from the statistics node that Object.values() in combine() "TypeError: Object.values is not a function"

I think, from reading online, this is because it requires node.js 7.x support, which I don't have.

If this is the case then can I suggest a note or dependency to avoid others making the same mistake on install?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.