# Change to another output on input

**URL:** <https://discourse.nodered.org/t/change-to-another-output-on-input/24744>\
**Category:** General\
**Created:** [13 April 2020 11:22 UTC](https://discourse.nodered.org/t/change-to-another-output-on-input/24744 "2020-04-13T11:22:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![microfix](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@microfix](https://discourse.nodered.org/u/microfix)\
**Post date:** [13 April 2020 11:22 UTC](https://discourse.nodered.org/t/change-to-another-output-on-input/24744/1 "2020-04-13T11:22:22Z")

</div>

So I'm new to all the programming. 🙂

I learn a lot from reading what all you make.  
And thanks for that.  
But now i need something and is hoping that some of you can help me learn this.

I need a function node, where I can change output for all payloads.

So if I input with a msg.payload = right\_click  
I want to have the output for all other payloads lead to another output.

I have a remote, and want to change lights, so if i push toggle, the lamp on the table toggles,  
then i "right\_click" and the toggle can now turn of and on the light on the wall.  
Hope some of you can help me out, and thanks in advance. 🙂

I also have a "left\_click" so if I can change back and forth that is nice, and i have more then 2 lamps. 🙂

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [13 April 2020 15:36 UTC](https://discourse.nodered.org/t/change-to-another-output-on-input/24744/2 "2020-04-13T15:36:21Z")

</div>

Perhaps a switch node can help you out.

---

<div class="post-metadata">

**Author:** ![microfix](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@microfix](https://discourse.nodered.org/u/microfix)\
**Post date:** [13 April 2020 15:59 UTC](https://discourse.nodered.org/t/change-to-another-output-on-input/24744/3 "2020-04-13T15:59:49Z")

</div>

I can't se a way, to make the switch that way. Maby it's just me.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [13 April 2020 16:06 UTC](https://discourse.nodered.org/t/change-to-another-output-on-input/24744/4 "2020-04-13T16:06:01Z")

</div>

Try this flow

```auto
[{"id":"ca9f5398.bdfe38","type":"inject","z":"5120f156.f4f4e","name":"","topic":"","payload":"left_click","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":324,"y":240,"wires":[["b83bad90.84fe9"]]},{"id":"8f6789e8.968ba","type":"inject","z":"5120f156.f4f4e","name":"","topic":"","payload":"right_click","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":324,"y":288,"wires":[["b83bad90.84fe9"]]},{"id":"b83bad90.84fe9","type":"switch","z":"5120f156.f4f4e","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"left_click","vt":"str"},{"t":"eq","v":"right_click","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":506,"y":264,"wires":[["70163f18.6dd9f8"],["4170e584.60c0c4"]]},{"id":"70163f18.6dd9f8","type":"debug","z":"5120f156.f4f4e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":694,"y":240,"wires":[]},{"id":"4170e584.60c0c4","type":"debug","z":"5120f156.f4f4e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":694,"y":288,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![microfix](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@microfix](https://discourse.nodered.org/u/microfix)\
**Post date:** [13 April 2020 16:17 UTC](https://discourse.nodered.org/t/change-to-another-output-on-input/24744/5 "2020-04-13T16:17:22Z")

</div>

Will do, once i get back to my pc. In an hour or so. But thanks for helping. 😊

---

<div class="post-metadata">

**Author:** ![microfix](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@microfix](https://discourse.nodered.org/u/microfix)\
**Post date:** [13 April 2020 17:03 UTC](https://discourse.nodered.org/t/change-to-another-output-on-input/24744/6 "2020-04-13T17:03:06Z")

</div>

I looked at it now, but that i understand.

My need is more the way of controlling all the data with a single switch, so i can put ind "turn\_on\_light" to lamp1, then switch and put the "turn\_on\_light" to lamp2. 🙂

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [13 April 2020 17:19 UTC](https://discourse.nodered.org/t/change-to-another-output-on-input/24744/7 "2020-04-13T17:19:12Z")

</div>

Perhaps you should provide some data we can work with, or what the input is.  
Do you mean switch on the dashboard, physical switch, logical switch ?

What is your input, and what do you want as output.

---

<div class="post-metadata">

**Author:** ![microfix](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@microfix](https://discourse.nodered.org/u/microfix)\
**Post date:** [13 April 2020 17:22 UTC](https://discourse.nodered.org/t/change-to-another-output-on-input/24744/8 "2020-04-13T17:22:19Z")

</div>

I have an IKEA remote, the round one,with 5 physical switches.  
I wanna turn on my lights with toggle, then when i press "arrow-right"  
it switches to another light, then when i press the "arrow-right" again, it switches to the 3 light.

I have found a way to do it, with switches, but i can only switch one way, not the other way around. 🙂

---

<div class="post-metadata">

**Author:** ![microfix](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@microfix](https://discourse.nodered.org/u/microfix)\
**Post date:** [13 April 2020 18:00 UTC](https://discourse.nodered.org/t/change-to-another-output-on-input/24744/10 "2020-04-13T18:00:29Z")

</div>

I have mad this, as a subflow.

```auto
[{"id":"b1f41687.9504c8","type":"switch","z":"ab257b02.ffd96","name":"Set flow.toggle-me","property":"toggle-me","propertyType":"flow","rules":[{"t":"eq","v":"3","vt":"str"},{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":970,"y":380,"wires":[["3dbf00d.a4d688"],["f957fd1e.0b504"],["ab9e5ec9.2b9d2"]]},{"id":"3dbf00d.a4d688","type":"change","z":"ab257b02.ffd96","name":"Set to 1","rules":[{"t":"set","p":"toggle-me","pt":"flow","to":"1","tot":"str"},{"t":"set","p":"toggle-me","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1210,"y":340,"wires":[[]]},{"id":"58a85b9.60326a4","type":"inject","z":"ab257b02.ffd96","name":"Startup","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":1060,"y":300,"wires":[["3dbf00d.a4d688"]]},{"id":"f47f1b5.f83efe8","type":"inject","z":"ab257b02.ffd96","name":"Toggle","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":770,"y":480,"wires":[["b1f41687.9504c8"]]},{"id":"2c8ffd11.771f9a","type":"inject","z":"ab257b02.ffd96","name":"Do something","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":770,"y":120,"wires":[["54018814.d1b928"]]},{"id":"f6c6173a.0989c8","type":"switch","z":"ab257b02.ffd96","name":"1,2,3","property":"toggle-me","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":1190,"y":200,"wires":[["6bb47044.0aed3"],["dd379602.c5c89"],["71b46800.9ae3b8"]]},{"id":"54018814.d1b928","type":"change","z":"ab257b02.ffd96","name":"Fecth state","rules":[{"t":"set","p":"toggle-me","pt":"msg","to":"toggle-me","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":200,"wires":[["f6c6173a.0989c8"]]},{"id":"f957fd1e.0b504","type":"change","z":"ab257b02.ffd96","name":"Set to 2","rules":[{"t":"set","p":"toggle-me","pt":"flow","to":"2","tot":"str"},{"t":"set","p":"toggle-me","pt":"msg","to":"2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1210,"y":380,"wires":[[]]},{"id":"ab9e5ec9.2b9d2","type":"change","z":"ab257b02.ffd96","name":"Set to 3","rules":[{"t":"set","p":"toggle-me","pt":"flow","to":"3","tot":"str"},{"t":"set","p":"toggle-me","pt":"msg","to":"3","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1210,"y":420,"wires":[[]]},{"id":"130f9132.2540b7","type":"switch","z":"ab257b02.ffd96","name":"","property":"payload.action","propertyType":"msg","rules":[{"t":"cont","v":"toggle","vt":"str"},{"t":"cont","v":"arrow_right_click","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":770,"y":280,"wires":[["54018814.d1b928","4f6d02a2.ab779c"],["b1f41687.9504c8","624ce1dd.5dca38"]]},{"id":"71b46800.9ae3b8","type":"function","z":"ab257b02.ffd96","name":"toggle","func":"msg.payload = { \"state\":\"toggle\"};\nreturn msg;","outputs":1,"noerr":0,"x":1350,"y":240,"wires":[[]]},{"id":"dd379602.c5c89","type":"function","z":"ab257b02.ffd96","name":"toggle","func":"msg.payload = { \"state\":\"toggle\"};\nreturn msg;","outputs":1,"noerr":0,"x":1350,"y":200,"wires":[[]]},{"id":"6bb47044.0aed3","type":"function","z":"ab257b02.ffd96","name":"toggle","func":"msg.payload = { \"state\":\"toggle\"};\nreturn msg;","outputs":1,"noerr":0,"x":1350,"y":160,"wires":[[]]},{"id":"624ce1dd.5dca38","type":"debug","z":"ab257b02.ffd96","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":380,"wires":[]},{"id":"4f6d02a2.ab779c","type":"debug","z":"ab257b02.ffd96","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":700,"y":200,"wires":[]}]

```

---

<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:** [12 June 2020 18:00 UTC](https://discourse.nodered.org/t/change-to-another-output-on-input/24744/11 "2020-06-12T18:00:30Z")

</div>

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