Data from different sensors in ui_table

Hello dear forum members,

I am a newbie and have the following problem:

I get data from different sensors (MQTT) and want to display them in the Ui table, but the data does not update with my flow. What do I have to do?

[
    {
        "id": "b1ec35adc40711d3",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": ""
    },
    {
        "id": "ac8a34a64dae7348",
        "type": "function",
        "z": "b1ec35adc40711d3",
        "name": "",
        "func": "if (msg.payload.Außen_L >= 2) {\n    Außen_T = msg.payload.Außen_T\n    Außen_L = msg.payload.Außen_L\n}\n\nif (msg.SCHLAFEN_T >= 2) {\n    SCHLAFEN_T = msg.SCHLAFEN_T\n    SCHLAFEN_L = msg.SCHLAFEN_L\n}\n\n\nif (msg.WEK_T >= 2) {\n    WEK_T = msg.WEK_T\n    WEK_L = msg.WEK_L\n}\n\n\nif (msg.ZIMMER_T >= 2) {\n    ZIMMER_T = msg.ZIMMER_T\n    ZIMMER_L = msg.ZIMMER_L\n}\n\nif (msg.payload.HWR_T >= 2) {\n    HWR_T = msg.payload.HWR_T\n    HWR_L = msg.payload.HWR_L\n}\n\nif (msg.TECHNIK_T > 2) {\n    TECHNIK_T = msg.TECHNIK_T\n    TECHNIK_L = msg.TECHNIK_L\n}\n\n\nvar data = [\n            {\n                \"raum\":\"WEK\",\n                \"temp\": WEK_T + \"°C\",\n                \"humidity\":WEK_L + \"%\",\n                \"quality\": 0\n            },\n            {\n                \"raum\":\"HWR\",\n                \"temp\": HWR_T + \"°C\",\n                \"humidity\":HWR_L+ \"%\",\n                \"quality\": 0\n\n            },\n            {\n                \"raum\":\"Schlafen\",\n                \"temp\":SCHLAFEN_T + \"°C\",\n                \"humidity\":SCHLAFEN_L+ \"%\",\n                \"quality\": 0\n\n            },\n            {\n                \"raum\":\"Bad\",\n                \"temp\": HWR_T + \"°C\",\n                \"humidity\":HWR_L + \"%\",\n                \"quality\": 0\n            },\n                        {\n                \"raum\":\"ZIMMER\",\n                \"temp\": ZIMMER_T + \"°C\",\n                \"humidity\":ZIMMER_L + \"%\",\n                \"quality\": 0\n            },\n            {\n                \"raum\":\"Technik\",\n                \"temp\": TECHNIK_T + \"°C\",\n                \"humidity\":TECHNIK_L + \"%\",\n                \"quality\": 0\n\n            }\n            ];\nmsg.payload = data;\n            \n            \nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 600,
        "y": 200,
        "wires": [
            [
                "9c8b2bda7a401e75"
            ]
        ]
    },
    {
        "id": "9c8b2bda7a401e75",
        "type": "change",
        "z": "b1ec35adc40711d3",
        "name": "ui_control",
        "rules": [
            {
                "t": "set",
                "p": "ui_control",
                "pt": "msg",
                "to": "{\"tabulator\":{\"headerVisible\":false,\"movableColumns\":false}}",
                "tot": "json"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 800,
        "y": 200,
        "wires": [
            [
                "aa80fc821055ef1c"
            ]
        ]
    },
    {
        "id": "aa80fc821055ef1c",
        "type": "ui_table",
        "z": "b1ec35adc40711d3",
        "group": "951f63e6.78df",
        "name": "",
        "order": 1,
        "width": 4,
        "height": 3,
        "columns": [
            {
                "field": "raum",
                "title": "Raum",
                "width": "",
                "align": "left",
                "formatter": "plaintext",
                "formatterParams": {
                    "target": "_blank"
                }
            },
            {
                "field": "temp",
                "title": "Age",
                "width": "",
                "align": "left",
                "formatter": "plaintext",
                "formatterParams": {
                    "target": "_blank"
                }
            },
            {
                "field": "humidity",
                "title": "humidity",
                "width": "",
                "align": "left",
                "formatter": "plaintext",
                "formatterParams": {
                    "target": "_blank"
                }
            },
            {
                "field": "quality",
                "title": "Quality",
                "width": "5",
                "align": "center",
                "formatter": "traffic",
                "formatterParams": {
                    "target": "_blank"
                }
            }
        ],
        "outputs": 0,
        "cts": false,
        "x": 950,
        "y": 220,
        "wires": []
    },
    {
        "id": "e04b9a488383cbea",
        "type": "function",
        "z": "b1ec35adc40711d3",
        "name": "",
        "func": "msg.WEK_T = msg.payload.tempc;\nmsg.WEK_L = msg.payload.hum;\n\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 260,
        "y": 260,
        "wires": [
            [
                "ac8a34a64dae7348"
            ]
        ]
    },
    {
        "id": "39d8189369ea0271",
        "type": "function",
        "z": "b1ec35adc40711d3",
        "name": "",
        "func": "msg.ZIMMER_T = msg.payload.tempc;\nmsg.ZIMMER_L = msg.payload.hum;\n\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 260,
        "y": 380,
        "wires": [
            [
                "ac8a34a64dae7348"
            ]
        ]
    },
    {
        "id": "e99c7938475fc2dd",
        "type": "function",
        "z": "b1ec35adc40711d3",
        "name": "",
        "func": "msg.SCHLAFEN_T = msg.payload.tempc;\nmsg.SCHLAFEN_L = msg.payload.hum;\n\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 280,
        "y": 320,
        "wires": [
            [
                "ac8a34a64dae7348"
            ]
        ]
    },
    {
        "id": "e8f9d1f860fdbcfa",
        "type": "function",
        "z": "b1ec35adc40711d3",
        "name": "",
        "func": "msg.TECHNIK_T = msg.payload.tempc;\nmsg.TECHNIK_L = msg.payload.hum;\n\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 280,
        "y": 440,
        "wires": [
            [
                "ac8a34a64dae7348"
            ]
        ]
    },
    {
        "id": "ffd23ed0bdefb8a1",
        "type": "mqtt in",
        "z": "b1ec35adc40711d3",
        "name": "WEK",
        "topic": "home/temperaturen/MQTTGateway_ESP32_BLE/BTtoMQTT/A4C13867EFB9",
        "qos": "2",
        "datatype": "json",
        "broker": "",
        "nl": false,
        "rap": true,
        "rh": 0,
        "x": 110,
        "y": 260,
        "wires": [
            [
                "e04b9a488383cbea"
            ]
        ]
    },
    {
        "id": "1960ccd73fc798c0",
        "type": "mqtt in",
        "z": "b1ec35adc40711d3",
        "name": "ZIMMER",
        "topic": "home/temperaturen/MQTTGateway_ESP32_BLE/BTtoMQTT/A4C138B5B9AE",
        "qos": "2",
        "datatype": "json",
        "broker": "",
        "nl": false,
        "rap": true,
        "rh": 0,
        "x": 120,
        "y": 380,
        "wires": [
            [
                "39d8189369ea0271"
            ]
        ]
    },
    {
        "id": "0a15cff1a8805bfb",
        "type": "mqtt in",
        "z": "b1ec35adc40711d3",
        "name": "TECHNIK",
        "topic": "home/temperaturen/MQTTGateway_ESP32_BLE/BTtoMQTT/A4C1388BB69C",
        "qos": "2",
        "datatype": "json",
        "broker": "",
        "nl": false,
        "rap": true,
        "rh": 0,
        "x": 120,
        "y": 440,
        "wires": [
            [
                "e8f9d1f860fdbcfa"
            ]
        ]
    },
    {
        "id": "f5cfe461fa811f77",
        "type": "mqtt in",
        "z": "b1ec35adc40711d3",
        "name": "SCHLAFEN",
        "topic": "home/temperaturen/MQTTGateway_ESP32_BLE/BTtoMQTT/A4C13892A4D2",
        "qos": "2",
        "datatype": "json",
        "broker": "",
        "nl": false,
        "rap": true,
        "rh": 0,
        "x": 130,
        "y": 320,
        "wires": [
            [
                "e99c7938475fc2dd"
            ]
        ]
    },
    {
        "id": "71aa81af7ecd0e04",
        "type": "mqtt in",
        "z": "b1ec35adc40711d3",
        "name": "",
        "topic": "homie/Raumqualitaet/#",
        "qos": "2",
        "datatype": "json",
        "broker": "",
        "nl": false,
        "rap": true,
        "rh": 0,
        "x": 160,
        "y": 180,
        "wires": [
            [
                "ac8a34a64dae7348"
            ]
        ]
    },
    {
        "id": "951f63e6.78df",
        "type": "ui_group",
        "name": "Garage",
        "tab": "83822f15.889e6",
        "order": 2,
        "disp": false,
        "width": "10"
    },
    {
        "id": "83822f15.889e6",
        "type": "ui_tab",
        "name": "Garage",
        "icon": "fa-car",
        "order": 1
    }
]

These are the data from 2 sensors as an example:
image
image

I look forward to your help

Welcome to the forum.

You have to revise the logic in the function node that is in front of the ui table node. Apparently the function node is not generating a well formated array of objects. Don´t you get error messages in the side panel when data comes from MQTT nodes ? I did a quick testing hard coding some variables and could see the table being updated. Tip: add a debug node after the function node to better understand the data being fed to the ui table node.


a3

[{"id":"171246f9.1a5e29","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"e7dbc266.f7819","type":"function","z":"171246f9.1a5e29","name":"","func":"\nvar data = [\n            {\n                \"raum\":\"WEK\",\n                \"temp\": 40 + \"°C\",\n                \"humidity\": 45 + \"%\",\n                \"quality\": 0\n            },\n            {\n                \"raum\":\"HWR\",\n                \"temp\": 90 + \"°C\",\n                \"humidity\": 95 + \"%\",\n                \"quality\": 0\n\n            },\n            {\n                \"raum\":\"Schlafen\",\n                \"temp\": 80 + \"°C\",\n                \"humidity\": 85+ \"%\",\n                \"quality\": 0\n\n            },\n            {\n                \"raum\":\"Bad\",\n                \"temp\": 90 + \"°C\",\n                \"humidity\": 95 + \"%\",\n                \"quality\": 0\n            },\n                        {\n                \"raum\":\"ZIMMER\",\n                \"temp\": 70 + \"°C\",\n                \"humidity\": 75 + \"%\",\n                \"quality\": 0\n            },\n            {\n                \"raum\":\"Technik\",\n                \"temp\": 60 + \"°C\",\n                \"humidity\": 65 + \"%\",\n                \"quality\": 0\n\n            }\n            ];\nmsg.payload = data;\n            \n            \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":260,"wires":[["81f562e2.f746e","b9666c28.e1cb8"]]},{"id":"81f562e2.f746e","type":"change","z":"171246f9.1a5e29","name":"ui_control","rules":[{"t":"set","p":"ui_control","pt":"msg","to":"{\"tabulator\":{\"headerVisible\":false,\"movableColumns\":false}}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":260,"wires":[["a59da387.c0c2c"]]},{"id":"a59da387.c0c2c","type":"ui_table","z":"171246f9.1a5e29","group":"951f63e6.78df","name":"","order":1,"width":"8","height":"4","columns":[{"field":"raum","title":"Raum","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"temp","title":"Age","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"humidity","title":"humidity","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"quality","title":"Quality","width":"5","align":"center","formatter":"traffic","formatterParams":{"target":"_blank"}}],"outputs":0,"cts":false,"x":790,"y":260,"wires":[]},{"id":"a892d71a.4b75e8","type":"function","z":"171246f9.1a5e29","name":"","func":"msg.WEK_T = 10;\nmsg.WEK_L = 15;\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":260,"y":260,"wires":[["e7dbc266.f7819"]]},{"id":"2e67d047.a2dd1","type":"function","z":"171246f9.1a5e29","name":"","func":"msg.ZIMMER_T = 30;\nmsg.ZIMMER_L = 35;\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":260,"y":380,"wires":[["e7dbc266.f7819"]]},{"id":"5c5f53b5.f7cfdc","type":"function","z":"171246f9.1a5e29","name":"","func":"msg.SCHLAFEN_T = 20;\nmsg.SCHLAFEN_L = 25;\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":320,"wires":[["e7dbc266.f7819"]]},{"id":"dbb85b53.260af8","type":"function","z":"171246f9.1a5e29","name":"","func":"msg.TECHNIK_T = 40;\nmsg.TECHNIK_L = 45;\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":440,"wires":[["e7dbc266.f7819"]]},{"id":"eddd3f5b.647c6","type":"inject","z":"171246f9.1a5e29","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":260,"wires":[["a892d71a.4b75e8"]]},{"id":"215ade61.7de2b2","type":"inject","z":"171246f9.1a5e29","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":320,"wires":[["5c5f53b5.f7cfdc"]]},{"id":"944b32b2.05205","type":"inject","z":"171246f9.1a5e29","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":380,"wires":[["2e67d047.a2dd1"]]},{"id":"bc692413.34bba8","type":"inject","z":"171246f9.1a5e29","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":440,"wires":[["dbb85b53.260af8"]]},{"id":"b9666c28.e1cb8","type":"debug","z":"171246f9.1a5e29","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":360,"wires":[]},{"id":"951f63e6.78df","type":"ui_group","name":"Garage","tab":"83822f15.889e6","order":2,"disp":false,"width":"10"},{"id":"83822f15.889e6","type":"ui_tab","name":"Garage","icon":"fa-car","order":1}]

Yes that's how it works with updating.

The problem is when I get a sensor data via MQTT, all other data from the other sensors is set to undefined.

Please put a debug node (set to display the complete msg object) on the output of the "homie/Raumqualitaet/#" mqtt-in node so we can see what the data looks like from it.

The way I normally handle that is building and persisting a master table in memory. Each time a reading arrives from the MQTT the master table is updated and the full table is sent to the ui table node. Your logic has to find the array index of the element to be updated. If the element does not exist in the master table then you add it dinamically. It is simple to implement the logic by using the JavaScript array method "findIndex".

Here is how a function node would looks like for your use case.

let masterTable = global.get("masterTable") || 
    [ {
        "raum":"WEK",
        "temp": 0 + "°C",
        "humidity":0 + "%",
        "quality": 0
    }];



let pay = msg.payload;
let topic = msg.topic;


// Seach masterTable for "raum". Search will return index of object in the array or -1 if not found
let row = masterTable.findIndex(element => element.raum == topic);


if (row == -1) {
    addElement = {"raum" : topic, "temp" : pay.tempc, "humidity" : pay.hum, "quality" : 0};
    masterTable.push(addElement)
} else {
    updateElement = {"raum" : topic, "temp" : pay.tempc, "humidity" : pay.hum, "quality" : 0};
    masterTable[row] = updateElement;
}


global.set("masterTable", masterTable);
msg.payload = masterTable;
            
            
return msg;

and here is a testing flow for you to play and improve. I did not tested it thoroughly.

[{"id":"29874c30.b81134","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"dba55a94.80f728","type":"function","z":"29874c30.b81134","name":"MasterTable","func":"let masterTable = global.get(\"masterTable\") || \n    [ {\n        \"raum\":\"WEK\",\n        \"temp\": 0 + \"°C\",\n        \"humidity\":0 + \"%\",\n        \"quality\": 0\n    }];\n\n\n\nlet pay = msg.payload;\nlet topic = msg.topic;\n\n\n// Seach masterTable for \"raum\". Search will return index of object in the array or -1 if not found\nlet row = masterTable.findIndex(element => element.raum == topic);\n\n\nif (row == -1) {\n    addElement = {\"raum\" : topic, \"temp\" : pay.tempc, \"humidity\" : pay.hum, \"quality\" : 0};\n    masterTable.push(addElement)\n} else {\n    updateElement = {\"raum\" : topic, \"temp\" : pay.tempc, \"humidity\" : pay.hum, \"quality\" : 0};\n    masterTable[row] = updateElement;\n}\n\n\nglobal.set(\"masterTable\", masterTable);\nmsg.payload = masterTable;\n            \n            \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":410,"y":200,"wires":[["beac1939.164f18","2b20ffd1.a3296"]]},{"id":"2b20ffd1.a3296","type":"ui_table","z":"29874c30.b81134","group":"951f63e6.78df","name":"","order":1,"width":"8","height":"4","columns":[{"field":"raum","title":"Raum","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"temp","title":"Age","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"humidity","title":"humidity","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"quality","title":"Quality","width":"5","align":"center","formatter":"traffic","formatterParams":{"target":"_blank"}}],"outputs":0,"cts":false,"x":570,"y":200,"wires":[]},{"id":"849db0ce.6ea46","type":"inject","z":"29874c30.b81134","name":"","props":[{"p":"topic","vt":"str"},{"p":"payload.tempc","v":"10","vt":"num"},{"p":"payload.hum","v":"15","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"WEK","payloadType":"str","x":150,"y":200,"wires":[["dba55a94.80f728"]]},{"id":"aff65be4.5ff5c8","type":"inject","z":"29874c30.b81134","name":"","props":[{"p":"topic","vt":"str"},{"p":"payload.tempc","v":"10","vt":"num"},{"p":"payload.hum","v":"15","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"SCHLAFEN","payloadType":"str","x":130,"y":260,"wires":[["dba55a94.80f728"]]},{"id":"c91f87f9.eced28","type":"inject","z":"29874c30.b81134","name":"","props":[{"p":"topic","vt":"str"},{"p":"payload.tempc","v":"10","vt":"num"},{"p":"payload.hum","v":"15","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ZIMMER","x":140,"y":380,"wires":[["dba55a94.80f728"]]},{"id":"86f7412e.d93b6","type":"inject","z":"29874c30.b81134","name":"","props":[{"p":"topic","vt":"str"},{"p":"payload.tempc","v":"10","vt":"num"},{"p":"payload.hum","v":"15","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"TECHNIK","payloadType":"str","x":140,"y":440,"wires":[["dba55a94.80f728"]]},{"id":"beac1939.164f18","type":"debug","z":"29874c30.b81134","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":570,"y":280,"wires":[]},{"id":"982a9be2.ad1a28","type":"inject","z":"29874c30.b81134","name":"","props":[{"p":"topic","vt":"str"},{"p":"payload.tempc","v":"20","vt":"num"},{"p":"payload.hum","v":"25","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"SCHLAFEN","x":130,"y":320,"wires":[["dba55a94.80f728"]]},{"id":"951f63e6.78df","type":"ui_group","name":"Garage","tab":"83822f15.889e6","order":2,"disp":false,"width":"10"},{"id":"83822f15.889e6","type":"ui_tab","name":"Garage","icon":"fa-car","order":1}]