Best way to restructure the msg.payload

I am really strugging to know the best way to change the msg.payload

if I have 6 device all giving out there msg.payload all the same format how do I pull the elements out (they all have same set of element (eg name,time,value ) so I can get setup for an excel chart (i know the file out option) It's more the best way to get the data in to the correct order ,eg names for each of message in the first line and then the time value listed below (or am I just looking at this all wrong

Please keep as simple as poss

Hi @gbond

it would help if you could provide some examples of the messages you have, and an example of what sort out output you'd like to get it to.

[{"id":"3c134a0a.2a5f26","type":"tab","label":"Motion","disabled":false,"info":""},{"id":"388811e0.133d4e","type":"smartthings-node-motion","z":"3c134a0a.2a5f26","conf":"a93055a9.084878","name":"Bathroom Motion Sensor","device":"c374ae8e-5a01-4218-bef4-410960202c25","x":390,"y":40,"wires":[["72bd20d4.2d181","86bcd1ee.6c486","b3e82316.f83e2"]]},{"id":"72bd20d4.2d181","type":"ui_text","z":"3c134a0a.2a5f26","group":"f969a4f6.ea9838","order":4,"width":0,"height":0,"name":"","label":"{{msg.payload.name}}.","format":"{{msg.payload.value}}","layout":"row-spread","x":610,"y":40,"wires":},{"id":"fb594bcf.7ac468","type":"ui_text","z":"3c134a0a.2a5f26","group":"f969a4f6.ea9838","order":5,"width":0,"height":0,"name":"","label":"{{msg.payload.name}}.","format":"{{msg.payload.value}}","layout":"row-spread","x":610,"y":160,"wires":},{"id":"636d8c84.6741c4","type":"smartthings-node-motion","z":"3c134a0a.2a5f26","conf":"a93055a9.084878","name":"cabin light-sensor","device":"d0b457db-87cf-4ed0-9513-8bc9fceef471","x":370,"y":160,"wires":[["fb594bcf.7ac468","7fb5c9af.e53b88","b3e82316.f83e2"]]},{"id":"88ee7022.2d086","type":"ui_text","z":"3c134a0a.2a5f26","group":"f969a4f6.ea9838","order":6,"width":0,"height":0,"name":"","label":"{{msg.payload.name}}.","format":"{{msg.payload.value}}","layout":"row-spread","x":610,"y":120,"wires":},{"id":"5f3b3b9b.c036c4","type":"ui_text","z":"3c134a0a.2a5f26","group":"f969a4f6.ea9838","order":7,"width":0,"height":0,"name":"","label":"{{msg.payload.name}}.","format":"{{msg.payload.value}}","layout":"row-spread","x":610,"y":80,"wires":},{"id":"b6a179e7.cb14f8","type":"smartthings-node-motion","z":"3c134a0a.2a5f26","conf":"a93055a9.084878","name":"Bunny shed light-sensor","device":"21fcf9d5-dd19-477f-9181-2be20b02d263","x":390,"y":80,"wires":[["5f3b3b9b.c036c4","439bd794.38ed18","b3e82316.f83e2"]]},{"id":"d07beb34.d147b8","type":"ui_text","z":"3c134a0a.2a5f26","group":"f969a4f6.ea9838","order":8,"width":0,"height":0,"name":"","label":"{{msg.payload.name}}.","format":"{{msg.payload.value}}","layout":"row-spread","x":610,"y":200,"wires":},{"id":"3e1aefe8.00d1b","type":"smartthings-node-motion","z":"3c134a0a.2a5f26","conf":"a93055a9.084878","name":"kitchen Motion Sensor","device":"d22cde06-dc4c-41e7-8735-d8feda564817","x":380,"y":200,"wires":[["d07beb34.d147b8","fd9540f3.8c1dd","b3e82316.f83e2"]]},{"id":"b3a902bb.dd39a","type":"ui_text","z":"3c134a0a.2a5f26","d":true,"group":"f969a4f6.ea9838","order":9,"width":0,"height":0,"name":"","label":"{{msg.payload.name}}.","format":"{{msg.payload.value}}","layout":"row-spread","x":610,"y":240,"wires":},{"id":"c31ae69d.8f7f78","type":"smartthings-node-motion","z":"3c134a0a.2a5f26","d":true,"conf":"a93055a9.084878","name":"utility Sensor(hue)","device":"bb9d4557-6b07-455d-af08-0294f0d7bcaa","x":370,"y":240,"wires":[["b3a902bb.dd39a","2cfbc61c.0e313a","b3e82316.f83e2"]]},{"id":"86bcd1ee.6c486","type":"change","z":"3c134a0a.2a5f26","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload.name","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":40,"wires":[["c9feb698.6dc8b8","8f8558e3.faf7e8"]]},{"id":"c9feb698.6dc8b8","type":"ui_chart","z":"3c134a0a.2a5f26","name":"","group":"e617cdb4.e35c5","order":2,"width":"7","height":"4","label":"Bathroom Chart","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"step","nodata":"","dot":true,"ymin":"0","ymax":"1","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#ff0000","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1020,"y":40,"wires":[]},{"id":"fd9540f3.8c1dd","type":"change","z":"3c134a0a.2a5f26","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload.name","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":200,"wires":[["a2834582.d8d8c8","8f8558e3.faf7e8"]]},{"id":"439bd794.38ed18","type":"change","z":"3c134a0a.2a5f26","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload.name","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":80,"wires":[["de2abc3c.20782","8f8558e3.faf7e8"]]},{"id":"7fb5c9af.e53b88","type":"change","z":"3c134a0a.2a5f26","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload.name","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":160,"wires":[["de2abc3c.20782","8f8558e3.faf7e8"]]},{"id":"2cfbc61c.0e313a","type":"change","z":"3c134a0a.2a5f26","d":true,"name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload.name","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":240,"wires":[["de2abc3c.20782","8f8558e3.faf7e8"]]},{"id":"a2834582.d8d8c8","type":"ui_chart","z":"3c134a0a.2a5f26","name":"","group":"e617cdb4.e35c5","order":1,"width":"7","height":"4","label":"Kitchen/Front Chart","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"step","nodata":"","dot":true,"ymin":"0","ymax":"1","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#ff0000","#0000ff","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1050,"y":160,"wires":[]},{"id":"de2abc3c.20782","type":"ui_chart","z":"3c134a0a.2a5f26","name":"","group":"e617cdb4.e35c5","order":3,"width":"7","height":"4","label":"everything else Chart","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"step","nodata":"","dot":true,"ymin":"0","ymax":"1","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#ff0000","#0000ff","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1060,"y":80,"wires":[]},{"id":"8a65f67.9d69f08","type":"inject","z":"3c134a0a.2a5f26","name":"","topic":"update","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":40,"wires":[["3e1aefe8.00d1b","388811e0.133d4e","b6a179e7.cb14f8","636d8c84.6741c4","deae78a5.46de98"]]},{"id":"deae78a5.46de98","type":"smartthings-node-motion","z":"3c134a0a.2a5f26","conf":"a93055a9.084878","name":"Front Door","device":"d1ab3f1a-4aa2-4aad-bd2f-69b650b898a6","x":350,"y":120,"wires":[["88ee7022.2d086","ec4c26f1.acdb28","b3e82316.f83e2"]]},{"id":"ec4c26f1.acdb28","type":"change","z":"3c134a0a.2a5f26","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload.name","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":120,"wires":[["a2834582.d8d8c8","8f8558e3.faf7e8"]]},{"id":"8f8558e3.faf7e8","type":"function","z":"3c134a0a.2a5f26","name":"","func":"\nreturn msg;","outputs":1,"noerr":0,"x":1010,"y":280,"wires":[["91a2daa9.0f2948"]]},{"id":"91a2daa9.0f2948","type":"ui_chart","z":"3c134a0a.2a5f26","name":"","group":"691e0586.ec56bc","order":1,"width":"7","height":"8","label":"all motion","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":true,"ymin":"0","ymax":"1","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#ffff80","#0000ff","#ff7f0e","#ff0000","#804000","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1180,"y":280,"wires":[]},{"id":"243f1314.09dccc","type":"file","z":"3c134a0a.2a5f26","name":"","filename":"Documents/node-red/motion.txt","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":990,"y":460,"wires":[]},{"id":"f4645579.93bcc8","type":"json","z":"3c134a0a.2a5f26","name":"","property":"payload","action":"","pretty":true,"x":790,"y":460,"wires":[["243f1314.09dccc"]]},{"id":"b529d1ae.9b267","type":"csv","z":"3c134a0a.2a5f26","name":"","sep":",","hdrin":false,"hdrout":false,"multi":"mult","ret":"\r","temp":"name,value","skip":"0","strings":true,"x":790,"y":500,"wires":[["567eb203.b7038c"]]},{"id":"567eb203.b7038c","type":"file","z":"3c134a0a.2a5f26","name":"","filename":"Documents/node-red/motion.csv","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":990,"y":500,"wires":[]},{"id":"b3e82316.f83e2","type":"link out","z":"3c134a0a.2a5f26","name":"motion","links":["6c9b9e44.b2032"],"x":575,"y":280,"wires":},{"id":"6c9b9e44.b2032","type":"link in","z":"3c134a0a.2a5f26","name":"","links":["b3e82316.f83e2"],"x":55,"y":460,"wires":[["90455ea8.8317f"]]},{"id":"a6489b95.6b7158","type":"function","z":"3c134a0a.2a5f26","name":"Time stamp","func":"msg.payload.time = new Date().toLocaleString();\nreturn msg;\n\n[{"name":"kitchen Motion Sensor","value":1},{"name":"Bathroom Motion Sensor","value":0},{"name":"Bunny shed light-sensor","value":0},{"name":"cabin light-sensor","value":0},{"name":"Front Door","value":0}]","outputs":1,"noerr":0,"x":330,"y":560,"wires":[]},{"id":"d7928e3f.341f6","type":"debug","z":"3c134a0a.2a5f26","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":810,"y":420,"wires":},{"id":"90455ea8.8317f","type":"change","z":"3c134a0a.2a5f26","name":"","rules":[{"t":"delete","p":"payload.deviceId","pt":"msg"},{"t":"delete","p":"payload.deviceType","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":460,"wires":[["3b0f48b1.6d8698","52a19f14.29cda"]]},{"id":"22d546b9.42179a","type":"file","z":"3c134a0a.2a5f26","name":"","filename":"Documents/node-red/motion.txt","appendNewline":true,"createDir":true,"overwriteFile":"delete","encoding":"none","x":390,"y":340,"wires":[]},{"id":"3879ff51.608f8","type":"inject","z":"3c134a0a.2a5f26","name":"Delete files","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":340,"wires":[["22d546b9.42179a","f84455c5.d97e88"]]},{"id":"f84455c5.d97e88","type":"file","z":"3c134a0a.2a5f26","name":"","filename":"Documents/node-red/motion.csv","appendNewline":true,"createDir":true,"overwriteFile":"delete","encoding":"none","x":400,"y":380,"wires":[]},{"id":"3b0f48b1.6d8698","type":"join","z":"3c134a0a.2a5f26","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"","count":"5","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":550,"y":460,"wires":[["b529d1ae.9b267","f4645579.93bcc8","d7928e3f.341f6"]]},{"id":"52a19f14.29cda","type":"debug","z":"3c134a0a.2a5f26","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":470,"y":420,"wires":},{"id":"a93055a9.084878","type":"smartthings-config","z":"","name":"zorin52.core token","token":"e8909498-eaac-462b-8d85-2eb245f3a22a"},{"id":"f969a4f6.ea9838","type":"ui_group","z":"","name":"Presence","tab":"f259fad.dccce08","order":3,"disp":true,"width":"6","collapse":false},{"id":"e617cdb4.e35c5","type":"ui_group","z":"","name":"Motion","tab":"76ee07bf.70ebb8","disp":true,"width":"8","collapse":false},{"id":"691e0586.ec56bc","type":"ui_group","z":"","name":"Charts","tab":"f259fad.dccce08","order":2,"disp":true,"width":"10","collapse":false},{"id":"f259fad.dccce08","type":"ui_tab","z":"","name":"Smartthings","icon":"mi-dashboard","order":2,"disabled":false,"hidden":false},{"id":"76ee07bf.70ebb8","type":"ui_tab","z":"","name":"Motion","icon":"dashboard","order":4,"disabled":false,"hidden":false}]

does this help

No it doesn't.

I'm interested in the messages you have, not the flow itself.

Your question says you have some messages and you want to get the data in some 'correct order'.

To help us understand what you mean, could you share an example of the messages you have in the flow and an example of what you would like to see.

is this better
object

topic: "update"

payload: object

_msgid: "7c4ae626.e93608"

_event: "node:b3e82316.f83e2"

3/12/2020, 10:57:22 PMnode: 52a19f14.29cdaupdate : msg : Object

object

topic: "update"

payload: object

_msgid: "7c4ae626.e93608"

_event: "node:b3e82316.f83e2"

3/12/2020, 10:57:22 PMnode: 52a19f14.29cdaupdate : msg : Object

object

topic: "update"

payload: object

_msgid: "7c4ae626.e93608"

_event: "node:b3e82316.f83e2"

3/12/2020, 10:57:22 PMnode: 52a19f14.29cdaupdate : msg : Object

{ topic: "update", payload: object, _msgid: "7c4ae626.e93608", _event: "node:b3e82316.f83e2" }

3/12/2020, 10:57:22 PMnode: 52a19f14.29cdaupdate : msg : Object

{ topic: "update", payload: object, _msgid: "7c4ae626.e93608", _event: "node:b3e82316.f83e2" }

sorry is this better
payload: object

deviceId: "d22cde06-dc4c-41e7-8735-d8feda564817"

deviceType: "motion"

name: "kitchen Motion Sensor"

value: 0

_msgid: "a07a1918.a89e18"

_event: "node:b3e82316.f83

For future reference, to copy the message property, hover over it and click the 'Copy value' button that appears:

image

So you have a message with a payload of:

{
    "payload": {
      "deviceId": "d22....",
      "deviceType": "motion",
      "name": "kitchen Motion Sensor",
      "value": 0
   }
}

The next part is to better understand from you what output you are trying to achieve... can you describe it in some more detail? Maybe create an example that mocks up the output you'd like.

kitchen Motion Sensor,Bathroom Motion Sensor,Bunny shed light-sensor,cabin light-sensor,Front Door
date & time,1,0,1,0, 0,0,0,0
date & time,1,0,1,0, 0,0,0,0
date & time,1,0,1,0, 0,0,0,0
etc

I hope you understand

{"topic":"update","payload":{"deviceId":"d22cde06-dc4c-41e7-8735-d8feda564817","deviceType":"motion","name":"kitchen Motion Sensor","value":0},"_msgid":"ead25fae.4e072","_event":"node:b3e82316.f83e2"}

{"topic":"update","payload":{"deviceId":"c374ae8e-5a01-4218-bef4-410960202c25","deviceType":"motion","name":"Bathroom Motion Sensor","value":0},"_msgid":"ead25fae.4e072","_event":"node:b3e82316.f83e2"}

etc

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