# Switch-Node problem

**URL:** https://discourse.nodered.org/t/switch-node-problem/89921
**Category:** General
**Created:** [31 July 2024 19:04 UTC](https://discourse.nodered.org/t/switch-node-problem/89921 "2024-07-31T19:04:52Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![pio007](https://avatars.discourse-cdn.com/v4/letter/p/ac91a4/32.png) [@pio007](https://discourse.nodered.org/u/pio007)
#### Post date: [31 July 2024 19:04 UTC](https://discourse.nodered.org/t/switch-node-problem/89921/1 "2024-07-31T19:04:52Z")

</div>

Hello,  
I have a problem with a switch node or a question for understanding.

I have an input value from a Zigbee sensor ("feuchte").

From a visualization I have an input value ("schwelle" which I first convert into a number).

Now I want to work with these two values ​​in the switch node and output true or false via the 2 outputs (in order to switch another device later).

 ![Bildschirmfoto 2024-07-31 um 20.41.19](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/d/3d2b8077eea05028e03e70212452cd6f0ee12d17.png)

However, the switch node does not provide any output values.  
It seems as if the value "schwelle" is not read in into the switch-node. Why?

 ![Bildschirmfoto 2024-07-31 um 20.48.46](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/5/c5440aee17853ee44d39a9e7bda464828c86594c.png)

I have more screenshots, but new users are not allowed to upload more than 2 images.  
Hope someone can help further  
Thank you very much.  
Regards Marc

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [31 July 2024 19:53 UTC](https://discourse.nodered.org/t/switch-node-problem/89921/2 "2024-07-31T19:53:42Z")

</div>

I don't actually think you need both switch and change nodes for this. The change node alone can change values based on the input. So have a look at doing that instead.

---

<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: [31 July 2024 20:05 UTC](https://discourse.nodered.org/t/switch-node-problem/89921/3 "2024-07-31T20:05:27Z")

</div>

Just to note there is no need to use JSONata.  
Rule 1 greater than msg schwelle  
Rule 2 otherwise.

You would also need to use a join node to join the message

See [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

---

<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: [31 July 2024 20:05 UTC](https://discourse.nodered.org/t/switch-node-problem/89921/4 "2024-07-31T20:05:58Z")

</div>

Hello @pio007, welcome to the forum.

Joining these two wires at the "feuchte" node _does not mean that `msg.feuchte` and `msg.schwelle` are both available at the same time._  
The two messages remain entirely separate.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/2/e231232f93272d1464a7721e4d55f0c56d8144bb.png)

I recommend that you put debug nodes to show the entire message coming from "Zigbee Luftfeuchte" and "Schwelle Luftfeuchte aus VIS".

Do `msg.schwelle` or `msg.feuchte` exist, or do both nodes pass a `msg.payload`?

Do both messages have a `msg.topic` property?

See [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

---

<div class="post-metadata">

### Author: ![pio007](https://avatars.discourse-cdn.com/v4/letter/p/ac91a4/32.png) [@pio007](https://discourse.nodered.org/u/pio007)
#### Post date: [31 July 2024 20:57 UTC](https://discourse.nodered.org/t/switch-node-problem/89921/5 "2024-07-31T20:57:58Z")

</div>

ahhh, I see, the problem is that not both msg arrive in the switch node at the same time. JOIN-node is the solution.  
Converting the string into a number doesn't seem necessary either. Thank you for your help!  
I have now added a JOIN node (the 2 topics are also assigned), the result in the debug is the following:

 ![Bildschirmfoto 2024-07-31 um 22.51.12](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/3/23fe3cd4dbcc0ff5e7a769da465aafa8f266316c.png)

 ![Bildschirmfoto 2024-07-31 um 22.50.38](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/04de08e6a37a8167cf2f3386275bf4d808e38813.png)

What I don't understand yet is how I can use the tow topics (feuchte and schwelle) in the switch node. I tried this, but the result is not correct...  
Thank you again...

---

<div class="post-metadata">

### Author: ![pio007](https://avatars.discourse-cdn.com/v4/letter/p/ac91a4/32.png) [@pio007](https://discourse.nodered.org/u/pio007)
#### Post date: [31 July 2024 20:58 UTC](https://discourse.nodered.org/t/switch-node-problem/89921/6 "2024-07-31T20:58:37Z")

</div>

![Bildschirmfoto 2024-07-31 um 22.56.14](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/8/b81580a14f9ac69f99d548664ef59e91c7ef0f5f.png)  
 ![Bildschirmfoto 2024-07-31 um 22.56.27](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/2/52925fb145f10b3b39f8841b1b533553f3aba4da.png)

---

<div class="post-metadata">

### Author: ![Frida](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frida/32/68250_2.png) [@Frida](https://discourse.nodered.org/u/Frida)
#### Post date: [31 July 2024 21:27 UTC](https://discourse.nodered.org/t/switch-node-problem/89921/7 "2024-07-31T21:27:03Z")

</div>

![pic01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/9/c92b1a7fc5e3cc8fa253e1da667109f1ba066846.png)

---

<div class="post-metadata">

### Author: ![pio007](https://avatars.discourse-cdn.com/v4/letter/p/ac91a4/32.png) [@pio007](https://discourse.nodered.org/u/pio007)
#### Post date: [1 August 2024 06:18 UTC](https://discourse.nodered.org/t/switch-node-problem/89921/8 "2024-08-01T06:18:33Z")

</div>

perfect, thank you very much everybody.... that works! 🤗 🤗

---

<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: [30 October 2024 06:18 UTC](https://discourse.nodered.org/t/switch-node-problem/89921/9 "2024-10-30T06:18:53Z")

</div>

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