I am currently working out the input for influxDB based on your Node in "listen to all" mode. It works, but as I am not very familar with Node Red (and Java Script), the script looks horrible...
The format of the string is:
"("<maingroup>“->“<middlegroup>“) "<room>“ - "<device>“ - "<action>
And this is my Script to split this accordingly:
Does anyone have hints how to improve this?
EDIT:
I think I found a good solution using Regex, at least it's much better than the "mess" before ;-) :
The format of the string is:
"("<maingroup>“->“<middlegroup>“) "<room>“ - "<device>“ - "<action>
And this is my Script to split this accordingly:
Code:
var outputMsg = {}; var p1 = msg.payload.split("->"); var HG = p1[0].substr(1,p1[0].length); var p2=p1[1].split(")"); var MG = p2[0]; var parts = p1[1].substr(MG.length+2,p1[1].length).split(" - ") outputMsg.payload = { hg: HG, mg: MG, room: parts[0], device: parts[1], action: parts[2] } return [ outputMsg ];
Does anyone have hints how to improve this?
EDIT:
I think I found a good solution using Regex, at least it's much better than the "mess" before ;-) :
Code:
var outputMsg = {}; var regexp = /^[\(](.*)[\-][>](.*)[\)][\s](.*)[\s][\-][\s](.*)[\s][\-][\s](.*)$/ var parts = msg.payload.match(regexp); outputMsg.payload = { hg: parts[1], mg: parts[2], room: parts[3], device: parts[4], action: parts[5] } return [ outputMsg ];
Kommentar