# Switch node and Object message

**URL:** <https://discourse.nodered.org/t/switch-node-and-object-message/7706>\
**Category:** General\
**Created:** [7 February 2019 12:12 UTC](https://discourse.nodered.org/t/switch-node-and-object-message/7706 "2019-02-07T12:12:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SuperNinja](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/superninja/32/5761_2.png) [@SuperNinja](https://discourse.nodered.org/u/SuperNinja)\
**Post date:** [7 February 2019 12:12 UTC](https://discourse.nodered.org/t/switch-node-and-object-message/7706/1 "2019-02-07T12:12:17Z")

</div>

I forgot to introduce myself Hi all , i'm new with Node Red and JavaScript. i'm on a project with multi sensor in my home automation.  
I would like to make averages for sensor values. I saw this topic which corresponds to my request: [DS18B20 smoothing and PID tuning - #2 by Andrei](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/2)  
The Switch node separates the sensors on the different outputs thanks to the **topic** and **payload** of each sensor.

For my part, the message I receive is an object:  
`{" MeteoTemperature ": 32.5," meteoHumidity ": 75}`  
**My question:** in the Switch node how do I have to fill the contitions to direct my sensors?

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

> [{"id":"4c6736d0.2f4a38","type":"switch","z":"fe2c7bc6.bd49c8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"payload.meteoTemperature","vt":"jsonata"},{"t":"cont","v":"meteoHumidity","vt":"str"},{"t":"cont","v":"meteoPressure","vt":"str"},{"t":"cont","v":"notUsed","vt":"str"},{"t":"cont","v":"voltage","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":358.57144927978516,"y":1865.714412689209,"wires":[["188a6136.b0778f"],,,,]},{"id":"188a6136.b0778f","type":"debug","z":"fe2c7bc6.bd49c8","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":513.5714149475098,"y":1842.7143421173096,"wires":},{"id":"852bed77.21c8f","type":"inject","z":"fe2c7bc6.bd49c8","name":"","topic":"","payload":"{"meteoTemperature":32.5,"meteoHumidity":75}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":212.85714721679688,"y":1867.1429471969604,"wires":[["4c6736d0.2f4a38"]]}]

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [7 February 2019 12:32 UTC](https://discourse.nodered.org/t/switch-node-and-object-message/7706/2 "2019-02-07T12:32:46Z")

</div>

Hi @SuperNinja

The Switch node can be used to route the entire message to different outputs based on the different rules you create. It does not modify the structure of the message.

You need to use a Split node first. When it receives msg.payload as an Object, it will emit a new message for each key/value pair in that object. You can configure the node to copy the key value to `msg.topic`.

You can then use a Switch node to check `msg.topic` and add a rule for each of the topics you are getting.

By the way, please read this post on sharing code in the forum: [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![SuperNinja](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/superninja/32/5761_2.png) [@SuperNinja](https://discourse.nodered.org/u/SuperNinja)\
**Post date:** [7 February 2019 14:59 UTC](https://discourse.nodered.org/t/switch-node-and-object-message/7706/3 "2019-02-07T14:59:24Z")

</div>

thanks @knolleary , i test it.
