# Split the string into separate values

**URL:** https://discourse.nodered.org/t/split-the-string-into-separate-values/2818
**Category:** General
**Created:** [4 September 2018 05:40 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818 "2018-09-04T05:40:16Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)
#### Post date: [4 September 2018 08:59 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/21 "2018-09-04T08:59:17Z")

</div>

There is obviously many ways to do this. It is up to you and your experiences and so on. But there is Node-RED way also. (Write less code and use power of dedicated nodes). For you as the beginner I recommend to at least investigate this flow I created.  
`[{"id":"df6d6c66.b6c4e","type":"split","z":"d9f8d1d.5cd143","name":"","splt":",","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":410,"y":820,"wires":[["fe502aa1.ee37c8","3ba2aff1.e8af5"]]},{"id":"d9822859.20a7b8","type":"inject","z":"d9f8d1d.5cd143","name":"","topic":"","payload":"15.4,50,23.8,79","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":"","x":220,"y":820,"wires":[["bc23045.f5103f8","df6d6c66.b6c4e"]]},{"id":"2f990562.44d8ea","type":"debug","z":"d9f8d1d.5cd143","name":"out 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":930,"y":760,"wires":[]},{"id":"fe502aa1.ee37c8","type":"change","z":"d9f8d1d.5cd143","name":"to number","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number(msg.payload)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":820,"wires":[["9052efa8.e5f0a","d6f23ad6.490eb8"]]},{"id":"9052efa8.e5f0a","type":"switch","z":"d9f8d1d.5cd143","name":"route","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":750,"y":820,"wires":[["2f990562.44d8ea"],["35825546.228baa"],["d5e60d8b.47391"],["d97cb86c.da9478"]]},{"id":"35825546.228baa","type":"debug","z":"d9f8d1d.5cd143","name":"out 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":930,"y":800,"wires":[]},{"id":"d5e60d8b.47391","type":"debug","z":"d9f8d1d.5cd143","name":"out 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":930,"y":840,"wires":[]},{"id":"d97cb86c.da9478","type":"debug","z":"d9f8d1d.5cd143","name":"out 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":930,"y":880,"wires":[]},{"id":"2f3bddd7.cf80e2","type":"comment","z":"d9f8d1d.5cd143","name":"split","info":"Split comma separated string into separated messages.\nValue placed to msg.payload\nValue type will be still string.\n\nThere will be 4 messages out of this split node\n\nFor each msg also given a property \"parts\". \nIt will be used later on.","x":410,"y":760,"wires":[]},{"id":"d4a6401f.81de4","type":"comment","z":"d9f8d1d.5cd143","name":"convert","info":"Convert the value of msg.payload to the number using JSONata expression.\n","x":590,"y":760,"wires":[]},{"id":"60cbfa64.9cb4b4","type":"comment","z":"d9f8d1d.5cd143","name":"route","info":"Route every message to differet output by using switch node.\nAs property \"parts\" has been given to each message, we can use its \n\"index\" property to find out proper output\n\n","x":750,"y":760,"wires":[]},{"id":"bc23045.f5103f8","type":"debug","z":"d9f8d1d.5cd143","name":"source data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":410,"y":980,"wires":[]},{"id":"3ba2aff1.e8af5","type":"debug","z":"d9f8d1d.5cd143","name":"spltted","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":530,"y":940,"wires":[]},{"id":"d6f23ad6.490eb8","type":"debug","z":"d9f8d1d.5cd143","name":"converted","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":660,"y":900,"wires":[]}]`

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [4 September 2018 09:37 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/22 "2018-09-04T09:37:33Z")

</div>

Since you are getting the data via MQTT - how do you create the data?

It might be a lot easier if you create the data in a format that will be easy to use in your 'datanode1 function.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [4 September 2018 10:34 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/23 "2018-09-04T10:34:16Z")

</div>

I think splitting a string should not be considered too hard, and is a worthwhile thing to be able to do here.

---

<div class="post-metadata">

### Author: ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)
#### Post date: [4 September 2018 10:40 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/24 "2018-09-04T10:40:58Z")

</div>

As the values are only the values and there is nothing more so the one should guarantee that values coming in always in same order. Or what to do if some value is not there? Yes, the splitting is easy but to keep the meaning or the origin of data is much more important in this case. Creating the data in proper way will come handy in all means.

---

<div class="post-metadata">

### Author: ![Srijan](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Srijan](https://discourse.nodered.org/u/Srijan)
#### Post date: [5 September 2018 05:45 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/25 "2018-09-05T05:45:41Z")

</div>

thanks sir , my problem is resolved  
thanks to all  
for ur time and help.

---

<div class="post-metadata">

### Author: ![Srijan](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Srijan](https://discourse.nodered.org/u/Srijan)
#### Post date: [5 September 2018 05:55 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/26 "2018-09-05T05:55:05Z")

</div>

[{"id":"7e84782b.434118","type":"template","z":"8ffd8e0f.ee325","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"This is the payload: {{payload}} !","output":"str","x":120,"y":380,"wires":[[]]}]

this is my code, in this code i want that if the value of pir is 1 then lights should turn on for 5 min and then automatically get off. but if its value again reaches to 1 again the light should glow for 5 min .  
plzz help me out

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [5 September 2018 06:23 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/27 "2018-09-05T06:23:02Z")

</div>

Look at the trigger node

---

<div class="post-metadata">

### Author: ![Srijan](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Srijan](https://discourse.nodered.org/u/Srijan)
#### Post date: [5 September 2018 06:28 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/28 "2018-09-05T06:28:21Z")

</div>

used the trigger node and even gave the delay of 5 min but a bit confused where to connect that trigger node

 ![2018-09-05%20(2)](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6822ab2c14c12475464f8e111788f8141527ee56.png)

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [5 September 2018 06:41 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/29 "2018-09-05T06:41:01Z")

</div>

Try it in different places in your flow and see what different results you get. (TIP: start on the right hand size of your flow)

---

<div class="post-metadata">

### Author: ![Srijan](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Srijan](https://discourse.nodered.org/u/Srijan)
#### Post date: [5 September 2018 07:15 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/30 "2018-09-05T07:15:43Z")

</div>

not getting ur point can u explain briefly

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [5 September 2018 07:30 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/31 "2018-09-05T07:30:52Z")

</div>

You say you are

> [@Srijan](#):
>
> confused where to connect that trigger node

But in your images only show a little bit of your flow. The best way for you to therefore work out where to connect the trigger node is to try. Try adding it to different places within your flow and see what difference it makes.

---

<div class="post-metadata">

### Author: ![Srijan](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Srijan](https://discourse.nodered.org/u/Srijan)
#### Post date: [5 September 2018 08:24 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/32 "2018-09-05T08:24:00Z")

</div>

i tried it it at all places but can't get the appropriate soln. to my problem.

 ![2018-09-05%20(3)](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/73df7c21b73aea633091bacd34d5de0f5f11394a.png)

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [5 September 2018 08:49 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/33 "2018-09-05T08:49:19Z")

</div>

Put the trigger before the node that will turn on the light.

BTW - you have a 'hanging' delay node that won't do anything since it's output goes no where.

---

<div class="post-metadata">

### Author: ![Srijan](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Srijan](https://discourse.nodered.org/u/Srijan)
#### Post date: [5 September 2018 10:24 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/34 "2018-09-05T10:24:30Z")

</div>

can i use function node for the same task to turn lights for 5min if movement is detected if yes  
please give me some clues

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [5 September 2018 11:15 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/35 "2018-09-05T11:15:40Z")

</div>

Yes, but why would you want to? The trigger node does exactly what you want to achieve.

---

<div class="post-metadata">

### Author: ![Srijan](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Srijan](https://discourse.nodered.org/u/Srijan)
#### Post date: [5 September 2018 11:17 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/36 "2018-09-05T11:17:50Z")

</div>

I am trying with it but not successful in my process  
if u can create a flow showing the same will help me a lot

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [5 September 2018 11:27 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/37 "2018-09-05T11:27:33Z")

</div>

`[{"id":"2c34fd24.8dcc8a","type":"inject","z":"73ce664f.9ecb98","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":149.5,"y":177,"wires":[["cc52cf20.3de798"]]},{"id":"21c05283.e1b196","type":"trigger","z":"73ce664f.9ecb98","op1":"true","op2":"false","op1type":"bool","op2type":"bool","duration":"5","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":449.5,"y":178,"wires":[["9e0d4b51.f74cc8"]]},{"id":"9e0d4b51.f74cc8","type":"debug","z":"73ce664f.9ecb98","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":655.5,"y":178,"wires":[]},{"id":"cc52cf20.3de798","type":"switch","z":"73ce664f.9ecb98","name":"If true","property":"payload","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":289.5,"y":178,"wires":[["21c05283.e1b196"]]},{"id":"c6d79979.ab21","type":"inject","z":"73ce664f.9ecb98","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150.5,"y":229,"wires":[["cc52cf20.3de798"]]}]`

---

<div class="post-metadata">

### Author: ![Srijan](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Srijan](https://discourse.nodered.org/u/Srijan)
#### Post date: [7 September 2018 06:38 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/38 "2018-09-07T06:38:11Z")

</div>

HELLO EVERYONE I NEED SOME HELP REGARDING MY FLOW

 ![2018-09-07](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7b305a0f631f283816c6a2c266408e4dcba9855c.png)

---

<div class="post-metadata">

### Author: ![Srijan](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Srijan](https://discourse.nodered.org/u/Srijan)
#### Post date: [7 September 2018 06:44 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/39 "2018-09-07T06:44:38Z")

</div>

NODE PIR(0,1) IS NOT ABLE TO CONTROL THE FAN AND LIGHT AS SHOWN IN THE FIGURE.  
SO I THINK I SHOULD CREATE A FUNCTION NODE FOR THIS  
IN WHICH IF PIR VALUE IS 1 THEN IT WILL TURN THE LIGHT AND FAN ON OTHERWISE ALL THE LIGHT AND FAN WILL BE OFF . THE CONTROL OF LIGHT AND FAN SHOULD BE TOTALLY OVER PIR .  
ANY HELP FROM UR SIDE

 ![2018-09-07](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7b305a0f631f283816c6a2c266408e4dcba9855c.png)

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [7 September 2018 07:08 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/40 "2018-09-07T07:08:04Z")

</div>

There is no need to shout (please don't write in capitals!)

Without seeing the contents of your function and switches it is difficult to know what you are doing. Please export your flow and paste it in this thread in between ``` so it formats it correctly

But where I guess you are going wrong is that Node-RED doesn't remember the contents of old messages. So you need to save the value of PIR0 so when PIR1 changes it remembers what state PIR0 is ( and save PIR1 so that when ...)  
You can read about how to do this  
[https://nodered.org/docs/writing-functions#storing-data](https://nodered.org/docs/writing-functions#storing-data)  
and can do it with a change node (eg set flow.pir1 to msg.payload)

[Previous page](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818.md?page=1)

[Next page](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818.md?page=3)
