Getting payload data from function to two debug nodes


I am trying to get data from two nodes to debug nodes, by a function.
If I add a debug node to the two nodes (zigbee nodes) I get this data.

I am then trying to get the payload data by a function and if the:
contact is "false" then it need to send the payload data to one debug node
occupancy is "true" it need to send the payload data to another debug node

But I get no data from the function.

My function code is (on message):

var contact =;
var occupancy = msg.payload.occupancy;

if (contact == "false"){
    return [msg,null];  
if (occupancy == "true"){
    return [msg,null];    

contact is boolean not a string.

so this should work.

if (contact == false){
    return [msg,null];  

NOTE: you could use a simple switch node to do this.

Hi @Steve-Mcl THX.
"the needle in the haystack"

I started with a switch node... but how can i get the switch node to look on both;
and msg.payload.occupancy?

You can use 2 switch nodes
sw1 - contact == false OR otherwise
sw2 - occupancy == true or otherwise

or you can do it with e switch node and a JSONata expression

expression: = false ? 1 : (payload.occupancy = true ? 2 : 0)

but, the function node is sometimes the best solution.

Ok thx.

...the function node is sometimes the best solution.
Ok atm. it use the same output (top) to one debug node, for contact and occupancy, the occupancy is not using the other debug node.. hmm

because the 2nd return needs a different signature...

if (occupancy == true){
    //return [msg, null];   //<< output to pin 1
    return [null, msg];     //<< output to pin 2
1 Like

Doesn't this work in a switch node.


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