# Node-Red switch logic not working

**URL:** <https://discourse.nodered.org/t/node-red-switch-logic-not-working/64956>\
**Category:** General\
**Created:** [11 July 2022 16:33 UTC](https://discourse.nodered.org/t/node-red-switch-logic-not-working/64956 "2022-07-11T16:33:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![yxqzme2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yxqzme2/32/64462_2.png) [@yxqzme2](https://discourse.nodered.org/u/yxqzme2)\
**Post date:** [11 July 2022 16:33 UTC](https://discourse.nodered.org/t/node-red-switch-logic-not-working/64956/1 "2022-07-11T16:33:51Z")

</div>

I am trying to do a simple holiday lights automation using binary sensors, but I do not seem to be getting the right output from the switch.

I have the 6 holidays input to the switch. If I make it a holiday, I get the correct output, but I have a seventh input (non-holiday) that it should choose if none of the holidays are happening.

By all the reading I have done, if I choose "stopping after first match" and put the seventh leg at the bottom I should be good, but it always outputs the chosen holiday AND the non-holiday input.

Is there something else I am supposed to do?  
I have also tried "Otherwise" under the sequence rules with no output at all.

 ![switch2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/9/296b9dee0a1a0cccd9cb7f36110bbe1c15406e29.png)

 ![switch](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/8/c852872f21ba012e99582e2ad2c5b7ead124e84f.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [11 July 2022 16:38 UTC](https://discourse.nodered.org/t/node-red-switch-logic-not-working/64956/2 "2022-07-11T16:38:04Z")

</div>

> [@yxqzme2](#):
>
> but it always outputs the chosen holiday AND the non-holiday input.

Because messages ALWAYS arrive from different wires at different times.

In other words, each `msg` going IN to the switch contains its own `payload`.

1. st patricks day goes to switch as `{payload: "STP"}` - so comes out of pin 3
2. other day goes to switch as `{payload: "OTHER"}` - so comes out of pin 7

---

<div class="post-metadata">

**Author:** ![yxqzme2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yxqzme2/32/64462_2.png) [@yxqzme2](https://discourse.nodered.org/u/yxqzme2)\
**Post date:** [11 July 2022 17:02 UTC](https://discourse.nodered.org/t/node-red-switch-logic-not-working/64956/3 "2022-07-11T17:02:57Z")

</div>

Thanks @Steve-Mcl, your thoughts on what i should change to get the desired output?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [11 July 2022 17:35 UTC](https://discourse.nodered.org/t/node-red-switch-logic-not-working/64956/4 "2022-07-11T17:35:53Z")

</div>

You may need to join the messages as an array , with a join node and a timeout, and possible use contains option in the switch node.

or

Rather than use "OTHER" there is an option for otherwise, click chevron next to equals, Also have you selected "Stop after first match" at the bottom of the switch config. You would then remove the HA node for "OTHER" as you would use otherwise if no match.

So if no match it would go to otherwise.

---

<div class="post-metadata">

**Author:** ![yxqzme2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yxqzme2/32/64462_2.png) [@yxqzme2](https://discourse.nodered.org/u/yxqzme2)\
**Post date:** [11 July 2022 18:28 UTC](https://discourse.nodered.org/t/node-red-switch-logic-not-working/64956/5 "2022-07-11T18:28:20Z")

</div>

Thank you very much @E1cid, I did figure this out with the info below.  
I know its probably crude, but with my testing, it works.

 ![Screenshot 2022-07-11 142829](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/0/e06110dd960cbbecc2ee781e63da932cf3d6e4ec.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [11 July 2022 18:45 UTC](https://discourse.nodered.org/t/node-red-switch-logic-not-working/64956/6 "2022-07-11T18:45:27Z")

</div>

I may be wrong, is the switch node even required in that flow?

---

<div class="post-metadata">

**Author:** ![yxqzme2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yxqzme2/32/64462_2.png) [@yxqzme2](https://discourse.nodered.org/u/yxqzme2)\
**Post date:** [11 July 2022 18:58 UTC](https://discourse.nodered.org/t/node-red-switch-logic-not-working/64956/7 "2022-07-11T18:58:54Z")

</div>

Thank you again. you are correct, and not only did I just learn something, but that made it much cleaner.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [9 September 2022 18:59 UTC](https://discourse.nodered.org/t/node-red-switch-logic-not-working/64956/8 "2022-09-09T18:59:06Z")

</div>

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