Changing message properties

Hi!
I have an exec node that run a python script, my python script has a while structure that sends several data once every 1 second, and the payload message that I receive isn't the same, and the payload name property is the same, so, how can I change the payload name property?
Now I am receiving the following data:

payload: "Date: 2018/07/23 16:38:49 -- Speed: 0 kph".
payload: "Date: 2018/07/23 16:38:49 -- Gas Level: 90%".

I want to change the first payload name to "payload.speed", and the second to "payload.gaslvl" and so on, like the following examples.

payload.speed: "Date: 2018/07/23 16:38:49 -- Speed: 0 kph".
payload.gaslvl: "Date: 2018/07/23 16:38:49 -- Gas Level: 90%".
payload.rpm ...

How can I solve this?

take a look at the change node or do it in a function node after your exec node.

But most nodes expect the important data to be in msg.payload so you might find there are issues if you are attaching further nodes

1 Like

That can be achieved with switch and change nodes. Below code will produce:

r-01

Flow:

[{"id":"a2e8b28c.0ceb4","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"b325c167.3cc55","type":"inject","z":"a2e8b28c.0ceb4","name":"speed","topic":"speed","payload":"Date: 2018/07/23 16:38:49 -- Speed: 0 kph","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":160,"wires":[["fe111fea.f6642"]]},{"id":"af3463f6.fab3f","type":"change","z":"a2e8b28c.0ceb4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.speed","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":160,"wires":[["53460eaf.2830d"]]},{"id":"fe111fea.f6642","type":"switch","z":"a2e8b28c.0ceb4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"Speed","vt":"str"},{"t":"cont","v":"Gas Level","vt":"str"},{"t":"cont","v":"rpm","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":370,"y":200,"wires":[["af3463f6.fab3f"],["7cbf68a.ac0eb98"],["b4a5708a.7c78c"]]},{"id":"7cbf68a.ac0eb98","type":"change","z":"a2e8b28c.0ceb4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.gaslvl","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":200,"wires":[["de46d686.4c6df8"]]},{"id":"b4a5708a.7c78c","type":"change","z":"a2e8b28c.0ceb4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.rpm","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":240,"wires":[["eaf846cd.41b418"]]},{"id":"53460eaf.2830d","type":"debug","z":"a2e8b28c.0ceb4","name":"speed","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":790,"y":160,"wires":[]},{"id":"de46d686.4c6df8","type":"debug","z":"a2e8b28c.0ceb4","name":"gaslvl","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":790,"y":200,"wires":[]},{"id":"eaf846cd.41b418","type":"debug","z":"a2e8b28c.0ceb4","name":"rpm","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.rpm","x":790,"y":240,"wires":[]},{"id":"166f93fd.c9e6bc","type":"inject","z":"a2e8b28c.0ceb4","name":"gaslvl","topic":"gaslvl","payload":"\"Date: 2018/07/23 16:38:49 -- Gas Level: 90%\".","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":220,"wires":[["fe111fea.f6642"]]}]

1 Like

Or, by moving the properties up 1 level to msg.speed, msg.gaslvl with 1 change node:

[{"id":"d605f6dc.c15438","type":"debug","z":"71dfb460.a1afbc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":570,"y":380,"wires":[]},{"id":"9fc6ee1c.a04a2","type":"inject","z":"71dfb460.a1afbc","name":"","topic":"","payload":"Date: 2018/07/23 16:38:49 -- Speed: 0 kph","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":360,"wires":[["18435e7b.448a92"]]},{"id":"14a96805.6fb558","type":"inject","z":"71dfb460.a1afbc","name":"","topic":"","payload":"Date: 2018/07/23 16:38:49 -- Gas Level: 90%","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":400,"wires":[["18435e7b.448a92"]]},{"id":"18435e7b.448a92","type":"change","z":"71dfb460.a1afbc","name":"","rules":[{"t":"set","p":"speed","pt":"msg","to":"$contains(payload, \"Speed\") ? payload : \"\"","tot":"jsonata"},{"t":"set","p":"gaslvl","pt":"msg","to":"$contains(payload, \"Gas\") ? payload : \"\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":380,"wires":[["d605f6dc.c15438"]]}]

Screenshot%20at%202018-07-25%2016-00-42

1 Like

Thank you for your help! It solve my problem.

1 Like

Thank you for your help!

Thank you for your help ghayne!

Thank you ukmoose for your help ^^