# How to block everything that is not needed?

**URL:** <https://discourse.nodered.org/t/how-to-block-everything-that-is-not-needed/35058>\
**Category:** General\
**Created:** [30 October 2020 07:26 UTC](https://discourse.nodered.org/t/how-to-block-everything-that-is-not-needed/35058 "2020-10-30T07:26:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zerg](https://avatars.discourse-cdn.com/v4/letter/z/6de8d8/32.png) [@Zerg](https://discourse.nodered.org/u/Zerg)\
**Post date:** [30 October 2020 07:26 UTC](https://discourse.nodered.org/t/how-to-block-everything-that-is-not-needed/35058/1 "2020-10-30T07:26:54Z")

</div>

I need to "function" node to send information only what i wrote in code and nothing else!  
How to block everything else that "flies" through it after the node "mqtt"?

The code that I need to send!

```auto
var button_corridor = flow.get('button_corridor') || ""; //Что бы отслеживалось состояние кнопки.

if (button_corridor === "ON") { // Включаем возможность изменения яркости!
    msg.enabled = true;
    return msg;
} 
else if (msg.payload === "Off"){
    msg.enabled = false;
    msg.brightness = null;
    return msg;
}
else {
    msg.brightness = null;
    return null;
}

```

And this is the message that he passes through himself every time!

```auto
{"brightness":152,"color_temp":375,"linkquality":65,"state":"ON","update_available":true}

```

 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/f/df07a4e02c79fad2e80c4837d81f09d3fa98e112.png)

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [30 October 2020 07:43 UTC](https://discourse.nodered.org/t/how-to-block-everything-that-is-not-needed/35058/2 "2020-10-30T07:43:47Z")

</div>

Use a switch node , and configure it to pass trought only the string/ value you want...

---

<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:** [30 October 2020 07:44 UTC](https://discourse.nodered.org/t/how-to-block-everything-that-is-not-needed/35058/3 "2020-10-30T07:44:02Z")

</div>

At beginning of code set `msg = {};` That will set whole message to an empty object. This will affect msg.payload, so if you need it in your if statement, set `var hold = msg;` before you overwrite msg. Then use `if(hold.payload = ...` in your if statement.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [30 October 2020 09:39 UTC](https://discourse.nodered.org/t/how-to-block-everything-that-is-not-needed/35058/4 "2020-10-30T09:39:43Z")

</div>

You could just create a new msg object...  
See - [Easy way of adding only mytimes to a msg](https://discourse.nodered.org/t/easy-way-of-adding-only-mytimes-to-a-msg/28683/10) as an example.  
(Similar to what @E1cid suggested)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 October 2020 11:02 UTC](https://discourse.nodered.org/t/how-to-block-everything-that-is-not-needed/35058/5 "2020-10-30T11:02:37Z")

</div>

> [@Zerg](#):
>
> And this is the message that he passes through himself every time!

No, that isn't the message, that is what is in msg.payload, because that is what you have configured the debug node to show. If you set the debug node to Show Full Message then you will see that msg.enabled and msg.brightness (which is not the same as msg.payload.brightness) should have been set as your code dictates. Perhaps you meant  
`msg.payload = {enabled: true}`  
and  
`msg.payload = {enabled: false, brightness: null}`  
If you don't understand then have a look at the node-red docs page Working with Messages which should help.

---

<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:** [13 November 2020 11:02 UTC](https://discourse.nodered.org/t/how-to-block-everything-that-is-not-needed/35058/6 "2020-11-13T11:02:39Z")

</div>

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