Activate multiple "in nodes", but each with delay?

Is there any elegant solution to this?

I need to call 5-8 "Node in" nodes, (each turns on relays), with different formations,
but it's not recommended to do it all at once to reduce power overload chance and interference.
So I need to leave some time between the actions.

  • Some kind of cycle would be nice, which needs only 2-3 node.

  • Can I call the "Node in" nodes directly? (From a function.)

You could do it with a function node outputting an increasing number, passed to a delay node for each 250ms delay, then a switch node taking the number and passing to the correct output to the correct linked in node.

It would be cleaner(ish) and maybe more manageable as you could change the message delay quicker.

[{"id":"45f356adf463df21","type":"inject","z":"c07b047ac4d1031c","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":340,"wires":[["ad27477b9db90af9"]]},{"id":"ad27477b9db90af9","type":"function","z":"c07b047ac4d1031c","name":"Counter","func":"for (var i = 0; i < 10; i++) {\n\n    node.send({\n        topic: i\n    })\n}\n\nnode.done();\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":340,"wires":[["cd49195e7a7bd6e1"]]},{"id":"6a7e775179a436a4","type":"switch","z":"c07b047ac4d1031c","name":"Switch","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"},{"t":"eq","v":"4","vt":"str"},{"t":"eq","v":"5","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":550,"y":340,"wires":[["fd784bb2d95c6a97"],["69ca47e9c6ff8f3c"],["65ff4e4b20b239c0"],["5d7b2175d60834c4"],["99c2eb9174ee7475"]]},{"id":"69ca47e9c6ff8f3c","type":"link out","z":"c07b047ac4d1031c","name":"link out 2","mode":"link","links":[],"x":675,"y":300,"wires":[]},{"id":"65ff4e4b20b239c0","type":"link out","z":"c07b047ac4d1031c","name":"link out 3","mode":"link","links":[],"x":675,"y":340,"wires":[]},{"id":"5d7b2175d60834c4","type":"link out","z":"c07b047ac4d1031c","name":"link out 4","mode":"link","links":[],"x":675,"y":380,"wires":[]},{"id":"99c2eb9174ee7475","type":"link out","z":"c07b047ac4d1031c","name":"link out 5","mode":"link","links":[],"x":675,"y":420,"wires":[]},{"id":"fd784bb2d95c6a97","type":"link out","z":"c07b047ac4d1031c","name":"link out 6","mode":"link","links":[],"x":675,"y":260,"wires":[]},{"id":"cd49195e7a7bd6e1","type":"delay","z":"c07b047ac4d1031c","name":"Delay","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":410,"y":340,"wires":[["6a7e775179a436a4"]]}]
1 Like

You can have an object called msg.delay, where property names reflects a link in nodes name and value is the delay. Pass that through a split node set to split msg.delay, and copy key to msg.target. Then have a delay node set to msg.delay and then a link call node set to send to msg.target. Finally make sure the corresponding link in has a link out set to return to link call node.
e.g.

[{"id":"fc83a3ec18010038","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"test","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":7540,"wires":[["d4e7238b24847c29"]]},{"id":"20e9cd21c919eddd","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"delay","v":"{\"1sec\":1000,\"2sec\":2000}","vt":"json"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":7540,"wires":[["fc83a3ec18010038"]]},{"id":"d4e7238b24847c29","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"target","property":"delay","x":490,"y":7540,"wires":[["d8389e93f1d5462b"]]},{"id":"d8389e93f1d5462b","type":"delay","z":"d1395164b4eec73e","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":640,"y":7540,"wires":[["3e0512e0826795b6"]]},{"id":"3e0512e0826795b6","type":"link call","z":"d1395164b4eec73e","name":"","links":[],"linkType":"dynamic","timeout":"30","x":800,"y":7540,"wires":[["8c2bf131d1114463"]]},{"id":"8c2bf131d1114463","type":"debug","z":"d1395164b4eec73e","name":"debug 2577","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":810,"y":7580,"wires":[]},{"id":"7753ed2cc43a9c53","type":"link in","z":"d1395164b4eec73e","name":"1sec","links":[],"x":525,"y":7700,"wires":[["06a1fce5b237dd6f","ac2bddc364f03e86"]]},{"id":"ac2bddc364f03e86","type":"link out","z":"d1395164b4eec73e","name":"link out 10","mode":"return","links":[],"x":715,"y":7660,"wires":[]},{"id":"06a1fce5b237dd6f","type":"debug","z":"d1395164b4eec73e","name":"debug 2575","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":7700,"wires":[]},{"id":"30021a1f86c67504","type":"debug","z":"d1395164b4eec73e","name":"debug 2576","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":7760,"wires":[]},{"id":"25fde0e88350236d","type":"link in","z":"d1395164b4eec73e","name":"2sec","links":[],"x":525,"y":7760,"wires":[["30021a1f86c67504","ac2bddc364f03e86"]]}]
1 Like

This might work too

[{"id":"2960e1995c367865","type":"inject","z":"514b185553136619","name":"","props":[{"p":"payload"},{"p":"topic","v":"[\"relay1\", \"relay4\", \"relay5\"]","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ON","payloadType":"str","x":90,"y":440,"wires":[["62e3f3ac43b1b4e7"]]},{"id":"3e248c5434a88c06","type":"delay","z":"514b185553136619","name":"1 msg / 5s","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"5","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":390,"y":440,"wires":[["4864310377d4eb27"]]},{"id":"4864310377d4eb27","type":"switch","z":"514b185553136619","name":"Topic","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"relay1","vt":"str"},{"t":"eq","v":"relay2","vt":"str"},{"t":"eq","v":"relay3","vt":"str"},{"t":"eq","v":"relay4","vt":"str"},{"t":"eq","v":"relay5","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":550,"y":440,"wires":[["510af376501bf81a"],["4f70f460e1d4d93e"],["de9c4b40ea8e325d"],["d4de9e139a0c664c"],["5b58f1093a614bb1"]]},{"id":"510af376501bf81a","type":"debug","z":"514b185553136619","name":"Relay1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":360,"wires":[]},{"id":"4f70f460e1d4d93e","type":"debug","z":"514b185553136619","name":"Relay2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":400,"wires":[]},{"id":"de9c4b40ea8e325d","type":"debug","z":"514b185553136619","name":"Relay3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":440,"wires":[]},{"id":"d4de9e139a0c664c","type":"debug","z":"514b185553136619","name":"Relay4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":480,"wires":[]},{"id":"5b58f1093a614bb1","type":"debug","z":"514b185553136619","name":"Relay5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":520,"wires":[]},{"id":"62e3f3ac43b1b4e7","type":"split","z":"514b185553136619","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"topic","x":230,"y":440,"wires":[["3e248c5434a88c06"]]}]

The input is msg.payload, perhaps "ON" or "OFF" and msg.topic, an array of relays to be switched, in order.

{
"payload":"ON",
"topic":["relay1","relay4","relay5"]
}

That was my first thought too, but than I would still need 5-7 nodes.

Looks great!

True, but it would be cleaner and more manageable.

Thank you very much for ALL the help!

From the 3 (half-)solutions, I've managed to put together one, that is:

  • working! (Not all above does.)
  • needs only 3 nodes all together
  • easy to change
  • can be copied and reused to the other use cases
[{"id":"248fd182180aba8f","type":"function","z":"2c9fbd1d.903c7a","name":"Array INs","func":"const InNodes = [\"In1\", \"In2\", \"In3 Kitchen\"];\n\nfor (let x of InNodes) {\n    msg.rate = 500;\n    msg.target = x;\n    node.send( msg );\n}\n\nnode.done();\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":100,"wires":[["e7529b53e6c82326"]]},{"id":"e7529b53e6c82326","type":"delay","z":"2c9fbd1d.903c7a","name":"Limit Rate 0.2","pauseType":"rate","timeout":"1000","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"0.2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":true,"outputs":1,"x":760,"y":100,"wires":[["2e0db48935ca7414"]]},{"id":"2e0db48935ca7414","type":"link call","z":"2c9fbd1d.903c7a","name":"Dynamic target call","links":[],"linkType":"dynamic","timeout":"30","x":970,"y":100,"wires":[[]]}]

I've learned 2 important things:

  • "Delay" node can be changed to work as "Rate Limiter".
  • "Link call" can be "Dynamic" by changing the type!
    (And "link-in" nodes called by name.")

This is the main function:

const InNodes = ["8in Nappali", "7in Konyha", "6in Fürdő", "5in 1.sz Ablak", "4in 1.sz Ajtó", "3in 2.sz. Ajtó", "2in 2.sz. Ablak"];

for (let x of InNodes) {
    msg.rate = 500;
    msg.target = "Fel_" + x;
    node.send( msg );
}

node.done();
1 Like