Mqtt In to a single number - how?

Hey

I need a single Number (float) for my themostat. So I try to select the value “temperature: 23.7” from the “mqtt In” and just pass the number

 : msg.payload : Object
object
battery: 100
humidity: 60
linkquality: 69
temperature: 23.7

function Node

// Extract the temperature from msg.payload and assign it to a new message
var temperature = msg.payload.temperature;

// Create a new message with only the temperature
msg.payload = temperature;

// Send out the new message
return msg;
// Create a new message with only the temperature
msg.payload = Math.round(msg.payload.temperature);

// Send out the new message
return msg;

The above is probably what you need…

1 Like

This doesn’t look like a typical debug message, I’m guessing that you can’t get the value from payload.temperature? It appears the value is at msg.temperature.

A change node can be used to move and/or adjust values and their message position.

image

You specifically ask for float that means the number can have a decimal. If that is correct no adjustment is necessary. If you need an integer, whole number no decimal use

image