I am new to node, so bare with me for the newbe question.
Background: I am using node-red installed on a HomeAssistance box
I am trying to setup Node to execute a loop. I am using node-red-contrib-loop.
On the Loop cycle, I am not able to create a condition to exit properly the loop.
See this example:
- I start setting the payload to "on" or "off" using two different starting injection node.
- loop cycle start
- if injection was "off", the loop does not execute and exit, which is the expected behaviour.
- if injection started with "on", the loop cycle execute, payload gets changed to "off" though a function after 5 seconds the loop should exit the cycle.
But this never happen and the loop continue without ever stopping.
On the "Loop Status" debug trace you can notice that the paylod gets actualy changed to "off" but the condition on the loop is never valid
Loop node is configured like this:
Function code is simply:
msg.payload = "off";
return msg;
Any suggestion?
This is the code of it
[{"id":"12ff73b357cc048c","type":"debug","z":"88350d16bca26e96","name":"Initial payload","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":360,"y":180,"wires":[]},{"id":"05eca99e83ef171b","type":"delay","z":"88350d16bca26e96","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":420,"y":360,"wires":[["a97bb9f03de6e1a0"]]},{"id":"04df46b06fba53d6","type":"debug","z":"88350d16bca26e96","name":"EndLoop","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":920,"y":340,"wires":[]},{"id":"11868e0005682135","type":"debug","z":"88350d16bca26e96","name":"Loop Status","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":400,"wires":[]},{"id":"a97bb9f03de6e1a0","type":"loop","z":"88350d16bca26e96","name":"Loop is Charging","kind":"cond","count":"","initial":"1","step":"1","condition":"msg.payload===\"on\"","conditionType":"js","when":"before","enumeration":"enum","enumerationType":"msg","limit":"","loopPayload":"loop-keep","finalPayload":"final-last","x":710,"y":360,"wires":[["04df46b06fba53d6"],["11868e0005682135","daf1fe87f33cb6af"]]},{"id":"51b60d1515376b14","type":"inject","z":"88350d16bca26e96","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":130,"y":180,"wires":[["12ff73b357cc048c","a97bb9f03de6e1a0"]]},{"id":"daf1fe87f33cb6af","type":"function","z":"88350d16bca26e96","name":"function payload update","func":"msg.payload = \"off\";\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":150,"y":360,"wires":[["05eca99e83ef171b"]]},{"id":"af8fe1c7d6bd86fb","type":"inject","z":"88350d16bca26e96","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":130,"y":220,"wires":[["a97bb9f03de6e1a0","12ff73b357cc048c"]]}]