# A "reverse" switch?

**URL:** https://discourse.nodered.org/t/a-reverse-switch/38304
**Category:** General
**Created:** [30 December 2020 21:41 UTC](https://discourse.nodered.org/t/a-reverse-switch/38304 "2020-12-30T21:41:13Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![traderjoe](https://avatars.discourse-cdn.com/v4/letter/t/f9ae1b/32.png) [@traderjoe](https://discourse.nodered.org/u/traderjoe)
#### Post date: [30 December 2020 21:41 UTC](https://discourse.nodered.org/t/a-reverse-switch/38304/1 "2020-12-30T21:41:13Z")

</div>

I have 2 different payloads coming into a node. They have different topics. How do I switch what comes out of the output based on a property? So if a property = 1, then output the payload with topic 1, if 2, then output the payload with topic 2.

Acts like reverse switch, right? Switch node has 1 input, 2 output routes. What I'm thinking of is a node with 2 input, with 1 output route.

---

<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: [30 December 2020 21:52 UTC](https://discourse.nodered.org/t/a-reverse-switch/38304/2 "2020-12-30T21:52:01Z")

</div>

Could you post the two (complete) payloads?

It is just I think you are not quite understanding how to use a `switch` node to its capacity.

(And) you may need to use more than one `switch` node.

---

<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 December 2020 21:56 UTC](https://discourse.nodered.org/t/a-reverse-switch/38304/3 "2020-12-30T21:56:38Z")

</div>

Use a Change node configured to Set msg.topic To msg.property.  
So if msg.property = 1 then the msg.topic will be set to 1.

---

<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: [30 December 2020 21:57 UTC](https://discourse.nodered.org/t/a-reverse-switch/38304/4 "2020-12-30T21:57:23Z")

</div>

That's another way.

Good on you @Colin.

---

<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: [30 December 2020 21:59 UTC](https://discourse.nodered.org/t/a-reverse-switch/38304/5 "2020-12-30T21:59:49Z")

</div>

> [@traderjoe](#):
>
> So if a property = 1, then output the payload with topic 1, if 2, then output the payload with topic 2.

This is interesting.

Taking a step back and trying to see the bigger picture:  
I'm guessing you want the `topic` to be set so the next stage of the flow can determine what to do with the message.

Why can't you use the `property` part of the message at the next stage?

---

<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 December 2020 22:01 UTC](https://discourse.nodered.org/t/a-reverse-switch/38304/6 "2020-12-30T22:01:23Z")

</div>

Actually I think that @traderjoe needs to ask the question again in a way that is easier to understand, as I expect he/she can see now that he has not explained it very well.

---

<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: [30 December 2020 22:02 UTC](https://discourse.nodered.org/t/a-reverse-switch/38304/7 "2020-12-30T22:02:10Z")

</div>

@traderjoe  
This flow does what I make of your question:

```auto
[{"id":"24597219.e27fbe","type":"inject","z":"703c61ac.837e1","name":"","props":[{"p":"payload"},{"p":"something_else","v":"blah","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"message one","payloadType":"str","x":1770,"y":230,"wires":[["29bc705.2a71b1"]]},{"id":"1e4f1eca.f73bc9","type":"inject","z":"703c61ac.837e1","name":"","props":[{"p":"payload"},{"p":"something_else","v":"foo","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"message two","payloadType":"str","x":1770,"y":280,"wires":[["29bc705.2a71b1"]]},{"id":"29bc705.2a71b1","type":"switch","z":"703c61ac.837e1","name":"something_else","property":"something_else","propertyType":"msg","rules":[{"t":"eq","v":"blah","vt":"str"},{"t":"eq","v":"foo","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1950,"y":260,"wires":[["6546362e.6e658"],["1c352175.76b1bf"]]},{"id":"6546362e.6e658","type":"debug","z":"703c61ac.837e1","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":2120,"y":230,"wires":[]},{"id":"1c352175.76b1bf","type":"debug","z":"703c61ac.837e1","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":2120,"y":290,"wires":[]}]

```

Very basic flow to get the idea through.

---

<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: [28 February 2021 22:02 UTC](https://discourse.nodered.org/t/a-reverse-switch/38304/8 "2021-02-28T22:02:15Z")

</div>

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