I'm trying to get 4 electrical values from 4 MQTT messages from a Z-wave device to log in Influx. I want the 4 values in one DB record so I'm using a Join node to put them together followed by a Function node to extract the values and format for Influx.
I have several similar functions working as desired so I know how to handle the formatting part but they are getting Zigbee data with everything in a single message.
The only way I could get something out of the join node that I know how to deal with (almost) is with it setup like this
Here is 1 of the 4 messages going into the Join node followed by what comes out of the Join node when all 4 arrive within a half second. Since these Z-wave devices spit out these 4 topics every 10 seconds I don't have a problem with timing (that I know of)
Here is my test flow. I've tried various incantations using the lines you see in the function, not all at once as it is shown. The structure after the "=" in this line
const path = payload.value["zwave/Master_Closet_Light/50/0/value/66561"]
came from copying the path from the debug output.
[{"id":"93fe7cb10253b290","type":"mqtt in","z":"d0f2cf2d.02296","name":"Master_Closet_Light","topic":"zwave/Master_Closet_Light/50/0/value/#","qos":"1","datatype":"json","broker":"a8641058.accf9","nl":false,"rap":false,"inputs":0,"x":230,"y":3190,"wires":[["9e36c487cf67cfaa","9e1da59c.3ea6b8"]]},{"id":"9e1da59c.3ea6b8","type":"debug","z":"d0f2cf2d.02296","name":"Original msg","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":410,"y":3250,"wires":[]},{"id":"9e36c487cf67cfaa","type":"join","z":"d0f2cf2d.02296","name":"","mode":"custom","build":"object","property":"payload.value","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":".5","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":400,"y":3190,"wires":[["e0ec91e09dc7bfb2","3dcce2d74ae4ab00"]]},{"id":"3dcce2d74ae4ab00","type":"function","z":"d0f2cf2d.02296","name":"multiple metrics","func":"const device = msg.topic.split('/');\nconst lastIndex = msg.topic.lastIndexOf('/');\nconst path = msg.topic.slice(0, lastIndex + 1);\nconst newpath = eval(\"msg.payload.value.\" + path + '66561');\n\nconst voltage = parseFloat(payload.value[\"zwave/\" + device[1] + \"/50/0/value/66561\"]);\nconst path = payload.value[\"zwave/Master_Closet_Light/50/0/value/66561\"]\nconst voltage = parseFloat(path);\n\nvar payload = newpath;\n\nreturn { payload:payload };\n","outputs":1,"noerr":4,"initialize":"","finalize":"","libs":[],"x":580,"y":3190,"wires":[["fda39dd4170aa710"]]},{"id":"e0ec91e09dc7bfb2","type":"debug","z":"d0f2cf2d.02296","name":"debug 1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":3250,"wires":[]},{"id":"fda39dd4170aa710","type":"debug","z":"d0f2cf2d.02296","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":3190,"wires":[]},{"id":"a8641058.accf9","type":"mqtt-broker","name":"Mosquitto on server-ha","broker":"192.168.5.5","port":"1883","clientid":"","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":"5","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"1","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]
Everything I've tried so far results in these errors
I'm a novice with JS and Function nodes so the various attempts came from web searches that seemed to be close to what I'm trying to accomplish.
All information/advice/pointers are welcome.
Thanks for your time!