Stuck splitting messages

#1

I am using bigtimer and looking at output #2.

example:

{"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.

0 Likes

#2

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

1 Like

#3

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:

[{"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.

0 Likes

#4

There are multiple ways to do this, 1 version:

[{"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.

0 Likes

#5

Thanks.

I'll look at it soon - I hope.

Just found another problem with one of my flows.

0 Likes

#6

Why make it so complicated?

Just access the properties directly:

[{"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":[]}]
0 Likes

#7

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.

0 Likes

#8

A change node would work as well.

0 Likes

#9

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

0 Likes

#10

Not true! Multiple lines!

0 Likes

#11

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.

0 Likes

#12

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

0 Likes