Quit during DELAY or WAIT UNTIL command

Hi Guys,

I am completely new to NODERED and just starting out in Home Automation. I have created a simple flow... RGB bulb turns of at {255,255,255} WHITE and delay or wait until for 5 seconds and then at {255,0,0} RED and delay or wait until for 5 seconds and then {0,255,0} GREEN and delay or wait until for 5 seconds and then {0,0,255} BLUE and then loop to the previouse {255,255,255} WHITE state... During the cycle if I give INJECT - TURN OFF RGB bulb, it doesnt turn off and keeps on looping... Please let me know what I need to do to get it corrected. Any suggestions will be really great for me... Also please share me if you have any documentation... Thanks so much for your help...

Ananth

Can you show us your flow? A screen capture is nice, plus the flow exported as JSON and pasted here using the </> button

Hi JBUDD,

Thanks so much for your reply... All I am trying to do is making color change from WHITE -> RED -> GREEN -> BLUE -> WHITE and the loop continues... If I click on Inject and give a TURN OFF RGB the bulb never goes off and still continuing the loop. I have attached the screenshot and Flow export for your reference. Thanks again.

<[{"id":"076369a220b218b0","type":"ha-wait-until","z":"960e647257e44eb6","name":"RGB01","server":"61e06672bcb1d0fb","version":1,"outputs":2,"entityId":"light.or_test_rgbcwb_bulb_01","entityIdFilterType":"exact","property":"state","comparator":"is","value":"ON","valueType":"jsonata","timeout":"5","timeoutType":"num","timeoutUnits":"seconds","entityLocation":"data","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":1100,"y":240,"wires":[["467e5e64d6aba530"],["84157ad08ae34dea"]]},{"id":"61e06672bcb1d0fb","type":"server","name":"Home Assistant 01","version":4,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":": ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"default","statusTimeFormat":"h:m"}]>

Ananth

I see that this is a Home Assistant flow problem.
Have you asked the Home Assistant community in their forum?

As Paul says, it's Home Assistant. We see a lot of HA queries here but few answers because most people don't use HA.
No doubt it is a very good operating system but I have not discovered what it offers over and above Node-red.

Here's how I would achieve what you describe just in Node-red.


White 5s, Red 5s, Green 5s, Blue 5s and repeat until told to stop.

[{"id":"dafdba319b2e4b0b","type":"inject","z":"a49f67fa0c96285a","name":"GO","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":370,"y":220,"wires":[["6e2629afad2ef035","87188dcbb13e01c0"]]},{"id":"6e2629afad2ef035","type":"trigger","z":"a49f67fa0c96285a","name":"WHITE then RED","op1":"255,255,255","op2":"255,0,0","op1type":"str","op2type":"str","duration":"5","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":2,"x":630,"y":220,"wires":[["ccf20fa499ebc48a"],["9f5c16c55f538125","ccf20fa499ebc48a"]]},{"id":"9f5c16c55f538125","type":"trigger","z":"a49f67fa0c96285a","name":"Nothing then GREEN","op1":"","op2":"0, 255,0","op1type":"nul","op2type":"str","duration":"5","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":620,"y":280,"wires":[["ccf20fa499ebc48a","45fb09d191b9fa35"]]},{"id":"45fb09d191b9fa35","type":"trigger","z":"a49f67fa0c96285a","name":"Nothing then BLUE","op1":"","op2":"0,0,255","op1type":"nul","op2type":"str","duration":"5","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":630,"y":340,"wires":[["ccf20fa499ebc48a","631fe4f90a6f045d"]]},{"id":"ccf20fa499ebc48a","type":"debug","z":"a49f67fa0c96285a","name":"LED Control","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":890,"y":280,"wires":[]},{"id":"d21516b1b4dac045","type":"inject","z":"a49f67fa0c96285a","name":"STOP","props":[{"p":"payload"},{"p":"reset","v":"","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"STOP","payloadType":"str","x":370,"y":300,"wires":[["6e2629afad2ef035","9f5c16c55f538125","45fb09d191b9fa35","631fe4f90a6f045d","e42663fcaa0f26ae"]]},{"id":"631fe4f90a6f045d","type":"trigger","z":"a49f67fa0c96285a","name":"Nothing then repeat","op1":"","op2":"repeat","op1type":"nul","op2type":"str","duration":"5","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":630,"y":400,"wires":[["20fa9e4e2c71cb86"]]},{"id":"87188dcbb13e01c0","type":"debug","z":"a49f67fa0c96285a","name":"START","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":600,"y":160,"wires":[]},{"id":"e42663fcaa0f26ae","type":"debug","z":"a49f67fa0c96285a","name":"STOP","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":460,"wires":[]},{"id":"20fa9e4e2c71cb86","type":"junction","z":"a49f67fa0c96285a","x":800,"y":160,"wires":[["6e2629afad2ef035"]]}]

Hi JBUDD,

Thanks Thanks Thanks so much for your help... Your solution partially works and even tweaking in my code worked as well... I can see that in STOP (INJECT NODE) you have given msg.reset and that seems to stop the code... I have developed the code a lit bit complex and I am using a FOR Loop which turns WHITE ( RGB Color - 255,255,255) to YELLOW (RGB Color - 255,255,0). For this I can change the delay time as per my wish and make the transition fast or slow... I tested the same in DEBUG node and also with my RGB Bulb and they work great...

But I am stuck with 3 hurdles... First the Else statement doesnt seem to execute and only the IF statement continues and stops after the FOR loop reaches its end... Second the current code is from WHITE -> YELLOW... I want to how to proceed with the following transitions...

255,255,255 -> 255,255,0 -> 255,0,0 -> 255,0,255 -> 0,0,255 -> 0,255,255 -> 0,255,0 -> 255,255,0 -> 255,255,255
WHITE -> YELLOW -> RED -> MAGENTA -> BLUE -> CYAN -> GREEN -> YELLOW -> WHITE

Third during the time FOR LOOP that changes from White to Yellow is running no matter I click msg.reset and STOP the loop the code keeps on running and I cannot come out of it and STOP it...

I have attached the FLOW chart and also the picture. Any help and suggestion you give will be really helpful for me... Thanks so much for your help.

Ananth

[{"id":"fc4ceb52012221d7","type":"function","z":"76400db782763139","name":"WHITE TO YELLOW","func":"var a;\nvar b;\nvar c;\nvar red = 255;\nvar green = 255;\nvar blue = flow.get ('a') || 255;\nvar exit\nif (msg.a > 10) \n{\n    for (a = 255; a >= 10; a = a - 10);\n    {\n        msg.a = msg.a - 10;\n        blue = blue - 10\n        flow.set('a', blue)\n        msg.rgb = [red, green, blue]\n        return msg;\n    }\n}\nelse\n{\n    msg.rgb = [255, 255, 0]\n    msg.exit\n    //return msg;\n}\n//return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":140,"wires":[["76601bb95751a503","68f5efbaee04ec1b","85f3497e163a79af"]]}]

That is correct, but msg.reset is not a general purpose interrupt, it's specific to core nodes which include a delay (delay and trigger nodes).
I think you are trying to use the function node WHITE TO YELLOW to try and create a smooth transition between white and yellow. I doubt if it works though because this code will run just once, not 25 times. (return exits the function node).

    for (a = 255; a >= 10; a = a - 10);
    {
        msg.a = msg.a - 10;
        blue = blue - 10
        flow.set('a', blue)
        msg.rgb = [red, green, blue]
        return msg;
    }

Note that a function will run it's code till the end before it pays attention to the next message waiting at the input, so msg.reset cannot stop it.
I don't know any simple way to interrupt a loop within a function node.

I had Node-red controlling my christmas tree lights this year, smoothly transitioning from one colour to the next. The LED control was with a Python script though, and if you want smooth transitions it might be wise to look at a program external to Node-red. Or there may be contrib nodes available to help with this.

Maybe something you can build on?

[{"id":"4ddf057ca1d5a4e2","type":"inject","z":"d8cbe4ea176a583b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":90,"y":360,"wires":[["cb47691bd4b8bd66"]]},{"id":"cb47691bd4b8bd66","type":"function","z":"d8cbe4ea176a583b","name":"WHITE TO YELLOW","func":"let invar = msg.payload\n\nlet red = 255\nlet green = 255\nlet blue = 255\n\nlet MyIntervalID = context.get('MyIntervalID') || undefined\nlet timeout = 200 // msec\n\nfunction MyInterval() {\n    let count = 255\n    if (MyIntervalID != undefined) { clearInterval(MyIntervalID) }\n    MyIntervalID = setInterval( ()=> {\n        node.warn(count) // remove after test\n        msg.rgb = [red, green, blue]\n        blue = blue - 10\n        node.send(msg)\n        count -= 10; if (count < 5) { clearInterval(MyIntervalID) }\n    }, timeout)\n}\nswitch(invar) {\n    case true:\n        MyInterval()\n        break\n    default:\n        node.warn('ha ha') // remove after test\n        clearInterval(MyIntervalID)\n        msg.rgb = [255, 255, 0]\n        node.send(msg)\n}\ncontext.set('MyIntervalID', MyIntervalID)\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":380,"wires":[["cc141d37f1129a11"]]},{"id":"3b1617f26ed9d7b1","type":"inject","z":"d8cbe4ea176a583b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":90,"y":400,"wires":[["cb47691bd4b8bd66"]]},{"id":"cc141d37f1129a11","type":"debug","z":"d8cbe4ea176a583b","name":"debug 263","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":610,"y":380,"wires":[]}]