# Node Red Ignore Switch

**URL:** https://discourse.nodered.org/t/node-red-ignore-switch/61009
**Category:** General
**Created:** [8 April 2022 21:06 UTC](https://discourse.nodered.org/t/node-red-ignore-switch/61009 "2022-04-08T21:06:07Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![David.Hammer00](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@David.Hammer00](https://discourse.nodered.org/u/David.Hammer00)
#### Post date: [8 April 2022 21:06 UTC](https://discourse.nodered.org/t/node-red-ignore-switch/61009/1 "2022-04-08T21:06:07Z")

</div>

Hey,

If the two switches are off and then I trigger one of the injectors, the function behind it is still executed, but why?

![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/b/8b78f3d20c0ac960e85aa82d264f8aa1f288d173.png)

![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/2/f2c6aac2262712eadc9d28365a955f133a12bef2.png)

Why is this still happening?

Thanks in advance

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [8 April 2022 21:48 UTC](https://discourse.nodered.org/t/node-red-ignore-switch/61009/2 "2022-04-08T21:48:19Z")

</div>

It's still happening because you misunderstand the role of a ui-switch.

For a node which either blocks messages or lets them through, try [node-red-contrib-simple-gate](https://flows.nodered.org/node/node-red-contrib-simple-gate)

---

<div class="post-metadata">

### Author: ![David.Hammer00](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@David.Hammer00](https://discourse.nodered.org/u/David.Hammer00)
#### Post date: [9 April 2022 06:51 UTC](https://discourse.nodered.org/t/node-red-ignore-switch/61009/3 "2022-04-09T06:51:49Z")

</div>

Thank you.  
I thought the switch blocks messages.  
I put a function behind the Switch with this code:

> if(msg.payload == true)  
> {  
> return msg;  
> }

Now its working

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [9 April 2022 08:21 UTC](https://discourse.nodered.org/t/node-red-ignore-switch/61009/4 "2022-04-09T08:21:35Z")

</div>

I'm glad you have fixed it.

At the risk of confusing you, there is also a Switch node (not UI) which can very easily discard or divert messages based on their payload.

It's probably a mistake to jump too quickly into writing functions rather than using the available nodes.

---

<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: [8 June 2022 08:22 UTC](https://discourse.nodered.org/t/node-red-ignore-switch/61009/5 "2022-06-08T08:22:07Z")

</div>

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