Splitting and converting values

Hello everyone,

I have an question ab my data visualised on my dashboard. As you can see in the picture below is all the data from the array just dropped in the text node. I would like to split it at the "," so you can see every name at an different line.

The values on the middle and on the right are a time, i would like to print it as the utc time instead of the version i become right now...

can anyone help me out please.

This is the flow:

[{"id":"295715674564e86f","type":"tab","label":"Laadpalen uitlezen","disabled":false,"info":"","env":[]},{"id":"b78e4954f32eefa3","type":"ui_text","z":"295715674564e86f","group":"c0bd3dba2cb057bf","order":1,"width":0,"height":0,"name":"","label":"Hier komen de meetresultaten","format":"{{msg.payload}}","layout":"row-left","className":"","x":210,"y":40,"wires":[]},{"id":"b141016a44d8acaf","type":"ui_date_picker","z":"295715674564e86f","name":"","label":"Begin datum","group":"772b1b396b59caed","order":1,"width":3,"height":2,"passthru":true,"topic":"begin","topicType":"str","className":"","x":150,"y":80,"wires":[["b9cd7ab11ea4a3e7"]]},{"id":"656a7c4a32c4418f","type":"ui_date_picker","z":"295715674564e86f","name":"","label":"Eind datum","group":"772b1b396b59caed","order":2,"width":3,"height":2,"passthru":true,"topic":"eind","topicType":"str","className":"","x":150,"y":120,"wires":[["b9cd7ab11ea4a3e7"]]},{"id":"b9cd7ab11ea4a3e7","type":"join","z":"295715674564e86f","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":310,"y":100,"wires":[["0fe0de31e4de87cc"]]},{"id":"4cbb380f2c304ba3","type":"template","z":"295715674564e86f","name":"","field":"url","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"https://app1pub.smappee.net/dev/v3/chargingparks/59796/sessions?range={{payload.begin}},{{payload.eind}}\n","output":"str","x":1060,"y":100,"wires":[["2b44e2e2c5cae7d3"]]},{"id":"5e51a4c1ec63d463","type":"link in","z":"295715674564e86f","name":"","links":[],"x":35,"y":40,"wires":[["b78e4954f32eefa3"]]},{"id":"6dcc214ba146ad04","type":"debug","z":"295715674564e86f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1590,"y":40,"wires":[]},{"id":"2b44e2e2c5cae7d3","type":"http request","z":"295715674564e86f","name":"Laadsessies","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":true,"proxy":"","authType":"bearer","senderr":false,"x":1230,"y":100,"wires":[["6762f15b6abbfc8a"]]},{"id":"63c220e43f9bde90","type":"ui_text","z":"295715674564e86f","group":"c0bd3dba2cb057bf","order":2,"width":2,"height":1,"name":"Naam","label":"","format":"{{msg.payload}}","layout":"row-left","className":"","x":1730,"y":80,"wires":[]},{"id":"3c18a8e5678f14bf","type":"ui_text","z":"295715674564e86f","group":"c0bd3dba2cb057bf","order":3,"width":2,"height":1,"name":"Begintijd","label":"heeft geladen van :","format":"{{msg.payload}}","layout":"row-left","className":"","x":1740,"y":120,"wires":[]},{"id":"9dd5c18a2042135d","type":"ui_text","z":"295715674564e86f","group":"c0bd3dba2cb057bf","order":4,"width":2,"height":1,"name":"Eindtijd","label":"tot :","format":"{{msg.payload}}","layout":"row-left","className":"","x":1740,"y":160,"wires":[]},{"id":"6762f15b6abbfc8a","type":"function","z":"295715674564e86f","name":"Laadsessies","func":"//laadsessies koppelen aan tijd\nvar VALUE = global.get('RFID.Token') || [];\nvar NAAM = global.get('RFID.Naam') || [];\nLAADSESSIE=[]; naam_laadsessie = [];\nfor(var i = 0; i <msg.payload.length ; i++){\n for (var x = 0; x< VALUE.length ; x++){\n if (VALUE[x] == msg.payload[i].rfid)\n naam_laadsessie[i] = NAAM[x]}\nLAADSESSIE[i] = [NAAM[i], \"heeft geladen van:\", msg.payload[i].from, \n\"tot:\", msg.payload[i].to ]\n}\n\n//array maken met ggegevens\nconst rotated = {\n Naam: [],\n Begintijd: [],\n Eindtijd: [],\n\n}\n\nconst APIdata = LAADSESSIE;\nfor (var j = 0; j < APIdata.length; j++) {\n rotated.Naam[j] = APIdata[j][0]\n rotated.Begintijd[j] = APIdata[j][2]\n rotated.Eindtijd[j] = APIdata[j][4]\n \n}\n\nmsg.payload = rotated;\n\nvar msg1 = { payload: rotated.Naam };\nvar msg2 = { payload: rotated.Begintijd };\nvar msg3 = { payload: rotated.Eindtijd };\n\nglobal.set('Laadsessie', rotated)\nreturn [msg,msg1,msg2,msg3];\n\n\n","outputs":4,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1410,"y":100,"wires":[["6dcc214ba146ad04"],["a7e50924b9181e4f"],["700b94f940761a09"],["a5be336e94b337bb"]]},{"id":"a7e50924b9181e4f","type":"function","z":"295715674564e86f","name":"","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1580,"y":80,"wires":[["63c220e43f9bde90"]]},{"id":"700b94f940761a09","type":"function","z":"295715674564e86f","name":"","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1580,"y":120,"wires":[["3c18a8e5678f14bf"]]},{"id":"a5be336e94b337bb","type":"function","z":"295715674564e86f","name":"","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1580,"y":160,"wires":[["9dd5c18a2042135d"]]},{"id":"0fe0de31e4de87cc","type":"change","z":"295715674564e86f","name":"","rules":[{"t":"set","p":"headers.Authorization","pt":"msg","to":"\"Bearer \" & $globalContext(\"UserMatrix[5][1]\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":100,"wires":[["4cbb380f2c304ba3"]]},{"id":"6d4f0cb04eddbebe","type":"function","z":"295715674564e86f","name":"","func":"var UserMatrix = global.get(\"UserMatrix\")\n\nmsg.payload= UserMatrix[6][1]\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":100,"wires":[["c2ee86f28cdb7c27"]]},{"id":"c2ee86f28cdb7c27","type":"json","z":"295715674564e86f","name":"","property":"payload","action":"","pretty":false,"x":910,"y":100,"wires":[[]]},{"id":"c0bd3dba2cb057bf","type":"ui_group","name":"Meetgegevens:","tab":"e6a0e46d81483439","order":2,"disp":true,"width":"6","collapse":false,"className":""},{"id":"772b1b396b59caed","type":"ui_group","name":"Vul hier de datums in van het gewenste bereik:","tab":"e6a0e46d81483439","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"e6a0e46d81483439","type":"ui_tab","name":"Laadpalen uitlezen","icon":"dashboard","order":9,"disabled":false,"hidden":true}]


and this is the data i receive:

{"Naam":["GSM Michaƫl","Brecht - Kaart","Brecht - Sleutelhanger","Louis - Kaart","Sofie - Kaart","Gast Suntronics - Kaart","Hans - Kaart"],"Begintijd":[1644906430,1644822887,1644681147,1644668356,1644571470,1644495025,1644219766],"Eindtijd":[1644908814,1644829823,1644685674,1644681140,1644577741,1644513179,1644233981]}

I allready tried this to to change the times... but this wont work

image

It sounds like you will need to put the data into a table as text node is not able to do this.

Here is an example of how to display your data in a table.

[{"id":"323d4bfe.23753c","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"Naam\":[\"GSM Michaƫl\",\"Brecht - Kaart\",\"Brecht - Sleutelhanger\",\"Louis - Kaart\",\"Sofie - Kaart\",\"Gast Suntronics - Kaart\",\"Hans - Kaart\"],\"Begintijd\":[1644906430,1644822887,1644681147,1644668356,1644571470,1644495025,1644219766],\"Eindtijd\":[1644908814,1644829823,1644685674,1644681140,1644577741,1644513179,1644233981]}","payloadType":"json","x":230,"y":160,"wires":[["9859b2cd.2ab078"]]},{"id":"9859b2cd.2ab078","type":"ui_template","z":"bf9e1e33.030598","group":"187a0d10.a44d4b","name":"","order":3,"width":0,"height":0,"format":"<style>\ntable{\n    background:grey;\n    border: 1px;\n    padding: 2px;\n}\nth, td{ \n    text-align: left;\n    border: 1px;\n    padding: 2px;\n}\n\n</style><table>\n    <tr>\n        <th ng-repeat=\"(key, value) in msg.payload\">{{key}}</th>\n    </tr>\n    <tr ng-repeat=\"(index,row) in msg.payload.Naam \">\n        <td>{{msg.payload.Naam[index]}}</td>\n        <td>{{msg.payload.Begintijd[index]*1000 | date : \"yyyy-MM-dd, hh:mm:ss\"}}</td>\n        <td>{{msg.payload.Eindtijd[index]*1000 | date : \"yyyy-MM-dd, hh:mm:ss\"}}</td>\n    </tr>\n</table>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":380,"y":160,"wires":[["651a0ed8.ad7c1"]]},{"id":"651a0ed8.ad7c1","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":40,"wires":[]},{"id":"187a0d10.a44d4b","type":"ui_group","name":"Group 1","tab":"8abb3dd0.ddf87","order":1,"disp":false,"width":"6","collapse":false,"className":""},{"id":"8abb3dd0.ddf87","type":"ui_tab","name":"tab3","icon":"dashboard","order":8,"disabled":false,"hidden":false}]

[edit] fixed error
and formatting of date fields.
Took me a while to realise the timestamps are in unix (seconds) not milliseconds.

Added some css styling.

1 Like

If you feed your msg.payload into this function it will output the data needed to show in a table node

let table_data = []
let input = msg.payload

for (let index = 0; index < input['Naam'].length; index++) {
    table_data.push({
        'Naam': input.Naam[index], 'Begintijd': new Date(input.Begintijd[index] * 1000).toLocaleString("nl-NL"), 'Eindtijd': new Date(input.Eindtijd[index] * 1000).toLocaleString("nl-NL")
    })

}

msg.payload = table_data

return msg;
1 Like

Thank you both for the help ! It works perfect right now !!

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