10. Adding Logic to Switch Node
In order to add logic into our switch node, we will add an inject node, one switch function node, and two change nodes. This will allow us to change the text displayed when the light is ON or OFF.
Connect each one of these nodes as follows
Double-click the switch function node and add the following condition
Click Done once completed
Next, double-click the top change (1) node, as shown in the image above, and add the following condition
Click Done once completed
Next, double-click the bottom change (2) node, as shown in the image above, and add the following condition
Click Done once completed
Next, double-click the inject node, set the payload to be a boolean with its value set to false.
This will turn the switch off whenever the inject node is pressed within the Node-Red Canvas.
Next, we connect all the nodes as follows
Click Deploy and go to your Dashboard to view your progress
Last modified 1yr ago
Copy link