# Stuck splitting messages

**URL:** <https://discourse.nodered.org/t/stuck-splitting-messages/9847>\
**Category:** General\
**Created:** [7 April 2019 02:31 UTC](https://discourse.nodered.org/t/stuck-splitting-messages/9847 "2019-04-07T02:31:50Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [7 April 2019 02:31 UTC](https://discourse.nodered.org/t/stuck-splitting-messages/9847/1 "2019-04-07T02:31:50Z")

</div>

I am using `bigtimer` and looking at output #2.

example:

```auto
{"payload":1,"reference":"DAYTIME:SUNRISE:SUNSET:744","topic":"status","state":"ON Auto","time":"05hrs 21mins","name":"Day Start/End","start":372,"end":1065,"dusk":1090,"dawn":347,"solarNoon":718,"sunrise":372,"sunset":1065,"night":1148,"nightEnd":289,"now":744,"timer":0,"duration":321,"onOverride":-1,"offOverride":-1,"stamp":1554603861685,"_msgid":"44e46be.5464d94","_event":"node:2c23f48.2b3238c"}

```

I am wanting to _cut_ this message up to get the many sub-pieces.  
So I have a `sunrise` message. A `sunset` message. A `dawn`, `dusk` etc etc.

`split` doesn't seem to work.  
Neither does `switch`. At least the way I have it.  
Using `switch` I get the entire message sent out each output.  
(or something like that. Actually I am probably wrong in saying it.)

But _at the end of the day_ it isn't working and I am stuck how to do it.

---

<div class="post-metadata">

**Author:** ![wb666greene](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wb666greene/32/6534_2.png) [@wb666greene](https://discourse.nodered.org/u/wb666greene)\
**Post date:** [7 April 2019 03:39 UTC](https://discourse.nodered.org/t/stuck-splitting-messages/9847/2 "2019-04-07T03:39:00Z")

</div>

Your string looks like json. Try the json node to turn it into javascript object and then further process it.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [7 April 2019 03:41 UTC](https://discourse.nodered.org/t/stuck-splitting-messages/9847/3 "2019-04-07T03:41:53Z")

</div>

I've kind of _nutted it out_ in the mean time.

I tried putting the `json` node in to the flow, but I still couldn't "spit" it.

(input from BigTimer's #2 output)  
Ultimately this is what I did.  
Messy, but it works:

```auto
[{"id":"99d575fb.35ad6","type":"function","z":"5106e962.4d99a8","name":"","func":"// x = x.toString();\nvar start = msg.start;\nvar end = msg.end;\nvar dawn = msg.dawn;\nvar dusk = msg.dusk;\n\nvar msg1 = {payload: start.toString()};\nvar msg2 = {payload: end.toString()};\nvar msg3 = {payload: dawn.toString()};\nvar msg4 = {payload: dusk.toString()};\nreturn [msg1, msg2, msg3, msg4];","outputs":4,"noerr":0,"x":300,"y":1170,"wires":[["6be096b7.3e8b38"],["fcddb726.ccf9f8"],["fd4dde9c.597a3"],["6365103f.7e7d3"]]},{"id":"6be096b7.3e8b38","type":"function","z":"5106e962.4d99a8","name":"","func":"var x = parseInt(msg.payload);\nvar h = parseInt(x/60);\nvar m = x%60;\nnode.warn(m);\nvar hour = h.toString();\nvar minute = m.toString();\nvar time = hour + \":\" + minute;\nmsg = {payload: 'Sunrise ' + time};\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":1150,"wires":[["18bc3835.66e6c8"]]},{"id":"fcddb726.ccf9f8","type":"function","z":"5106e962.4d99a8","name":"","func":"var x = parseInt(msg.payload);\nvar h = parseInt(x/60);;\nvar m = x%60;\nvar hour = h.toString();\nvar minute = m.toString();\nvar time = hour + \":\" + minute;\nmsg = {payload: 'Sunset ' + time};\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":1190,"wires":[["d4ba8f59.ef48c"]]},{"id":"fd4dde9c.597a3","type":"function","z":"5106e962.4d99a8","name":"","func":"var x = parseInt(msg.payload);\nvar h = parseInt(x/60);\nvar m = x%60;\nvar hour = h.toString();\nvar minute = m.toString();\nvar time = hour + \":\" + minute;\nmsg = {payload: 'Dawn ' + time};\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":1230,"wires":[["55ef9081.2ff9b8"]]},{"id":"6365103f.7e7d3","type":"function","z":"5106e962.4d99a8","name":"","func":"var x = parseInt(msg.payload);\nvar h = parseInt(x/60);\nvar m = x%60;\nvar hour = h.toString();\nvar minute = m.toString();\nvar time = hour + \":\" + minute;\nmsg = {payload: 'Dusk ' + time};\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":1270,"wires":[["92d91706.1a8d28"]]},{"id":"18bc3835.66e6c8","type":"debug","z":"5106e962.4d99a8","name":"Start","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":690,"y":1150,"wires":[]},{"id":"d4ba8f59.ef48c","type":"debug","z":"5106e962.4d99a8","name":"End","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":690,"y":1190,"wires":[]},{"id":"55ef9081.2ff9b8","type":"debug","z":"5106e962.4d99a8","name":"Dawn","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":690,"y":1230,"wires":[]},{"id":"92d91706.1a8d28","type":"debug","z":"5106e962.4d99a8","name":"Dusk","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":690,"y":1270,"wires":[]}]

```

(Edit)

This is **one** example of some flow I tried which didn't work.  
You can see the `json` node and the `split` and `switch`.  
Didn't work.

 ![Screenshot%20from%202019-04-07%2013-42-54](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e6aa24696215c7fceff4896cfb3136ef0a2dc9ee.png)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [7 April 2019 05:58 UTC](https://discourse.nodered.org/t/stuck-splitting-messages/9847/4 "2019-04-07T05:58:37Z")

</div>

There are multiple ways to do this, 1 version:

```auto
[{"id":"5549e92f.f9fb98","type":"inject","z":"e6817f81.7d7f8","name":"","topic":"","payload":"{\"reference\":\"DAYTIME:SUNRISE:SUNSET:744\",\"topic\":\"status\",\"state\":\"ON Auto\",\"time\":\"05hrs 21mins\",\"name\":\"Day Start/End\",\"start\":372,\"end\":1065,\"dusk\":1090,\"dawn\":347,\"solarNoon\":718,\"sunrise\":372,\"sunset\":1065,\"night\":1148,\"nightEnd\":289,\"now\":744,\"timer\":0,\"duration\":321,\"onOverride\":-1,\"offOverride\":-1,\"stamp\":1554603861685,\"_msgid\":\"44e46be.5464d94\",\"_event\":\"node:2c23f48.2b3238c\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":250,"y":380,"wires":[["7c7004e3.37ef9c"]]},{"id":"224db7f8.a81eb8","type":"debug","z":"e6817f81.7d7f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":550,"y":320,"wires":[]},{"id":"7c7004e3.37ef9c","type":"function","z":"e6817f81.7d7f8","name":"","func":"m = msg.payload\n\nout1 = {payload:m.start}\nout2 = {payload:m.end}\nout3 = {payload:m.dusk}\nout4 = {payload:m.dawn}\n\nreturn [out1,out2,out3,out4];","outputs":4,"noerr":0,"x":390,"y":380,"wires":[["224db7f8.a81eb8"],["4af0225f.34b4dc"],["9464e2cf.62509"],["9775c6ec.01b5d8"]]},{"id":"4af0225f.34b4dc","type":"debug","z":"e6817f81.7d7f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":550,"y":360,"wires":[]},{"id":"9464e2cf.62509","type":"debug","z":"e6817f81.7d7f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":550,"y":400,"wires":[]},{"id":"9775c6ec.01b5d8","type":"debug","z":"e6817f81.7d7f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":550,"y":440,"wires":[]}]

```

didnt check the output of the jsonata, was incorrect, removed it.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [7 April 2019 06:00 UTC](https://discourse.nodered.org/t/stuck-splitting-messages/9847/5 "2019-04-07T06:00:47Z")

</div>

Thanks.

I'll look at it soon - I hope.

Just found another problem with one of my flows.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [8 April 2019 10:13 UTC](https://discourse.nodered.org/t/stuck-splitting-messages/9847/6 "2019-04-08T10:13:16Z")

</div>

Why make it so complicated?

Just access the properties directly:

```auto
[{"id":"4d09a6e9.a14098","type":"bigtimer","z":"1d66267b.4c5caa","outtopic":"","outpayload1":"","outpayload2":"","name":"Big Timer","comment":"","lat":"51.7972","lon":"-3.8246","starttime":5001,"endtime":1425,"starttime2":0,"endtime2":0,"startoff":0,"endoff":0,"startoff2":0,"endoff2":0,"offs":0,"outtext1":"","outtext2":"","timeout":1440,"sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"day6":0,"month6":0,"d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"d6":0,"w6":0,"xday1":0,"xmonth1":0,"xday2":0,"xmonth2":0,"xday3":0,"xmonth3":0,"xday4":0,"xmonth4":0,"xday5":0,"xmonth5":0,"xday6":0,"xmonth6":0,"xd1":0,"xw1":0,"xd2":0,"xw2":0,"xd3":0,"xw3":0,"xd4":0,"xw4":0,"xd5":0,"xw5":0,"xd6":0,"xw6":0,"suspend":false,"random":false,"repeat":true,"atstart":true,"odd":false,"even":false,"x":260,"y":320,"wires":[[],["ba237ec7.ea96a","7c14243e.abcb2c","94c6b4e2.970658","7c9e8337.d9513c"],[]]},{"id":"ba237ec7.ea96a","type":"debug","z":"1d66267b.4c5caa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"sunrise","targetType":"msg","x":610,"y":320,"wires":[]},{"id":"7c14243e.abcb2c","type":"debug","z":"1d66267b.4c5caa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"sunset","targetType":"msg","x":610,"y":360,"wires":[]},{"id":"94c6b4e2.970658","type":"debug","z":"1d66267b.4c5caa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"dawn","targetType":"msg","x":610,"y":400,"wires":[]},{"id":"7c9e8337.d9513c","type":"debug","z":"1d66267b.4c5caa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"dusk","targetType":"msg","x":600,"y":440,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 April 2019 21:14 UTC](https://discourse.nodered.org/t/stuck-splitting-messages/9847/7 "2019-04-08T21:14:44Z")

</div>

Yeah the "problem" is that I still need to split the messages.

But it with a function node to separate them or with debug nodes with filtering in them to which part of the message is shown.

As I am wanting to set context/flow/global (not sure yet which) either _n_ function nodes are needed or one which splits them and (though not in the flow I posted) set the _context_ values.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [8 April 2019 21:35 UTC](https://discourse.nodered.org/t/stuck-splitting-messages/9847/8 "2019-04-08T21:35:02Z")

</div>

> [@Trying\_to\_learn](#):
>
> As I am wanting to set context/flow/global (not sure yet which) either _n_ function nodes are needed or one which splits them and (though not in the flow I posted) set the _context_ values.

A change node would work as well.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [9 April 2019 01:57 UTC](https://discourse.nodered.org/t/stuck-splitting-messages/9847/9 "2019-04-09T01:57:42Z")

</div>

Again: True. But there would need to be one for each _value_ I wanted to use.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [9 April 2019 08:50 UTC](https://discourse.nodered.org/t/stuck-splitting-messages/9847/10 "2019-04-09T08:50:38Z")

</div>

Not true! Multiple lines!

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [9 April 2019 10:49 UTC](https://discourse.nodered.org/t/stuck-splitting-messages/9847/11 "2019-04-09T10:49:27Z")

</div>

How can a `change` node set contexts?

I'll look into it too. But I am not sure that part is still in the scope of what is actually the desired goal.

Ok.

Mia Culpa.

I don't use the `change` node that often.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [9 April 2019 11:44 UTC](https://discourse.nodered.org/t/stuck-splitting-messages/9847/12 "2019-04-09T11:44:29Z")

</div>

> [@Trying\_to\_learn](#):
>
> I don't use the `change` node that often.

I almost only use change nodes and very few function nodes.
