Can I return a real null value to a multi out function from an else if statement?

The way it is now, if it returns null, it will fire a null message. I'd like it to not fire at all.

This works as is, problem was from bad formatting further up in my code. msg2 = null

let msg2 = {};
if (phoneState === "offhook") {
    msg2 = null;
} else if (ivsRule === "ivs"){
    msg2.payload = ((cameraName.toLowerCase()).replace(/xvr /, "")).replace(/ floor/, "");
} else {
    msg2.payload = ivsRule;
};


return [ msg1, msg2 ];

Another problem I am having is trying to use an or statement like so but it seems to let everything pass.

(evco === "CrossRegionDetection" && action === "Start" && ivsRule === "first" || "second" || "third")

If what returns null?

Which output both output 1 and output 2?

To not send anything, return null

I'm not sure I get what you mean by that.

If phoneState === "offhook" you get no output on the second output of the node.

What do you mean by a real null in the title?

null means nothing is sent.

You may be confused with the terms. (Not sure).
Just asking.

An empty object with just a message id

if I use [ msg1, null ] there is no output. Hard coded.

Ok, so in your code:

Line 3.

msg2 = null;

Try msg2.payload = "";

See if that does what you want.

Sorry, I am only guessing at what you want.
Please don't get upset. I know sometimes it is hard to explain things in the exact words others understand.
Not sure if it is msg2.payload or just msg2.

1 Like

If you are looking (on output 2) for a certain message to identify the phone is offhook, you could do it a different way:

let msg2 = {};
if (phoneState === "offhook") {
    msg2.payload = "offhook";
} else if (ivsRule === "ivs"){
    msg2.payload = ((cameraName.toLowerCase()).replace(/xvr /, "")).replace(/ floor/, "");
} else {
    msg2.payload = ivsRule;
};


return [ msg1, msg2 ];

then in the next node connected to output 2, look for the message offhook and act on that.

Again, just offering ideas.

No worries, I've been on forums for a long time. Sending "" Worked as expected with no message. That is a tts output to my phone. I don't want it to go off if I'm on the phone.

I appreciate your help.

Hey, no worries.

Sorry I couldn't help you more, but maybe I have helped you understand it a bit more.
And that would be a good thing.

All the best.

1 Like

If that one with the msg2.payload = "" worked, mark it as the solution.

That helps others with this problem see the answer.

Does clicking solution close the thread on this forum? I just want to leave it open to possibly get an answer to my other question without making a new post.

Oh. Yes it would solve it.

But if there is still a question, by all means leave it open.

But it may help if you explain it a bit more, as I thought the question was answered.

It may be better if you post a new thread, as a thread with 2 questions in it is a bit confusing.
(Just saying.)

This question.

Well, while we are here... :wink:

(evco === "CrossRegionDetection" && action === "Start" && ivsRule === "first" || "second" || "third")

How about you explain to me - as I am not understanding it - what you want to do?

To me the structure looks ..... wrong somehow.

Should be

if (evco === "CrossRegionDetection" && action === "Start" && (ivsRule === "first" || ivsRule === "second" || ivsRule ==="third") )
2 Likes

Thanks @Steve-Mcl

Yeah, the ( ) around it were throwing me.

I could see something but couldn't quite put my finger on it.

It is, it's just a snippet. That snippet returns true even if some of the string variables don't match. When I break them up they work.

let msg1 = {};
if (evco === "CrossRegionDetection" && action === "Start" && ivsRule === "ivs") {msg1.payload = {
    domain: "camera",
    service: "snapshot",
    data: {
        "entity_id": cameraEntity,
    },
    topic: 'single',
    title: cameraName,
};
} else if (evco === "CrossRegionDetection" && action === "Start" && ivsRule === "first" ) {msg1.payload = {
    domain: "camera",
    service: "snapshot",
    data: {
        "entity_id": cameraEntity,
    },
    topic: 'multi',
    title: ivsRule,
};
} else if (evco === "CrossRegionDetection" && action === "Start" && ivsRule === "basement") {msg1.payload = {
    domain: "camera",
    service: "snapshot",
    data: {
        "entity_id": cameraEntity,
    },
    topic: 'multi',
    title: ivsRule,
};
} else if (evco === "CrossRegionDetection" && action === "Start" && ivsRule === "alley") {msg1.payload = {
    domain: "camera",
    service: "snapshot",
    data: {
        "entity_id": cameraEntity,
    },
    topic: 'multi',
    title: ivsRule,
};
} else if (evco === "CrossRegionDetection" && action === "Start" && ivsRule === "garden") {msg1.payload = {
    domain: "camera",
    service: "snapshot",
    data: {
        "entity_id": cameraEntity,
    },
    topic: 'multi',
    title: ivsRule,
};
} else if (evco === "VideoMotion" && action === "Start") {msg1.payload = {
    domain: "camera",
    service: "snapshot",
    data: {
        "entity_id": cameraEntity,
    },
    topic: 'motion',
    title: cameraName,
};
} else {
    ""
};

Sorry, but that post helps a lot in the context of what you are trying to do.

The first bit did leave some critical details out.

That is probably above my head.
I'll look at it, but no promises on this part.

1 Like

Ok, maybe petty, but.....

msg1.payload = {domain: "camera", service: "snapshot", data: {"entity_id": cameraEntity},
    topic: 'single',
    title: cameraName,};
}

All parts should be in ".

So it should be:

msg1.payload = {"domain": "camera"," service": "snapshot", "data": {"entity_id": cameraEntity},
    "topic": 'single',
    "title": cameraName,};
}

That won't fix the problem, but if I remember correctly that is how it should be.

And:
Not sure on how it would change things:
At the end of each test: return msg1;

That may help, but I'm not sure.

And!

Just noticedL
data: {"entity_id": cameraEntity,} is wrong.

Extra , in there after Entity
Yes?

And an extra , at the end of most of the lines too.....

Or it seems to me to be extraneous.

1 Like

Yeah I just saw a lot of errors and mix ups between msg1 and msg1.payload. I don't know how anything was even going through. Let me clean everything up. The comma was extra.