Filter out Object Information

433 views
Skip to first unread message

TridiumControls

unread,
Sep 24, 2017, 6:50:44 PM9/24/17
to Node-RED
Hi, 

How do I go about splitting this information? I mainly care about the oldState and currentState. Preferably to be 2 outputs inside a function block so that I can map the outputs to a modbus write. 

zwave: value changed : msg : Object
object
topic: "zwave: value changed"
payload: object
nodeid: 3
cmdclass: 38
cmdidx: 0
instance: 1
oldState: 1
currState: 50
label: "Level"
units: ""
value: object
value_id: "3-38-1-0"
node_id: 3
class_id: 38
type: "byte"
genre: "user"
instance: 1
index: 0
label: "Level"
units: ""
help: ""
read_only: false
write_only: false
min: 0
max: 255
is_polled: false
value: 50


TridiumControls

unread,
Sep 24, 2017, 7:35:21 PM9/24/17
to Node-RED
I went ahead and ran it through JSON node. How would I go bout and extracting information from JSON?

zwave: value changed : msg.payload : string[372]
"{"nodeid":3,"cmdclass":38,"cmdidx":0,"instance":1,"oldState":44,"currState":99,"label":"Level","units":"","value":{"value_id":"3-38-1-0","node_id":3,"class_id":38,"type":"byte","genre":"user","instance":1,"index":0,"label":"Level","units":"","help":"","read_only":false,"write_only":false,"min":0,"max":255,"is_polled":false,"value":99},"uuid":"12312344412341234"}"

Nick O'Leary

unread,
Sep 25, 2017, 1:41:40 AM9/25/17
to Node-RED

Given your original message (forget about converting it to a single string... that makes it unnecessarily harder) you can access the two properties as:

msg.payload.oldState
and
msg.payload.currState

So if you have a function with two outputs, you can do:

var M1 = {
    payload: msg.payload.oldState
};
var M2 = {
    payload: msg.payload.currState
};
return [M1, M2];


--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/ddd546fe-ae21-4f20-97e8-64f9a5c4b80d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Julian Knight

unread,
Sep 28, 2017, 4:11:35 AM9/28/17
to Node-RED
JSONata via the change node is good for that kind of manipulation - though, as Nick says, if you just want a couple of attributes, a function node is a simple way of doing it.

TridiumControls

unread,
Sep 28, 2017, 12:44:32 PM9/28/17
to Node-RED
Thanks Nick and Julian,

That makes sense.

My apologies Nick, didn't see your reply. Went to spam for some reason.

I'm taking a few Java scripting classes, and won't be asking these easy questions here. Appreciate you taking the time to reply. I'll give it a go when I get home.

Colin Law

unread,
Sep 28, 2017, 4:10:37 PM9/28/17
to node...@googlegroups.com
Hopefully you mean javascript lessons. Java is not the same (whether
used for scripting or otherwise). If you are in a java course you are
on the wrong one :)

Colin

TridiumControls

unread,
Sep 28, 2017, 4:13:44 PM9/28/17
to Node-RED
Yes. Js.

Phone added an extra space.

Reply all
Reply to author
Forward
0 new messages