Remove " " in payload

Hi all,

I searched google and this forum, but didn't find an answer my specific question.

I'm trying to create a table in the dashboard showing the room name, temperature and humidity of my 10 Aqara Multisensors.
For this I am using the "table" node from node-red-node-ui-table.

This table uses the following format as payload:

var data = [
{
"Raum": "Küche",
"Temperatur": temp,
"Humidity": hum,
}
]

For single sensors I am able to create this table, but not for all 10 of them.
What I'm doing is the following:
Get the humidity and temperature of a sensor from iobroker and in a function node do the following:

temp = msg.payload[1] + "°C";
hum = msg.payload[0] + "%";

var data = '{   "Raum": "Küche",    "Temperatur": temp,   "Humidity": hum,  }';

msg.payload = data;
return msg;

I do this for all 10 sensors and then join them via the join node.
Then I use another function node to do the following:

var data = [
    msg.payload[0],
    msg.payload[1],
    msg.payload[2],
    msg.payload[3],
    msg.payload[4],
    msg.payload[5],
    msg.payload[6],
    msg.payload[7],
    msg.payload[8],
    msg.payload[9],
    ]

msg.payload = data;
return msg;

What that gets me is this array:

0: "{   "Raum": "Flur 1",    "Temperatur": temp,   "Humidity": hum,  }"
1: "{   "Raum": "Loggia",    "Temperatur": temp,   "Humidity": hum,  }"
2: "{   "Raum": "Esszimmer",    "Temperatur": temp,   "Humidity": hum,  }"
3: "{   "Raum": "Wohnzimmer",    "Temperatur": temp,   "Humidity": hum,  }"
4: "{   "Raum": "Büro",    "Temperatur": temp,   "Humidity": hum,  }"
5: "{   "Raum": "Schlafzimmer",    "Temperatur": temp,   "Humidity": hum,  }"
6: "{   "Raum": "Kleines Bad",    "Temperatur": temp,   "Humidity": hum,  }"
7: "{   "Raum": "Großes Bad",    "Temperatur": temp,   "Humidity": hum,  }"
8: "{   "Raum": "Gästezimmer",    "Temperatur": temp,   "Humidity": hum,  }"
9: "{   "Raum": "Küche",    "Temperatur": temp,   "Humidity": hum,  }"

The array itself is fine, but the issue (I think) is that each value is a string enclosed in " ".
The table node doesn't seem to know what to do with that.

Is there a way to create my data array without each entry being enclosed in " "?
In the first functions that build each of those entries I have to assign a string to the payload, otherwhise it complains about the structur I try to put into the payload.
The payload would be: { "Raum": "Büro", "Temperatur": temp, "Humidity": hum, }

I mitigated it by using join nodes only and then using payload[0][0], payload [0][1], payload[1][0] and so on, but that way the values are never in the correct order and my rooms, temperatures and humidity will be mixed around.

In short words: how can I remove the " " in my final function? :smiley:

I hope my request isn't too complicated :S

As you have concatenated the % and C to your payload you have made them strings if they where numbers already. best to not add the % and C. You can add them when you display the data in the table.

Then you can guarantee the payloads are numbers by doing

temp = Number(msg.payload[1]);
hum = Number(msg.payload[0]);
1 Like

You, sir, are amazing!
That did the trick! :slight_smile:

Thank you so very much!

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