While loop not working, even though false condition is met

Hi,

I am trying to increment the brightness of my led while I hold down my Ikea tradfri button. If I hold the down button, the msg.payload.event.command output is "move". As soon as I let go it outputs "stop_with_on_off" as you can see in the debug menu. However I still get an endless loop, because it still resorts to the true condition, even though the false was met.

Thanks in advance

Try to avoid loops at all cost in node-red.

The easiest way to do this is to use a trigger node, which can send a message every second.
The trigger node can be cancelled by sending a msg.reset (usually i send msg.reset set to false)
This will cancel the trigger and thus the brightness.

Something like this:

The Trigger node can also be reset by any msg.payload value you wish to use. So you can trigger on move and reset on stop_with_on_off.
e.g.

[{"id":"c6b3048da8f259f9","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 226","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":3820,"wires":[]},{"id":"17ae2d4bda5d3143","type":"trigger","z":"da8a6ef0b3c9a5c8","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"-1","extend":false,"overrideDelay":false,"units":"s","reset":"stop_with_on_off","bytopic":"all","topic":"topic","outputs":1,"x":400,"y":3880,"wires":[["c6b3048da8f259f9"]]},{"id":"4b948b0a3f5a39e5","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"move","payloadType":"str","x":170,"y":3860,"wires":[["17ae2d4bda5d3143"]]},{"id":"bde352fde2225293","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"stop_with_on_off","payloadType":"str","x":160,"y":3900,"wires":[["17ae2d4bda5d3143"]]}]
1 Like

Thanks this works flawlessly

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.