I have two switches connected to a function node. I want this node to send a true signal once both switches are sending "true" to the function block. Otherwise I don't want the function node to do anything. What would the code look like?
See this article in the cookbook for an example of how to join messages into one object.
Once you have both values in the message, you can check both to see if they are true.
e.g.
if (msg.payload.sw1 == true && msg.payload.sw2 == true) {
return msg; //pass message on to next node
}
return null;//dont pass message
The code didn't work and cookbook guides are too advanced for me at this point in time.
I think I need to change msg.topic, so I'm assuming sw1 and sw2 are the topics. How do I changed msg.topic? Do I simply remove "topic" and put sw1 or sw2 in its place?
If you save & update each switch-state in context variables, you can always make the comparison when a message arrives (if you dont keep that statuses saved you do not know the state of the other switch when a message arrives, unless you as @Steve-Mcl mentioned, combine them into a single message)
In which case ...
I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.
This is great, thank you!
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.