Combining node messages - Node Red

If only I had half the knowledge you guys have. It works! Thanks @JasonJoel and @Boredom for your patience and guidance.

Is there a good resource for these commands? Like, to really learn it.

It's JavaScript, lots of resources out there. Can get a bit daunting though. I find that I need to delve a bit more into JSON data parsing. There's a depth to the language that really doesn't need to be utilized within Node Red.

Yah and I just want to know it specifically for node red.

I'd suggest reaching out to the community when you have something. It'll be less confusing.

Posting a random example of something I use for the lights in my garage....


1 Like

I have no problem reaching out to the community, but it makes me feel "needy". But I do admit that I do learn the concepts better when I can see them.

Thankfully, there are many here that truly enjoy helping others. Wouldn't call it "needy", more like "inquisitive".

2 Likes

If you were feeling adventurous, would you mind trying something with that function?

Add a line before line 1 that reads:
msg.warn(msg.payload.data[0].name);

Monitor your debug log and try your lock. I'm curious if that would give you your name, "Home". (Trying to learn something new here.) I have a suspicion that it will return null.

Just remove the line afterwards.

I expect not, as the data item value isn't properly formed json. It is only json-esque.

But doesn't hurt to try...

Challenge accepted! stand by ...

@Boredom @JasonJoel

image

Errr....need more coffee.
It should be node.warn, not msg.warn

it made the announcement like normal. Did it on two doors

Anything in the debug log? I'm guessing it returned "undefined".

yes undefined. what were we warning of?

That was an attempt to pull the "name" from the malformed JSON data. Didn't work, not too surprising though.
{"1":{"name":"Home","code":"2222"}}

Thank you. Also, when writing your own functions, that node.warn is very helpful to help troubleshoot. You can comment out the line so it doesn't run by preceding it with //

2 Likes

Ok, toyed with this a bit...came up with one way to get your "who" from the data.
var dataTmp = msg.payload.data.split(""");
var WhoDidIt = dataTmp[5];

So, the kludge I typed above would look like....
image

Totally unnecessary when compared to what you have currently. Just gives a bit more control to the output text itself. (Don't really need the variables for displayName or value either.)

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.