Switch Node - Wrong Output Problem

Hello,

I am facing a problem with a switch node, which takes wrong input and outputs something wrong as well. The problem is caused by the trigger because when it gets activated for the first time it then doesn't reset so that's what I am trying to find. Is there any way to make it reset when the second output's function is finished?

Thanks for your time, appreciate your help!

In the following image, output 1 of switch is activated but function "Fire" of output 2 is still decreasing the number. That's what I am trying to avoid.
image

[{"id":"a22d2372.a6411","type":"function","z":"6306a6a6.84f1b8","name":"Fire ","func":"\nvar counter = flow.get('counter')\nmsg.payload = counter; \nif(counter<20)\n{\n   return 0;\n}\nelse\n{\ncounter=counter-1;\n}\nflow.set(\"counter\",counter);\nreturn msg; ","outputs":1,"noerr":0,"initialize":"","finalize":"","x":970,"y":260,"wires":[["13b9dd5b.05fa73"]]}]

I found a solution and I would like to show it !

[{"id":"3a3cc25a.14183e","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"74fd26b6.b14468","type":"function","z":"3a3cc25a.14183e","name":"Data Generation","func":"flow.set(\"counter\", 20);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":340,"y":100,"wires":[["c3041f59.7568b"]],"info":"Ορίζεται μία μεταβλητή counter η οποία έχει αριθμητική ακέραια τυχαία τιμή από 20 έως 60 και προσομειώνει την τιμή της θερμοκρασίας. Είναι flow διότι χρειάζεται να υπάρχει πρόσβαση σε αυτή και από άλλους κόμβους και στο τέλος επιστρέφεται ως msg. "},{"id":"2cc5af72.77e9d","type":"inject","z":"3a3cc25a.14183e","name":"Temperature Sensor","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":130,"y":100,"wires":[["74fd26b6.b14468"]],"info":"Μόλις ο κόμβος \"Inject\" ενεργοποιηθεί, λαμβάνεται μία μέτρηση κάθε ένα λεπτό."},{"id":"4ffcbf9e.49c86","type":"ui_gauge","z":"3a3cc25a.14183e","name":"Temperature Adjustment","group":"2d70c600.e2d54a","order":6,"width":0,"height":0,"gtype":"gage","title":"Temperature","label":"Celsius","format":"{{value}}","min":"0","max":"20","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1010,"y":160,"wires":[]},{"id":"3521b71d.5019e8","type":"function","z":"3a3cc25a.14183e","name":"Fire ","func":"//Στις παρακάτω εντολές γίνεται μία προσομοίωση εξασθένησης της \n//πυρκαγιάς που είναι ενεργή στο χώρο του θεάτρου. Η τιμή της \n//μεταβλητής counter υποδηλώνει τη θερμοκρασία και αν αυτή είναι \n//μικρότερη του 20 αυτό σημαίνει ότι το σύστημα ψεκασμού είχε ήδη\n//ενεργοποιηθεί και έχει σβήσει. Αν όχι, τότε μειώνεται κάθε φορά \n//ενδεικτικά κατά 1, εφόσον ταυτόχρονα λειτουργεί και το σύστημα \n//ψεκασμού που είναι ένας κόμβος switch. Με τη μείωση της \n//υποδηλώνεται ότι η πυρκαγιά εξασθενεί.\nvar counter = flow.get('counter')\nmsg.payload = counter; \nif(counter<0)\n{\n   return 0;\n}\nelse\n{\ncounter=counter-1;\n}\nflow.set(\"counter\",counter);\nreturn msg; ","outputs":1,"noerr":0,"initialize":"","finalize":"","x":770,"y":120,"wires":[["4ffcbf9e.49c86","21ea5e6e.5a46f2","f49fc8f7.dd15a8"]]},{"id":"21ea5e6e.5a46f2","type":"switch","z":"3a3cc25a.14183e","name":"Reset Switch","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":570,"y":220,"wires":[["4e724087.6c654"]]},{"id":"4e724087.6c654","type":"function","z":"3a3cc25a.14183e","name":"Reset Function","func":"msg.payload=0;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":580,"y":160,"wires":[["c3041f59.7568b"]]},{"id":"c3041f59.7568b","type":"trigger","z":"3a3cc25a.14183e","name":"Trigger","op1":"counter","op2":"counter-1","op1type":"flow","op2type":"flow","duration":"-1","extend":false,"overrideDelay":false,"units":"s","reset":"0","bytopic":"all","topic":"topic","outputs":1,"x":560,"y":100,"wires":[["3521b71d.5019e8"]],"info":"Με τον κόμβο trigger γίνεται η υπόθεση ότι κάθε 1 δευτερόλεπτο μειώνεται η υψηλή θερμοκρασία που είναι αποτέλεσμα της πυρκαγιάς, κατά 1 βαθμό κελσίου."},{"id":"f49fc8f7.dd15a8","type":"debug","z":"3a3cc25a.14183e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":950,"y":100,"wires":[]},{"id":"2d70c600.e2d54a","type":"ui_group","name":"Monitoring","tab":"c0a2130d.da022","order":1,"disp":true,"width":"6","collapse":false},{"id":"c0a2130d.da022","type":"ui_tab","name":"Alarm","icon":"dashboard","disabled":false,"hidden":false}]

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