# Switch Node | Beginner Question

**URL:** <https://discourse.nodered.org/t/switch-node-beginner-question/70573>\
**Category:** General\
**Created:** [14 November 2022 12:27 UTC](https://discourse.nodered.org/t/switch-node-beginner-question/70573 "2022-11-14T12:27:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dokwon](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@dokwon](https://discourse.nodered.org/u/dokwon)\
**Post date:** [14 November 2022 12:27 UTC](https://discourse.nodered.org/t/switch-node-beginner-question/70573/1 "2022-11-14T12:27:36Z")

</div>

Hey guys,

starting to learn Node-RED and hence running into some 'beginner-friendly' questions 😃

![2022-11-14 13_15_48-Window](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/4/24a57dea9a6933b787c3b952fbb853419d751a9e.png)  
screenshot 1

![2022-11-14 13_17_43-Window](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fc2e4f649d52bdb5653a245212996aec45ddf6f2.png)  
screenshot 2

The screenshots are taken from a switch node that I have attached to an 'mqtt in' node representing the output from a thermometer. The object that gets passed can be see in the second screenshot.  
Now in my mind, it should be possible to parse the number from temperature and apply a simple logic: "If temperature below 18°C do this", else "do that".  
I set this up in screenshot one. However this does not work. Even if the temp is below 18°C the node will always choose "otherwise".

Interestingly enough, if I ask it to proceed if regex matches \d\*\.\d\* it will correctly understand that there is a number and continue the flow. I must be missing something fundamental here, anyone willing to help?

PS. I already have the automation running by using a change node and moving msg.payload.temperature to msg.payload. Everything is running fine. I just want to understand the switch node better.

Thanks!

---

<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:** [14 November 2022 13:52 UTC](https://discourse.nodered.org/t/switch-node-beginner-question/70573/2 "2022-11-14T13:52:11Z")

</div>

You are using JSONata which you do not require  
The mqtt message comes in on msg.payload.temperature most likely, but your test screenshot, you have enter the data in msg, not msg.payload.

I would set the switch property to `msg.` `payload.temperature`  
and the rule to as you have it.  
`<=` `18`

As to regex it the payload a string or an object, show us in a debug node the msg entering the switch node.

---

<div class="post-metadata">

**Author:** ![dokwon](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@dokwon](https://discourse.nodered.org/u/dokwon)\
**Post date:** [14 November 2022 14:34 UTC](https://discourse.nodered.org/t/switch-node-beginner-question/70573/3 "2022-11-14T14:34:34Z")

</div>

Awesome. Yes I see it now. Explains why the regex matches aswell. Thank you!

---

<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 November 2022 14:35 UTC](https://discourse.nodered.org/t/switch-node-beginner-question/70573/4 "2022-11-28T14:35:10Z")

</div>

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