Creating a loop I think!

Hello

I'm running node red on a Raspberry pi3.
I need to create a loop I think.
if the weight is greater > 10.00 then open and close the side value. 5 seconds open 5 seconds closed. then repeat
if the weight is greater > 10.00 then open and close the side value. 5 seconds open 5 seconds closed
then
if the weight is greater < 10.00 then close the side value.

I have the switch working with the properties of > or < 10.00 which is working as it should

I just can't understand the open and close side value for 5 seconds.
can anyone help me, please?

Also, I'm a newbie to this.

Thank you in advance

There are a number of ways to do the wait

Take a look at the trigger node
Or look at the delay node

I have tried these but I cannot make this work. all that I have archived is pulling my hair out LOL.
So how would you suggest this will work

So I need the payload to be 0 for on and 1 for off.
but these need to be sent once every 5 seconds.

trigger node works perfectly for this.

[{"id":"e21999f4.7dfe7","type":"inject","z":"edc1cbfc.6b3b8","name":"","topic":"","payload":"12","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":308,"wires":[["fb45f1e0.5bf138"]]},{"id":"f52683fe.9cc9d","type":"inject","z":"edc1cbfc.6b3b8","name":"","topic":"","payload":"9","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":352,"wires":[["fb45f1e0.5bf138"]]},{"id":"fb45f1e0.5bf138","type":"switch","z":"edc1cbfc.6b3b8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"10","vt":"num"},{"t":"lte","v":"10","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":314,"y":330,"wires":[["2808e8d5.d36808"],["f903fa10.ec3758","9b399400.b0a9c"]]},{"id":"2808e8d5.d36808","type":"trigger","z":"edc1cbfc.6b3b8","op1":"open","op2":"close","op1type":"str","op2type":"str","duration":"5","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":632,"y":264,"wires":[["e005e34e.5d8578"]]},{"id":"e005e34e.5d8578","type":"debug","z":"edc1cbfc.6b3b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":730,"y":352,"wires":[]},{"id":"f903fa10.ec3758","type":"change","z":"edc1cbfc.6b3b8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":498,"y":396,"wires":[["e005e34e.5d8578"]]},{"id":"9b399400.b0a9c","type":"change","z":"edc1cbfc.6b3b8","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":498,"y":352,"wires":[["2808e8d5.d36808"]]}]

Thanks so much for coming back to I have added this to my flow and because of my input node is creating an output every 1 second I get a closed every second, which is fine but when the switch is > 10.00 the open is followed by a closed straight away. hope this makes sense.

Ok so how do you see this work with a 5 second window of open/close, do you want to execute them all ? You will end up with a major lag. You can add a delay as rate limiter (max 1 per 5 seconds) in the input.

ideally the way I would like this to work is, disregard any messages that are received. any payload > than 10.00 open and close the valve once then start the process again. the default position of the valve is closed.

I need to ideally be able to customised the valve opening and closing time

I have added a delay as suggest but it's doing some crazy things!

Take a look at the cookbook https://cookbook.nodered.org/basic/route-on-context

You could use the change node to set a flow/global variable and then use a switch on your input based on that flow/global variable

How did you configure the delay node ? This should sit in front of the switch node.

yea that's how I had it configured just seems to do some weird things.

I think whats happening is every 5 seconds its sending a close. once the open is received the closed message follows it straight away not giving the valve to open for 5 secs and close for 5 seconds.

I forgot to check the checkbox.

How are the triggers suppose to work?
mine will send an 1 (open) straight away
wait 5 seconds
then send a 1 (open) and a 0 (close) at the same time. is this normal?

If you are sending a message every 5 seconds as well, are you sure you aren't seeing the triggered message and the next message?

You are sending numbers and strings ? Not the same thing.
Can you post your flow, and some input examples ?

[{"id":"66efa7f8.f43b48","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"d0e46998.c11a08","type":"ui_gauge","z":"66efa7f8.f43b48","name":"","group":"f13266f9.ba79b8","order":4,"width":0,"height":0,"gtype":"gage","title":"gauge","label":"","format":"{{value}}","min":0,"max":"1000","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":590,"y":620,"wires":[]},{"id":"83dae66c.1f0b88","type":"serial in","z":"66efa7f8.f43b48","name":"","serial":"4d850d89.ed6994","x":270,"y":620,"wires":[["d0e46998.c11a08","dfe9033b.370e5"]]},{"id":"8012e5a6.d874e8","type":"function","z":"66efa7f8.f43b48","name":"payload 1","func":"msg.payload = 1\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":380,"wires":[["84773402.193848"]]},{"id":"a832c13.8bd904","type":"function","z":"66efa7f8.f43b48","name":"Payload 0","func":"msg.payload = 0\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":300,"wires":[["84773402.193848","7b87346c.30948c"]]},{"id":"1932fb28.2dbcb5","type":"change","z":"66efa7f8.f43b48","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":220,"wires":[["95796087.40c8a","d7a9a518.97d5e8"]]},{"id":"5b50a292.67a84c","type":"change","z":"66efa7f8.f43b48","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":534,"y":162,"wires":[[]]},{"id":"dfe9033b.370e5","type":"switch","z":"66efa7f8.f43b48","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"10.00","vt":"num"},{"t":"lte","v":"10.00","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":250,"y":80,"wires":[["a832c13.8bd904"],["5b50a292.67a84c","8012e5a6.d874e8"]]},{"id":"84773402.193848","type":"ui_switch","z":"66efa7f8.f43b48","name":"","label":"Fan","tooltip":"","group":"c1cdc8de.1ea148","order":10,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"0","onvalueType":"num","onicon":"","oncolor":"","offvalue":"1","offvalueType":"num","officon":"","offcolor":"","x":1030,"y":280,"wires":[["db287e03.9c9d5"]]},{"id":"d7a9a518.97d5e8","type":"ui_switch","z":"66efa7f8.f43b48","name":"","label":"Side Valve","tooltip":"","group":"c1cdc8de.1ea148","order":10,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"0","onvalueType":"str","onicon":"","oncolor":"","offvalue":"1","offvalueType":"str","officon":"","offcolor":"","x":1050,"y":200,"wires":[["d3a54be.bc9e9b8"]]},{"id":"d3a54be.bc9e9b8","type":"rpi-gpio out","z":"66efa7f8.f43b48","name":"","pin":"38","set":"","level":"0","freq":"","out":"out","x":1220,"y":200,"wires":[]},{"id":"db287e03.9c9d5","type":"rpi-gpio out","z":"66efa7f8.f43b48","name":"","pin":"40","set":"","level":"0","freq":"","out":"out","x":1220,"y":280,"wires":[]},{"id":"95796087.40c8a","type":"debug","z":"66efa7f8.f43b48","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1130,"y":100,"wires":[]},{"id":"7b87346c.30948c","type":"trigger","z":"66efa7f8.f43b48","op1":"","op2":"1","op1type":"nul","op2type":"str","duration":"5","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":760,"y":80,"wires":[["95796087.40c8a","d7a9a518.97d5e8"]]},{"id":"f13266f9.ba79b8","type":"ui_group","z":"","name":"Bottom Hopper","tab":"e6123a00.bae988","order":3,"disp":true,"width":"6","collapse":false},{"id":"4d850d89.ed6994","type":"serial-port","z":"","serialport":"/dev/ttyACM0","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","waitfor":"","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"},{"id":"c1cdc8de.1ea148","type":"ui_group","z":"","name":"Misc","tab":"e6123a00.bae988","order":1,"disp":true,"width":"6","collapse":false},{"id":"e6123a00.bae988","type":"ui_tab","z":"","name":"Silent Roar","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

I warn you this isn't pretty, as I said a newbie. will accept any suggestions LOL

step 1 would be to edit your post to surround the code by 3 backticks ` before and after to make it importable

appreciate your patience :wink:

Also I have edited my last post

export it again (editing an existing post won't always work).

three backticks `

code

three backticks `

i managed to import it.

What kind of data comes from the serial ?
Do you have some dummy data available ?

All that is coming from the serial is weight from scales.
Every second 0.00 is the payload.

Sorry is that enough information?