I have a splitter and change node in series that now split the json into different ports such that I can route them as needed. I've been looking off and on since yesterday on how to utilize the array filter function but haven't found anything that looks correct. Here's a shortened version of what I currently have.
[{"id":"9d1cdbd1.d25ed","type":"function","z":"a3c4e269.ff5da","name":"id to location","func":"const table = [\n {id: 1066, tag: \"B\"},\n {id: 245, tag: \"A\"},\n {id: 1878, tag: \"C\"},\n {id: 9170, tag: \"D\"},\n {id: 11106, tag: \"E\"},\n {id: 1294, tag: \"F\"},\n {id: 10160, tag: \"G\"},\n]\nconst topicArray = msg.topic.split(\"/\")\nconst id = topicArray[topicArray.length - 1]\n// now use table.filter() to find lookup the appropriate one\nmsg.payload = id\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":690,"y":400,"wires":[[]]},{"id":"b890bc86.1bbde8","type":"debug","z":"a3c4e269.ff5da","name":"humidity","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":580,"y":520,"wires":[]},{"id":"9f28c1f6.cb06a","type":"debug","z":"a3c4e269.ff5da","name":"battery","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":570,"y":560,"wires":[]},{"id":"fefaec1e.dadd8","type":"influxdb out","z":"a3c4e269.ff5da","d":true,"influxdb":"5b91dbad.94ba7c","name":"TempF","measurement":"","precision":"","retentionPolicy":"","database":"sensors","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":770,"y":480,"wires":[]},{"id":"9100e02d.7b5668","type":"switch","z":"a3c4e269.ff5da","name":"by topic","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"id","vt":"str"},{"t":"eq","v":"model","vt":"str"},{"t":"eq","v":"temperature_C","vt":"str"},{"t":"eq","v":"humidity","vt":"str"},{"t":"eq","v":"battery_ok","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":380,"y":460,"wires":[["b5e0b53a.b47108"],["9ce3b83c.884cb"],["7d954704.7195f"],["b890bc86.1bbde8"],["9f28c1f6.cb06a"]]},{"id":"a1a50547.4cf42","type":"split","z":"a3c4e269.ff5da","name":"splitter","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":230,"y":460,"wires":[["9100e02d.7b5668"]]},{"id":"bc96ace8.cf89b","type":"mqtt in","z":"a3c4e269.ff5da","name":"MQTT","topic":"rtl_433/Acurite-Tower/#","qos":"2","datatype":"json","broker":"b2400571.717f88","x":90,"y":460,"wires":[["d812ce4c.2bc208","a1a50547.4cf42"]]},{"id":"7d954704.7195f","type":"unit-converter","z":"a3c4e269.ff5da","category":"temperature","inputUnit":"C","outputUnit":"F","inputField":"payload","outputField":"payload","inputFieldType":"msg","outputFieldType":"msg","roundOutputField":false,"outputFieldDecimals":2,"name":"TempC2F","x":580,"y":480,"wires":[["fefaec1e.dadd8","1ffafa31.1223ee"]]},{"id":"1ffafa31.1223ee","type":"debug","z":"a3c4e269.ff5da","name":"temperature","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":440,"wires":[]},{"id":"d812ce4c.2bc208","type":"debug","z":"a3c4e269.ff5da","name":"MQTT debug","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":250,"y":380,"wires":[]},{"id":"9ce3b83c.884cb","type":"debug","z":"a3c4e269.ff5da","name":"model","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":570,"y":440,"wires":[]},{"id":"5dd4e5ca.3628b4","type":"deduplicate","z":"a3c4e269.ff5da","name":"","keyproperty":"","expirypolicy":"keep","registryclass":"","expiry":"1","x":530,"y":400,"wires":[["9d1cdbd1.d25ed"],[]]},{"id":"b5e0b53a.b47108","type":"debug","z":"a3c4e269.ff5da","name":"id","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":510,"y":360,"wires":[]},{"id":"5b91dbad.94ba7c","type":"influxdb","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"sensors","name":"influxdb","usetls":false,"tls":"","influxdbVersion":"1.x","url":"http://localhost:8086","rejectUnauthorized":true},{"id":"b2400571.717f88","type":"mqtt-broker","name":"RPi3","broker":"192.168.0.200","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
My main issues seem to be:
- how to get the id converted to a location
- how to use the id/location value and sensor type to generate an influxdb injection node
From what has been suggested here and further reviewing what other people are doing with databases it appears that the best practice is to use tags rather than a single key/value pair like I have currently. I gather that I should use a setup similar to:
tags
sensor type
location or id
fields
temp
humidity
battery
wind speed
wind direction
rain
If that's correct, I still don't see how to accomplish this with the standard Influxdb inject node.