If condition with a function

in a function it would be something like this and you would need to attach it to the output of the home/away presence node:

const isNight = global.get(“isNight”);
if(msg.payload === “home” && isNight === true){
    msg.payload = “got home and its night”;
    return msg;
} else {
    return null;
}

not tested

Perfect!

I can manage do that with the switch node instead.

1 Like

respected sir, i request to help me out..
i am making pulse read sensor so for that i run python code and send data to node red. in that i had used (function node) with code

msg.payload=msg.payload.Pulse
return msg;

reading is showing no problem but sir now i want to make another 2nd function node such that whenever the value exceeded 100 then condition is matched and give true message to (switch node) which is connected to 2nd function node.so sir what code should i wright in 2nd function code.
path name of sanser value coming is payload.
thankyou

1 - how are you sending the data to NR?
2 - is

msg.payload=msg.payload.Pulse
return msg;

the only code in the 'function' node? if so, you could use a change node instead:
Screen Shot 2020-06-13 at 4.36.25 AM
3 - you say

now i want to make another 2nd function node such that whenever the value exceeded 100 then condition is matched
why not use a switch node for this?

1- sir through ibm cloud.
2- yes sir
msg.payload=msg.payload.Pulse
return msg;
these same code i am running in my 1st function node named (pulse rate)
3- but sir before using switch node i thought comparison of pulse values must be there with the help of 1st and 2nd function node.Then 2nd function node will be connected with switch node which will connect the further node only when condition is fulfilled. for this i use 1:- value rules as (is true) in switch node..
however i want what you think sir
thankyou

Ok, now you have confused me. Are you saying you have two (2) inputs and you need to compare their values?

Please provide a flow diagram explaining what you need to do.

Hi sir, its true that i'm very late to reply. i'm sorry for that. it's about the project that i had to do and due to less time i had submitted with another way.
thank you 'Zenofmud' for helping us out!