Switch node and Object message


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
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?




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



thanks @knolleary , i test it.