rdmtc / node-red-contrib-combine Goto Github PK
View Code? Open in Web Editor NEWNode-RED Nodes that outputs combinations of consecutive incoming messages
License: MIT License
Node-RED Nodes that outputs combinations of consecutive incoming messages
License: MIT License
I have a question about the design of "deferred sending mode" in logic
node.
Currently, deferred sending works in the following way:
combine()
is called on the array of current values - result is undefined as current values array is emptysend()
is scheduled to run in XX seconds; it is scheduled for sending the currently combined values (why?)combine()
value from step 2 above is sentcombine()
is called on the array of current valuescombine()
value from step 7 above is sentI 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?
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.
I'm playing with the logic node, but I cannot achieve what I intend:
true
then true
--> Works with ORfalse
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"]]}]
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
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.