# How to select one msg.payload out of 4 recieved

**URL:** <https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355>\
**Category:** General\
**Created:** [15 June 2020 11:18 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355 "2020-06-15T11:18:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![anthony\_dob](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anthony_dob/32/23958_2.png) [@anthony\_dob](https://discourse.nodered.org/u/anthony_dob)\
**Post date:** [15 June 2020 11:18 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/1 "2020-06-15T11:18:56Z")

</div>

Hello,

Im working on a IoT project where i want to control 8 leds and 4 button states from my Nucleo. The goal is to see each button state seperately on my phone. For this i have a MQTT topic for each button. The problem i have is the following. I recieve all 4 button states in seperated msg.payloads (on/off) in node-red each 10 seconds with a COM node. I would need a function between my COM that recieves all 4 states and MQTT out that only selects the button state i need for that MQTT out topic. I basically need to filter the 4 msg.payloads with a function to send 1 msg.payload with the correct button state. Anyone who can help me?

This is my flow:

```auto
[{"id":"4d2d5268.e0844c","type":"serial in","z":"66429bb6.5913e4","name":"COM4","serial":"29049e1d.8eec82","x":1010,"y":80,"wires":[["548b250a.8feeec"]]},{"id":"41e3896c.4ea1a8","type":"mqtt out","z":"66429bb6.5913e4","name":"","topic":"VIVES/IOT/AD/SW1","qos":"","retain":"","broker":"54ccd74f.37d7a8","x":1400,"y":80,"wires":[]},{"id":"bce00e61.94e56","type":"mqtt in","z":"66429bb6.5913e4","name":"","topic":"VIVES/IOT/AD/LED1","qos":"2","datatype":"auto","broker":"54ccd74f.37d7a8","x":380,"y":60,"wires":[["582631eb.23449","bbf63d0d.dc7a2"]]},{"id":"582631eb.23449","type":"serial out","z":"66429bb6.5913e4","name":"","serial":"29049e1d.8eec82","x":590,"y":60,"wires":[]},{"id":"bbf63d0d.dc7a2","type":"debug","z":"66429bb6.5913e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":610,"y":100,"wires":[]},{"id":"691648a4.4a4a98","type":"debug","z":"66429bb6.5913e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":200,"wires":[]},{"id":"26c89c18.030204","type":"serial out","z":"66429bb6.5913e4","name":"","serial":"29049e1d.8eec82","x":590,"y":160,"wires":[]},{"id":"6945cff.14bdf3","type":"mqtt in","z":"66429bb6.5913e4","name":"","topic":"VIVES/IOT/AD/LED2","qos":"2","datatype":"auto","broker":"54ccd74f.37d7a8","x":380,"y":160,"wires":[["26c89c18.030204","691648a4.4a4a98"]]},{"id":"bf07402f.aa258","type":"mqtt in","z":"66429bb6.5913e4","name":"","topic":"VIVES/IOT/AD/LED3","qos":"2","datatype":"auto","broker":"54ccd74f.37d7a8","x":380,"y":260,"wires":[["923b0883.a68598","8baced00.f390e"]]},{"id":"595a4df.e3bb2b4","type":"mqtt in","z":"66429bb6.5913e4","name":"","topic":"VIVES/IOT/AD/LED4","qos":"2","datatype":"auto","broker":"54ccd74f.37d7a8","x":380,"y":360,"wires":[["f2c64952.b897e8","9438efc7.8e79e"]]},{"id":"52d0aaa2.4f07b4","type":"mqtt in","z":"66429bb6.5913e4","name":"","topic":"VIVES/IOT/AD/LED5","qos":"2","datatype":"auto","broker":"54ccd74f.37d7a8","x":380,"y":460,"wires":[["eadbd314.62693","b497de43.1e8a7"]]},{"id":"4242d02e.cd241","type":"mqtt in","z":"66429bb6.5913e4","name":"","topic":"VIVES/IOT/AD/LED6","qos":"2","datatype":"auto","broker":"54ccd74f.37d7a8","x":380,"y":560,"wires":[["8f177d2e.86bf3","4eac1148.33fe4"]]},{"id":"1a0fc216.2151be","type":"mqtt in","z":"66429bb6.5913e4","name":"","topic":"VIVES/IOT/AD/LED7","qos":"2","datatype":"auto","broker":"54ccd74f.37d7a8","x":380,"y":660,"wires":[["dfd7889f.ebf828","cf257fb1.17ee"]]},{"id":"c9a8c324.0251b","type":"mqtt in","z":"66429bb6.5913e4","name":"","topic":"VIVES/IOT/AD/LED8","qos":"2","datatype":"auto","broker":"54ccd74f.37d7a8","x":380,"y":760,"wires":[["d444fe89.8b73d","8fa1d13.dd6c03"]]},{"id":"923b0883.a68598","type":"serial out","z":"66429bb6.5913e4","name":"","serial":"29049e1d.8eec82","x":590,"y":260,"wires":[]},{"id":"f2c64952.b897e8","type":"serial out","z":"66429bb6.5913e4","name":"","serial":"29049e1d.8eec82","x":590,"y":360,"wires":[]},{"id":"eadbd314.62693","type":"serial out","z":"66429bb6.5913e4","name":"","serial":"29049e1d.8eec82","x":590,"y":460,"wires":[]},{"id":"8f177d2e.86bf3","type":"serial out","z":"66429bb6.5913e4","name":"","serial":"29049e1d.8eec82","x":590,"y":560,"wires":[]},{"id":"dfd7889f.ebf828","type":"serial out","z":"66429bb6.5913e4","name":"","serial":"29049e1d.8eec82","x":590,"y":660,"wires":[]},{"id":"d444fe89.8b73d","type":"serial out","z":"66429bb6.5913e4","name":"","serial":"29049e1d.8eec82","x":590,"y":760,"wires":[]},{"id":"8baced00.f390e","type":"debug","z":"66429bb6.5913e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":300,"wires":[]},{"id":"9438efc7.8e79e","type":"debug","z":"66429bb6.5913e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":400,"wires":[]},{"id":"b497de43.1e8a7","type":"debug","z":"66429bb6.5913e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":500,"wires":[]},{"id":"4eac1148.33fe4","type":"debug","z":"66429bb6.5913e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":600,"wires":[]},{"id":"cf257fb1.17ee","type":"debug","z":"66429bb6.5913e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":700,"wires":[]},{"id":"8fa1d13.dd6c03","type":"debug","z":"66429bb6.5913e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":800,"wires":[]},{"id":"548b250a.8feeec","type":"function","z":"66429bb6.5913e4","name":"","func":"\nreturn msg;","outputs":1,"noerr":0,"x":1190,"y":80,"wires":[["41e3896c.4ea1a8","8d779a1.7601968"]]},{"id":"8d779a1.7601968","type":"debug","z":"66429bb6.5913e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1370,"y":120,"wires":[]},{"id":"1da226ef.a4fca9","type":"serial in","z":"66429bb6.5913e4","name":"","serial":"29049e1d.8eec82","x":1010,"y":180,"wires":[["4ec320d0.9dd6b"]]},{"id":"49d040e9.9b4e2","type":"serial in","z":"66429bb6.5913e4","name":"","serial":"29049e1d.8eec82","x":1010,"y":260,"wires":[["1f343890.9ab327"]]},{"id":"e2d342ed.53ee5","type":"serial in","z":"66429bb6.5913e4","name":"","serial":"29049e1d.8eec82","x":1010,"y":340,"wires":[["9208904b.6ea12"]]},{"id":"4ec320d0.9dd6b","type":"function","z":"66429bb6.5913e4","name":"","func":"\nreturn msg;","outputs":1,"noerr":0,"x":1180,"y":180,"wires":[["76e64a99.2dda64"]]},{"id":"1f343890.9ab327","type":"function","z":"66429bb6.5913e4","name":"","func":"\nreturn msg;","outputs":1,"noerr":0,"x":1190,"y":260,"wires":[["7b177b40.788f84"]]},{"id":"9208904b.6ea12","type":"function","z":"66429bb6.5913e4","name":"","func":"\nreturn msg;","outputs":1,"noerr":0,"x":1190,"y":340,"wires":[["d326bbbd.dbf338"]]},{"id":"76e64a99.2dda64","type":"mqtt out","z":"66429bb6.5913e4","name":"","topic":"VIVES/IOT/AD/SW2","qos":"","retain":"","broker":"54ccd74f.37d7a8","x":1400,"y":180,"wires":[]},{"id":"7b177b40.788f84","type":"mqtt out","z":"66429bb6.5913e4","name":"","topic":"VIVES/IOT/AD/SW3","qos":"","retain":"","broker":"54ccd74f.37d7a8","x":1400,"y":260,"wires":[]},{"id":"d326bbbd.dbf338","type":"mqtt out","z":"66429bb6.5913e4","name":"","topic":"VIVES/IOT/AD/SW4","qos":"","retain":"","broker":"54ccd74f.37d7a8","x":1400,"y":340,"wires":[]},{"id":"29049e1d.8eec82","type":"serial-port","z":"","serialport":"COM4","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"},{"id":"54ccd74f.37d7a8","type":"mqtt-broker","z":"","name":"HiveMQ","broker":"tcp://broker.hivemq.com","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

This is what i recieve every 10 seconds: state can be 'button \* is uit' or 'button \* is aan'  
 ![2020-06-15 12_57_32-Node-RED](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/f/1f5e5e8d15c1943d81e331e0ee8b58069c6ae454.png)

The setup i have. I just don't know how to write the function that selects only the msg.payload (button1)  
 ![2020-06-15 13_31_32-Node-RED](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3cbfdc3e21bd1c362e2a227d0c5887938eb16262.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [15 June 2020 11:41 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/2 "2020-06-15T11:41:21Z")

</div>

You lost me.

`MQTT` is the protocol from your machine (_main computer running Node-Red_) to your phone.

It sends messages on the state of the buttons.  
Each button **should** have its own `topic` so when it gets to your phone......

What am I saying!

Easier way.

`MQTT in` node. `topic` set to **a specific** button's topic.  
That goes to the desired indication node.

Repeat 4 times for the 4 buttons and no problem.

I don't know what/where/how this `com` node comes into the scheme.

Small suggestion on the flow:  
Granted you are using it for your needs. _we_ can't simulate (or may even have) the node.

Set up some simulation with `inject` nodes that gives the desired output.

That way people can import the flow and see what is happening.

As it is, I can't. (Nor anyone else I guess.)

Now the LEDs .

Do you mean the node, or a physical LED?  
(Though I guess not many phones have 8 physical LEDs on them)

Or are they on the _other end of the comms link_? (`MQTT`?)

I will try to bash up a flow to do what you want, but until I know better what you want, I would prefer a bit better definition of what you want to do.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [15 June 2020 11:51 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/3 "2020-06-15T11:51:46Z")

</div>

I got bored....

Here is a basic idea of what I am talking:

```auto
[{"id":"1bde9e00.2cbbca","type":"comment","z":"b9924a74.4d98f8","name":"Phone","info":"","x":120,"y":3490,"wires":[]},{"id":"199b1fa.76c636","type":"comment","z":"b9924a74.4d98f8","name":"Computer","info":"","x":540,"y":3490,"wires":[]},{"id":"4d9e86f6.cedc7","type":"comment","z":"b9924a74.4d98f8","name":"Phone","info":"","x":840,"y":3490,"wires":[]},{"id":"a13d71bc.75cb5","type":"inject","z":"b9924a74.4d98f8","name":"Button 1","topic":"","payload":"Button 1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":3560,"wires":[["65b44057.d8c938"]]},{"id":"65b44057.d8c938","type":"mqtt out","z":"b9924a74.4d98f8","name":"","topic":"Button1","qos":"","retain":"","broker":"378c0403.8cda04","x":260,"y":3560,"wires":[]},{"id":"95f30a24.0a1808","type":"mqtt in","z":"b9924a74.4d98f8","name":"","topic":"Topic1","qos":"2","datatype":"auto","broker":"378c0403.8cda04","x":390,"y":3560,"wires":[["87adc0cb.0ea23"]]},{"id":"e843ca1a.d0efa","type":"mqtt out","z":"b9924a74.4d98f8","name":"","topic":"State1","qos":"","retain":"","broker":"378c0403.8cda04","x":680,"y":3560,"wires":[]},{"id":"7a45093b.a0367","type":"mqtt in","z":"b9924a74.4d98f8","name":"State1","topic":"State1","qos":"2","datatype":"auto","broker":"378c0403.8cda04","x":800,"y":3560,"wires":[["a3e0593e.a412f8"]]},{"id":"87adc0cb.0ea23","type":"function","z":"b9924a74.4d98f8","name":"Do stuff here","func":"\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":3560,"wires":[["e843ca1a.d0efa"]]},{"id":"a3e0593e.a412f8","type":"debug","z":"b9924a74.4d98f8","name":"Indicator 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":940,"y":3560,"wires":[]},{"id":"378c0403.8cda04","type":"mqtt-broker","z":"","name":"MQTT HOST","broker":"192.168.0.99","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

Repeat for all 4 buttons.

How you get 8 LEDs is a mystery to me.

 ![Screenshot from 2020-06-15 21-51-03](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/39eca3db2e442585fa13bd8a0812d687c12feaa4.png)

Sorry I goofed with the `MQTT` names at the button/computer part.  
But if you load the code you will see what I really mean.

---

<div class="post-metadata">

**Author:** ![anthony\_dob](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anthony_dob/32/23958_2.png) [@anthony\_dob](https://discourse.nodered.org/u/anthony_dob)\
**Post date:** [15 June 2020 11:55 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/4 "2020-06-15T11:55:00Z")

</div>

Hello,

i think i wasn't very clear with what i need help with. Im dutch and a noobie with node-red so explaining in a short text is kinda hard.

So basically i have my nucleo connected to my computer. I have 8 leds on my nucleo and 4 buttons wich i want to control with my phone. I do this with the app "Linear MQTT Dashboard".

The leds work just fine. I can control each led with a switch in the app.

The problem i have is, i want to see each button state of my nucleo (pressed/not pressed) on my phone app aswell. For this i need to send each button state to a seperated MQTT topic. As you could see on the picture i manage to send all 4 button states to node-red as a string.

Now i would need a function that filters the 4 strings that i recieve and resend only the string of 1 button to the MQTT out node.

This is what i want the function to do:

```auto
if msg.payload = "button 1 is uit" or "button 1 is aan"
delete all other msg.payloads and only send "button 1 is uit" or "button 1 is aan"
return msg;

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [15 June 2020 12:06 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/5 "2020-06-15T12:06:02Z")

</div>

> [@anthony\_dob](#):
>
> The problem i have is, i want to see each button state of my nucleo (pressed/not pressed) on my phone app aswell. For this i need to send each button state to a seperated MQTT topic. As you could see on the picture i manage to send all 4 button states to node-red as a string.

Are you talking "REAL TIME" or as the buttons get pressed?

Real time is going to be very difficult - but I am only just off my `Learner` plates.

If it is only when things change it is a whole lot easier.

The "pressed/not pressed" is not that important. I'm guessing they are usually not pressed.

Each button sends a `message` and before you send that message (on your phone, I'm guessing) you set a `topic` in the `MQTT` node.

That distinguishes the 4 buttons.

Button 1's messages come through with a `topic` of (for example) `button1_state`  
Button 2 would be `button2_state`  
and so on.

No big deal.

You need to get that working first. Check on the phone if each button has its own topic.  
It isn't any good sending all 4 button states out one `MQTT` node.  
Or if you do, ensure that node isn't setting the `topic` and the `msg.topic` is set before it gets to the `MQTT` node.

We will get to the `function` node later on.

Ok, I see you are sending `uit` and `aan` as the two states. But how you are doing it, you are making it more difficult that it needs to be.

With the `topic` part you can modularise it easier.

Looking at what you posted though, I am a bit confused in the logic.

But I think for now, it may be better we get the reception part working better.

Sorry, it isn't I am trying to tell you exactly what to do. Only you know what you want to do. I am looking at what you are showing me and I am offering **a** solution. One which I hope will help you in more ways than just now, but show you things that will help you in the future.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [15 June 2020 12:12 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/6 "2020-06-15T12:12:47Z")

</div>

So, only to help me get a handle on what is where:

Where are the buttons?  
How are you indicating the state of the buttons on the phone's display? That requires a `dashboard` of some kind. Ok, you said:

> [@anthony\_dob](#):
>
> I do this with the app "Linear MQTT Dashboard".

But I don't know exactly how that works. Though not important, _we_ need to establish what messages you send to it to get the desired results.

> [@anthony\_dob](#):
>
> i want to see each button state of my nucleo (pressed/not pressed) on my phone app aswell.

So I'm guessing that is the other 4 _LEDs_?

Could you explain better the 8 LEDs? All on the phone? Where?

---

<div class="post-metadata">

**Author:** ![anthony\_dob](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anthony_dob/32/23958_2.png) [@anthony\_dob](https://discourse.nodered.org/u/anthony_dob)\
**Post date:** [15 June 2020 12:16 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/7 "2020-06-15T12:16:48Z")

</div>

sorry for the bad explaining.. So i have my nucleo programmed to send the button states every 10 seconds. Not real time only the button states that moment every 10 seconds. It sends this to node-red trough USB. In node-red i pick the state of the buttons up with the COM node wich my nucleo is connected to.. Hope this explains how it is working.

---

<div class="post-metadata">

**Author:** ![anthony\_dob](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anthony_dob/32/23958_2.png) [@anthony\_dob](https://discourse.nodered.org/u/anthony_dob)\
**Post date:** [15 June 2020 12:21 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/8 "2020-06-15T12:21:01Z")

</div>

All leds and buttons are on a extension shield connected on my nucleo. ill show you the code i put in my nucleo. That way you might understand what i am trying to do.

```auto
//UART_Recv_SendINT
#include "mbed.h"
 
Ticker sendStatusUB1;
Ticker sendStatusUB2;
Ticker sendStatusUB3;
Ticker sendStatusUB4;
Serial pc(SERIAL_TX, SERIAL_RX);
DigitalOut led1(A5);
DigitalOut led2(D3);
DigitalOut led3(D4);
DigitalOut led4(D5);
DigitalOut led5(D6);
DigitalOut led6(D7);
DigitalOut led7(D9);
DigitalOut led8(D10);
DigitalIn sw1(A1);
DigitalIn sw2(A2);
DigitalIn sw3(A3);
DigitalIn sw4(A4);
 
void SendMQTTsw1()
{
    if(sw1){pc.printf("button 1 is uit\n");}
    else {pc.printf("button 1 is aan\n");} 
}
void SendMQTTsw2()
{
    if(sw2){pc.printf("button 2 is uit\n");}
    else {pc.printf("button 2 is aan\n");} 
}
void SendMQTTsw3()
{
    if(sw3){pc.printf("button 3 is uit\n");}
    else {pc.printf("button 3 is aan\n");} 
}
void SendMQTTsw4()
{
    if(sw4){pc.printf("button 4 is uit\n");}
    else {pc.printf("button 4 is aan\n");} 
}

int main()
{
    sendStatusUB1.attach(&SendMQTTsw1, 10.0);
    sendStatusUB2.attach(&SendMQTTsw2, 10.0);
    sendStatusUB3.attach(&SendMQTTsw3, 10.0);
    sendStatusUB4.attach(&SendMQTTsw4, 10.0);
    char c;
    while(1)
    {
        if(pc.readable())
        {
            c = pc.getc(); // Read hyperterminal
            if (c == '0') { led1 = 0; }
            if (c == '1') { led1 = 1; }
            if (c == '2') { led2 = 0; }
            if (c == '3') { led2 = 1; }
            if (c == '4') { led3 = 0; }
            if (c == '5') { led3 = 1; }
            if (c == '6') { led4 = 0; }
            if (c == '7') { led4 = 1; }
            if (c == '8') { led5 = 0; }
            if (c == '9') { led5 = 1; }
            if (c == 'a') { led6 = 0; }
            if (c == 'b') { led6 = 1; }
            if (c == 'c') { led7 = 0; }
            if (c == 'd') { led7 = 1; }
            if (c == 'e') { led8 = 0; }
            if (c == 'f') { led8 = 1; }
        }
       
    }
}

```

---

<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:** [15 June 2020 12:26 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/9 "2020-06-15T12:26:55Z")

</div>

Look at the Switch node. In there you can tell it to see if msg.payload Contains "button 1" and send it to output 1, if it contains "button 2" then send it to output 2 and so on. That will split it into four separate paths so you can then decide what you want to do with each one.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [15 June 2020 12:27 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/10 "2020-06-15T12:27:50Z")

</div>

> [@anthony\_dob](#):
>
> sorry for the bad explaining..

Don't worry. I failed English.

Ok, we are moving in the right direction.

That last post is great!

It means you can edit what is sent.

The messages though don't look quite right.

I can only see the code for the first button. But I'll read around that.

The _plan_:  
You `{pc.printf("button 1 is uit\n");}`

Which means you can construct the message so it has a `topic` also.

Alas I am getting out of my depth.

Put the `debug` node directly on the output of the `COM` node. That will help.

Look up how to construct `JSON` messages.  
Then, you make the code send a `payload` and a `topic`.  
The payload will be simply the _pressed_ or _released_ message. The topic will be which of the buttons it is.

I see someone else has replied.

But if you can do this, it will greatly simplify the problem.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [15 June 2020 12:29 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/11 "2020-06-15T12:29:04Z")

</div>

Yeah, silly me. I forgot about the `contains` option.

Good on you Colin.

Silly me.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [15 June 2020 12:30 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/12 "2020-06-15T12:30:45Z")

</div>

This is what @Colin was meaning:

```auto
[{"id":"b9924a74.4d98f8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"37cfbf3a.73feb","type":"inject","z":"b9924a74.4d98f8","name":"","topic":"","payload":"open","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":690,"y":960,"wires":[["b65e3427.d0f1a"]]},{"id":"b65e3427.d0f1a","type":"ui_switch","z":"b9924a74.4d98f8","name":"","label":"On/Off","tooltip":"","group":"4a387253.a6300c","order":33,"width":"2","height":"1","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"open","onvalueType":"str","onicon":"","oncolor":"","offvalue":"close","offvalueType":"str","officon":"","offcolor":"","x":870,"y":990,"wires":[["2eb7254a.5392d2"]]},{"id":"69aef393.5aa95c","type":"inject","z":"b9924a74.4d98f8","name":"","topic":"","payload":"close","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":690,"y":1030,"wires":[["b65e3427.d0f1a"]]},{"id":"2eb7254a.5392d2","type":"debug","z":"b9924a74.4d98f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1030,"y":990,"wires":[]},{"id":"835c3a2c.a45628","type":"fs-ops-move","z":"b9924a74.4d98f8","name":"","sourcePath":"SourcePath","sourcePathType":"msg","sourceFilename":"SourceFile","sourceFilenameType":"msg","destPath":"Destination","destPathType":"msg","destFilename":"Month","destFilenameType":"msg","link":false,"x":590,"y":410,"wires":[[]]},{"id":"140ccd04.07e44b","type":"inject","z":"b9924a74.4d98f8","name":"","topic":"","payload":"Foo","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":410,"wires":[["74ce89f0.fe53d8"]]},{"id":"daedbe47.cc0ef8","type":"debug","z":"b9924a74.4d98f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":580,"y":360,"wires":[]},{"id":"74ce89f0.fe53d8","type":"function","z":"b9924a74.4d98f8","name":"","func":"msg = {\"_msgid\":\"cdbc874.5066578\",\"topic\":\"\",\"payload\":[\"AC_In.db\"],\"Month\":\"Jun_AC_In.db\",\"SourceFile\":\"AC_In.db\",\"directory\":\"2020\",\"path\":\"/home/me/TEMP/TEMP/\",\"SourcePath\":\"/home/me/TEMP/TEMP/\",\"Destination\":\"/home/me/TEMP/TEMP/2020\"}\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":410,"wires":[["835c3a2c.a45628","daedbe47.cc0ef8"]]},{"id":"51de51af.9d1848","type":"comment","z":"b9924a74.4d98f8","name":"Erase all data by using clearData command","info":"","x":277,"y":1949,"wires":[]},{"id":"8843ad3.515b5d","type":"comment","z":"b9924a74.4d98f8","name":"Format Table using ui_control","info":"","x":227,"y":2102,"wires":[]},{"id":"6f020d17.cd6e14","type":"ui_template","z":"b9924a74.4d98f8","group":"48d9dd9c.267f3c","name":"SETUP","order":32,"width":0,"height":0,"format":"<link rel=\"stylesheet\" href=\"/weather-icons/mycss/weather-icons.min.css\">\n<style>\n :root {\n --dashboard-unit-width: 48px;\n --dashboard-unit-height: 48px;\n }\n /* This is the normal button definition */\n .GButton{\n background-color: black !important;\n color: #cccccc !important;\n /*height: 100%;*/\n height: var(--dashboard-unit-height);\n width: 100%;\n border-radius: 10px;\n font-size:1.0em;\n font-weight:normal;\n margin: 0;\n min-height: 36px;\n min-width: unset;\n line-height: unset;\n }\n /* This is for wide buttons */\n .GButtonW{\n background-color: black !important;\n color: white !important;\n height: var(--dashboard-unit-height);\n width: 100%;\n border-radius: 10px;\n font-size:0.7em;\n font-weight:bold;\n margin: 0;\n min-height: 36px;\n min-width: unset;\n line-height: unset;\n }\n .GButton2{\n background-color: black !important;\n color: #cccccc !important;\n /*height: calc(var(--dashboard-unit-height) * 2);*/\n height: calc((var(--dashboard-unit-height) * 2) + 6px);\n width: 100%;\n border-radius: 10px;\n font-size:1.0em;\n font-weight:normal;\n margin: 0;\n min-height: 36px;\n min-width: unset;\n line-height: unset;\n }\n .GButton3{\n background-color: black !important;\n color: #cccccc !important;\n /*height: calc(var(--dashboard-unit-height) * 2);*/\n height: calc((var(--dashboard-unit-height) * 3) + ((3 - 1) * 6px));\n width: 100%;\n border-radius: 10px;\n font-size:1.0em;\n font-weight:normal;\n margin: 0;\n min-height: 36px;\n min-width: unset;\n line-height: unset;\n }\n\n\n\n .nr-dashboard-theme-dark ui-card-panel {\n \tbackground-color: #222;\n \toutline: 1px solid #cccccc;\n }\n</style>\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"global","x":300,"y":500,"wires":[[]]},{"id":"3a750c40.6e9f04","type":"ui_template","z":"b9924a74.4d98f8","group":"4a387253.a6300c","name":"","order":34,"width":"3","height":"3","format":"<div id=\"regular\">\n <md-button class=\"md-button GButton3\" style=\"background-color:#34495e\" ng-click=\"send({payload: 'toggle'})\"> \n Telemetry\n </md-button> \n</div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":190,"y":620,"wires":[[]]},{"id":"8133ada3.2c5108","type":"ui_template","z":"b9924a74.4d98f8","d":true,"group":"53792891.774238","name":"","order":6,"width":"2","height":"1","format":"<div id=\"{{'thediv_'+$id}}\"></div>\n<script>\n(function($scope) {\n setTimeout(function() {\n //debugger\n $scope.init();\n },100);\n \n $scope.init = function () {\n var d = document.getElementById('thediv_'+$scope.$id)\n var parent = d.parentElement\n console.log('width: '+parent.style.width)\n console.log('height: '+parent.style.height)\n }\n \n})(scope);\n</script>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":550,"y":540,"wires":[[]]},{"id":"c7de52e5.60838","type":"ui_template","z":"b9924a74.4d98f8","group":"48d9dd9c.267f3c","name":"MT","order":33,"width":0,"height":0,"format":"<div ng-bind-html=\"msg.payload\"></div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":100,"y":500,"wires":[[]]},{"id":"ec35c74d.a1e47","type":"ui_template","z":"b9924a74.4d98f8","group":"4a387253.a6300c","name":"","order":35,"width":"3","height":"1","format":"<div id=\"regular\">\n <md-button class=\"md-button GButton\" style=\"background-color:#34495e\" ng-click=\"send({payload: 'toggle'})\"> \n Telemetry\n </md-button> \n</div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":390,"y":620,"wires":[[]]},{"id":"e55aed8d.46e4b8","type":"ui_template","z":"b9924a74.4d98f8","group":"4a387253.a6300c","name":"","order":36,"width":"3","height":"1","format":"<div id=\"regular\">\n <md-button class=\"md-button GButton\" style=\"background-color:#34495e\" ng-click=\"send({payload: 'toggle'})\"> \n Telemetry\n </md-button> \n</div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":390,"y":670,"wires":[[]]},{"id":"56efc78f.112d18","type":"ui_template","z":"b9924a74.4d98f8","group":"4a387253.a6300c","name":"","order":37,"width":"3","height":"1","format":"<div id=\"regular\">\n <md-button class=\"md-button GButton\" style=\"background-color:#34495e\" ng-click=\"send({payload: 'toggle'})\"> \n Telemetry\n </md-button> \n</div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":390,"y":720,"wires":[[]]},{"id":"6e34db77.2b6de4","type":"ui_template","z":"b9924a74.4d98f8","group":"533d5a60.43abdc","name":"style","order":3,"width":0,"height":0,"format":"<style id=\"dash-override\">\n :root{\n --dashboard-unit-height:48px\n }\n .scalebutton{\n background-color: black !important;\n color: #cccccc !important;\n height: unset;\n width: 100%;\n border-radius: 10px;\n font-size:1.0em;\n font-weight:normal;\n margin: 0;\n min-height: 36px;\n min-width: unset;\n line-height: unset;\n }\n .heightOne{\n height: calc((var(--dashboard-unit-height) * 1));\n }\n .heightTwo{\n height: calc((var(--dashboard-unit-height) * 2) + ((2 - 1) * 6px));\n }\n .heightThree{\n height: calc((var(--dashboard-unit-height) * 3) + ((3 - 1) * 6px));\n }\n</style>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"global","x":120,"y":1010,"wires":[[]]},{"id":"dc89ef3c.faf558","type":"ui_template","z":"b9924a74.4d98f8","group":"533d5a60.43abdc","name":"4x2","order":6,"width":"4","height":"2","format":"<div id=\"{{'thediv_'+$id}}\">\n <md-button id=\"{{'btn_'+$id}}\" class=\"md-button scalebutton\">\n BUTTON LABEL\n </md-button>\n</div>\n<script>\n(function($scope) {\n setTimeout(function() {\n //debugger\n $scope.init();\n },100);\n \n $scope.init = function () {\n var d = document.getElementById('thediv_'+$scope.$id)\n var parent = d.parentElement\n var size = parent.getAttribute('ui-card-size').split('x')\n console.log(size)\n var w = parseInt(size[0])\n var h = parseInt(size[1])\n var classToAdd = h == 1 ? 'heightOne' : h == 2 ? 'heightTwo' : 'heightThree'\n var b = document.getElementById('btn_'+$scope.$id)\n b.classList.add(classToAdd)\n \n\n }\n \n})(scope);\n</script>\n\n\n\n\n\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":120,"y":890,"wires":[[]]},{"id":"2b8849e2.51dffe","type":"ui_template","z":"b9924a74.4d98f8","group":"533d5a60.43abdc","name":"2x3","order":6,"width":"2","height":"3","format":"<div id=\"{{'thediv_'+$id}}\">\n <md-button id=\"{{'btn_'+$id}}\" class=\"md-button scalebutton\">\n BUTTON LABEL\n </md-button>\n</div>\n<script>\n(function($scope) {\n setTimeout(function() {\n //debugger\n $scope.init();\n },100);\n \n $scope.init = function () {\n var d = document.getElementById('thediv_'+$scope.$id)\n var parent = d.parentElement\n var size = parent.getAttribute('ui-card-size').split('x')\n console.log(size)\n var w = parseInt(size[0])\n var h = parseInt(size[1])\n var classToAdd = h == 1 ? 'heightOne' : h == 2 ? 'heightTwo' : 'heightThree'\n var b = document.getElementById('btn_'+$scope.$id)\n b.classList.add(classToAdd)\n \n\n }\n \n})(scope);\n</script>\n\n\n\n\n\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":120,"y":930,"wires":[[]]},{"id":"3206c3a3.7d9e74","type":"ui_template","z":"b9924a74.4d98f8","group":"533d5a60.43abdc","name":"3x1","order":6,"width":"3","height":"1","format":"<div id=\"{{'thediv_'+$id}}\">\n <md-button id=\"{{'btn_'+$id}}\" class=\"md-button scalebutton\">\n BUTTON LABEL\n </md-button>\n</div>\n<script>\n(function($scope) {\n setTimeout(function() {\n //debugger\n $scope.init();\n },100);\n \n $scope.init = function () {\n var d = document.getElementById('thediv_'+$scope.$id)\n var parent = d.parentElement\n var size = parent.getAttribute('ui-card-size').split('x')\n console.log(size)\n var w = parseInt(size[0])\n var h = parseInt(size[1])\n var classToAdd = h == 1 ? 'heightOne' : h == 2 ? 'heightTwo' : 'heightThree'\n var b = document.getElementById('btn_'+$scope.$id)\n b.classList.add(classToAdd)\n \n\n }\n \n})(scope);\n</script>\n\n\n\n\n\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":120,"y":970,"wires":[[]]},{"id":"b00c2af6.fc2da","type":"comment","z":"b9924a74.4d98f8","name":"Interesting *","info":"From Hotnipi for different height buttons.","x":130,"y":850,"wires":[]},{"id":"982fbd3c.301c6","type":"moment","z":"b9924a74.4d98f8","name":"","topic":"","input":"","inputType":"msg","inTz":"Australia/Sydney","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-ww","locale":"en_AU","output":"","outputType":"msg","outTz":"Australia/Sydney","x":140,"y":1460,"wires":[["62aafd0e.362ca4"]]},{"id":"62aafd0e.362ca4","type":"change","z":"b9924a74.4d98f8","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"directory","tot":"msg"},{"t":"set","p":"path","pt":"msg","to":"log_paths","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1460,"wires":[["3e82214c.4f5e56","74dc3090.9cd47"]]},{"id":"2951533c.fc233c","type":"inject","z":"b9924a74.4d98f8","name":"Weekly","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":1380,"wires":[["2dcb01c2.836abe","b387aa5e.e7d998"]]},{"id":"3e82214c.4f5e56","type":"template","z":"b9924a74.4d98f8","name":"add to paths","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{{path}}}reboot","output":"str","x":540,"y":1460,"wires":[["6be3a710.d9bf6","5df568be.38c1f"]]},{"id":"74dc3090.9cd47","type":"debug","z":"b9924a74.4d98f8","name":"RAW","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":380,"y":1420,"wires":[]},{"id":"6be3a710.d9bf6","type":"function","z":"b9924a74.4d98f8","name":"Build stuff","func":"//msg.SourcePath = msg.path + \"reboot\";\nmsg.SourcePath = msg.payload;\nmsg.Destination = msg.payload + \"/\" + msg.directory;\nreturn msg;","outputs":1,"noerr":0,"x":110,"y":1500,"wires":[["2b790b29.f00e74"]]},{"id":"5df568be.38c1f","type":"debug","z":"b9924a74.4d98f8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":700,"y":1460,"wires":[]},{"id":"2b790b29.f00e74","type":"fs-ops-dir","z":"b9924a74.4d98f8","name":"","path":"SourcePath","pathType":"msg","filter":"Rebooted at*","filterType":"str","dir":"payload","dirType":"msg","x":330,"y":1500,"wires":[["2cc39458.0f7294"]]},{"id":"2cc39458.0f7294","type":"switch","z":"b9924a74.4d98f8","name":"","property":"payload[0]","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":520,"y":1500,"wires":[["84c35525.13d6d8"]]},{"id":"84c35525.13d6d8","type":"fan","z":"b9924a74.4d98f8","x":700,"y":1500,"wires":[["43b19e01.8af518","12daa301.5caa3d","cf2dee61.6eb37"]]},{"id":"43b19e01.8af518","type":"fs-ops-mkdir","z":"b9924a74.4d98f8","name":"","path":"SourcePath","pathType":"msg","dirname":"directory","dirnameType":"msg","mode":"777","fullpath":"directory","fullpathType":"msg","x":130,"y":1540,"wires":[["3bfacdcc.1f1f12"]]},{"id":"12daa301.5caa3d","type":"delay","z":"b9924a74.4d98f8","name":"Delay","pauseType":"delay","timeout":"2","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":100,"y":1580,"wires":[["9d56f252.d02b88","5bdf7e06.a9d24"]]},{"id":"cf2dee61.6eb37","type":"debug","z":"b9924a74.4d98f8","name":"OUT","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":890,"y":1500,"wires":[]},{"id":"3bfacdcc.1f1f12","type":"debug","z":"b9924a74.4d98f8","name":"1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":320,"y":1540,"wires":[]},{"id":"9d56f252.d02b88","type":"split","z":"b9924a74.4d98f8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":320,"y":1580,"wires":[["454ab5ea.50fba4","a4d345c6.645068"]]},{"id":"454ab5ea.50fba4","type":"debug","z":"b9924a74.4d98f8","name":"1d","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":530,"y":1620,"wires":[]},{"id":"b387aa5e.e7d998","type":"change","z":"b9924a74.4d98f8","name":"TEMP/foo","rules":[{"t":"set","p":"log_paths","pt":"global","to":"/home/me/TEMP/foo/","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":1380,"wires":[[]]},{"id":"5bdf7e06.a9d24","type":"debug","z":"b9924a74.4d98f8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":320,"y":1620,"wires":[]},{"id":"cbca0f4f.b40aa8","type":"exec","z":"b9924a74.4d98f8","command":"mv {{msg.SourcePath}}/Rebooted* {{msg.Destination}}","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":540,"y":1680,"wires":[[],[],[]]},{"id":"a1604aa7.b3fdb8","type":"template","z":"b9924a74.4d98f8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"mv {{SourcePath}}/Rebooted* {{Destination}}","output":"str","x":170,"y":1760,"wires":[["b37e39fa.564a88"]]},{"id":"b37e39fa.564a88","type":"debug","z":"b9924a74.4d98f8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":370,"y":1760,"wires":[]},{"id":"9a4e8d9a.70665","type":"template","z":"b9924a74.4d98f8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"This is the payload: {{payload}} !","output":"str","x":250,"y":1820,"wires":[[]]},{"id":"a4d345c6.645068","type":"fs-ops-move","z":"b9924a74.4d98f8","name":"","sourcePath":"SourcePath","sourcePathType":"msg","sourceFilename":"payload","sourceFilenameType":"msg","destPath":"Destination","destPathType":"msg","destFilename":"payload","destFilenameType":"msg","link":false,"x":540,"y":1580,"wires":[[]]},{"id":"2dcb01c2.836abe","type":"delay","z":"b9924a74.4d98f8","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":100,"y":1420,"wires":[["982fbd3c.301c6"]]},{"id":"b8b96a5a.b58a68","type":"comment","z":"b9924a74.4d98f8","name":"2020 06 10 Working.","info":"","x":520,"y":1350,"wires":[]},{"id":"101620da.dd9def","type":"inject","z":"b9924a74.4d98f8","name":"Your message","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":250,"y":2630,"wires":[["ab588538.5d8fc8"]]},{"id":"77c3a40d.cf1914","type":"inject","z":"b9924a74.4d98f8","name":"Stop","topic":"control","payload":"Stop","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":2450,"wires":[["ab588538.5d8fc8"]]},{"id":"bfdfa379.3510d8","type":"inject","z":"b9924a74.4d98f8","name":"Go","topic":"control","payload":"Go","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":2500,"wires":[["ab588538.5d8fc8"]]},{"id":"5d54f15f.bd2fa8","type":"debug","z":"b9924a74.4d98f8","name":"Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":550,"y":2630,"wires":[]},{"id":"ab588538.5d8fc8","type":"function","z":"b9924a74.4d98f8","name":"","func":"if (msg.topic == \"control\")\n{\n context.set(\"allow\",msg.payload);\n return;\n}\nvar x = context.get(\"allow\")\nif (x == \"Stop\")\n{\n return;\n}\nelse\nreturn msg;","outputs":1,"noerr":0,"x":400,"y":2630,"wires":[["5d54f15f.bd2fa8"]]},{"id":"1bde9e00.2cbbca","type":"comment","z":"b9924a74.4d98f8","name":"Phone","info":"","x":120,"y":3490,"wires":[]},{"id":"199b1fa.76c636","type":"comment","z":"b9924a74.4d98f8","name":"Computer","info":"","x":540,"y":3490,"wires":[]},{"id":"4d9e86f6.cedc7","type":"comment","z":"b9924a74.4d98f8","name":"Phone","info":"","x":840,"y":3490,"wires":[]},{"id":"a13d71bc.75cb5","type":"inject","z":"b9924a74.4d98f8","name":"Button 1","topic":"","payload":"Button 1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":3560,"wires":[["65b44057.d8c938"]]},{"id":"65b44057.d8c938","type":"mqtt out","z":"b9924a74.4d98f8","name":"","topic":"Button1","qos":"","retain":"","broker":"378c0403.8cda04","x":260,"y":3560,"wires":[]},{"id":"95f30a24.0a1808","type":"mqtt in","z":"b9924a74.4d98f8","name":"","topic":"Topic1","qos":"2","datatype":"auto","broker":"378c0403.8cda04","x":390,"y":3560,"wires":[["87adc0cb.0ea23"]]},{"id":"e843ca1a.d0efa","type":"mqtt out","z":"b9924a74.4d98f8","name":"","topic":"State1","qos":"","retain":"","broker":"378c0403.8cda04","x":680,"y":3560,"wires":[]},{"id":"7a45093b.a0367","type":"mqtt in","z":"b9924a74.4d98f8","name":"State1","topic":"State1","qos":"2","datatype":"auto","broker":"378c0403.8cda04","x":800,"y":3560,"wires":[["a3e0593e.a412f8"]]},{"id":"87adc0cb.0ea23","type":"function","z":"b9924a74.4d98f8","name":"Do stuff here","func":"\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":3560,"wires":[["e843ca1a.d0efa"]]},{"id":"a3e0593e.a412f8","type":"debug","z":"b9924a74.4d98f8","name":"Indicator 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":940,"y":3560,"wires":[]},{"id":"8dd4a8b0.631a68","type":"switch","z":"b9924a74.4d98f8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"button 1","vt":"str"},{"t":"cont","v":"button 2","vt":"str"},{"t":"cont","v":"button 3","vt":"str"},{"t":"cont","v":"button 4","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":430,"y":3830,"wires":[[],[],[],[]]},{"id":"4a387253.a6300c","type":"ui_group","z":"","name":"SPARE","tab":"de5134a7.f0a0d","order":3,"disp":true,"width":"6","collapse":false},{"id":"48d9dd9c.267f3c","type":"ui_group","z":"","d":true,"name":"Full_Remote","tab":"b128eb09.9f681","order":1,"disp":false,"width":"3","collapse":false},{"id":"53792891.774238","type":"ui_group","name":"Group 7","tab":"de5134a7.f0a0d","order":4,"disp":true,"width":6},{"id":"533d5a60.43abdc","type":"ui_group","z":"","name":"Default","tab":"51cd257f.61873c","order":1,"disp":true,"width":"6","collapse":false},{"id":"378c0403.8cda04","type":"mqtt-broker","z":"","name":"MQTT HOST","broker":"192.168.0.99","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"de5134a7.f0a0d","type":"ui_tab","name":"Tab 6","icon":"dashboard","order":5},{"id":"b128eb09.9f681","type":"ui_tab","z":"","name":"HDMI_TV_control","icon":"dashboard","order":1,"disabled":false,"hidden":false},{"id":"51cd257f.61873c","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

As the idea.

(Oh and I goofed with the code you posted. I forgot to scroll and see it all.)

There is nothing wrong with what @Colin said and how it works.  
Other than you will have to use another node to then determine if the button is `uit` or `aan`.  
If you can find a way to add a `topic` to the message being sent you can remove that need because there will be two parts to the message:  
The `topic` will identify the button and the `payload` will be the state.

So as is, you have the first `switch` node. That splits the incoming message into the 4 button states.

On each output of that `switch` node, you (may) need another `switch` to _switch_ the message or a `function` node to look at the message and act depending on the condition.

With a `topic` you would send it into a `node` and the conditional testing would not be needed.

Just saying.

It is a bit of "swings and roundabouts" (give and take) where you want to do what.  
At the end of the day it has to be done somewhere.  
Just one way the message has to parsed twice to determine the state.  
The other way it is parsed once and the condition is given.

---

<div class="post-metadata">

**Author:** ![anthony\_dob](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anthony_dob/32/23958_2.png) [@anthony\_dob](https://discourse.nodered.org/u/anthony_dob)\
**Post date:** [15 June 2020 12:37 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/13 "2020-06-15T12:37:31Z")

</div>

i haven't worked with switch node before but is this how you do it? It's currently not working

![2020-06-15 14_36_14-Node-RED](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/8/1868810b11f8e069621e2165586169bb304a858e.png) ![2020-06-15 14_36_23-Node-RED](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fd2217d3f9269ccc243f58ee8547d0b178b700f3.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [15 June 2020 12:46 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/14 "2020-06-15T12:46:46Z")

</div>

Nearly.

I posted an example.

You need to change the `==` to `contains`.

Then it will work.

And!

Just make it `button x` where x is either 1, 2, 3 or 4

So it will look like:

![Screenshot from 2020-06-15 22-47-49](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/9/29626b3b9e014a085ab93a38a7aa4cb69f6bf224.png)

Here is an example of the two methods I said:

```auto
[{"id":"8dd4a8b0.631a68","type":"switch","z":"b9924a74.4d98f8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"button 1","vt":"str"},{"t":"cont","v":"button 2","vt":"str"},{"t":"cont","v":"button 3","vt":"str"},{"t":"cont","v":"button 4","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":430,"y":3830,"wires":[["22c88f1e.d9f058"],[],[],[]]},{"id":"467f5727.31621","type":"inject","z":"b9924a74.4d98f8","name":"Button 1 pressed","topic":"","payload":"button 1 pressed","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":3810,"wires":[["8dd4a8b0.631a68"]]},{"id":"e6104c46.8d1178","type":"inject","z":"b9924a74.4d98f8","name":"Button 1 released","topic":"","payload":"button 1 released","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":3850,"wires":[["8dd4a8b0.631a68"]]},{"id":"22c88f1e.d9f058","type":"debug","z":"b9924a74.4d98f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":3770,"wires":[]},{"id":"95ea0452.77e96","type":"switch","z":"b9924a74.4d98f8","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"button 1","vt":"str"},{"t":"eq","v":"button 2","vt":"str"},{"t":"eq","v":"button 3","vt":"str"},{"t":"eq","v":"button 4","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":430,"y":3990,"wires":[["5916dcef.ba58c4"],[],[],[]]},{"id":"2986458f.c1362a","type":"inject","z":"b9924a74.4d98f8","name":"Button 1 pressed","topic":"button 1","payload":"pressed","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":3970,"wires":[["95ea0452.77e96"]]},{"id":"bcb4595e.1c34","type":"inject","z":"b9924a74.4d98f8","name":"Button 1 released","topic":"button 1","payload":"released","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":4010,"wires":[["95ea0452.77e96"]]},{"id":"5916dcef.ba58c4","type":"debug","z":"b9924a74.4d98f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":3930,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![anthony\_dob](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anthony_dob/32/23958_2.png) [@anthony\_dob](https://discourse.nodered.org/u/anthony_dob)\
**Post date:** [15 June 2020 12:52 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/15 "2020-06-15T12:52:01Z")

</div>

It works! thank you so much and Colin as well!

 ![2020-06-15 14_51_23-Node-RED](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/1/e19e9314dd15a1ebaafe3e05294e7cfb3f4055c7.png) ![2020-06-15 14_51_31-Node-RED](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f9b44db2f6dae873946db9040faae98e4b7aeeed.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [15 June 2020 12:55 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/16 "2020-06-15T12:55:44Z")

</div>

But please look at the second example in that code I posted.

I know it is a bit _annoying_ (difficult) (unwanted complication) at this stage.

But if you look at it and open the `switch` node (and maybe the `inject` nodes) to see what is going on, you can see how it moves the filtering of the message to a different _level_ and so makes things _easier_ for you.

Ok, maybe not easier, but it separates how it is done.

 ![Screenshot from 2020-06-15 22-57-39](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/3/23492d8f6519d42b4fef281642a413d210c5327a.png)

---

<div class="post-metadata">

**Author:** ![anthony\_dob](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anthony_dob/32/23958_2.png) [@anthony\_dob](https://discourse.nodered.org/u/anthony_dob)\
**Post date:** [15 June 2020 13:02 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/17 "2020-06-15T13:02:25Z")

</div>

oh yes i see. Second one you added a topic. Makes it more readable i guess. Again thank you for the help! I have been strugling many hours to write a function wich would do this.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [15 June 2020 13:05 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/18 "2020-06-15T13:05:08Z")

</div>

Well, it means at the next _stage_ you don't need to receive the prefix.

The message is easier to read.

---

<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:** [15 June 2020 13:08 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/19 "2020-06-15T13:08:18Z")

</div>

When you have a bit more experience come back to this and work out how to do it all in one function node. It is possible to extract the button number and the value from the string and then automatically work out the topic and send the value to the mqtt node. Then instead of 1 switch and four MQTT nodes you end up with 1 function node and 1 MQTT node.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [15 June 2020 13:13 UTC](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355/20 "2020-06-15T13:13:59Z")

</div>

~~But the topic would have to be written/set in the arduino end of things as I indicated - yes?~~

Sorry. You mean **after** the `COM` node. My bad.

[Next page](https://discourse.nodered.org/t/how-to-select-one-msg-payload-out-of-4-recieved/28355.md?page=2)
