Generic sensor processing code

I use rtl_433 to convert my Acurite sensors into MQTT that NR utilizes. The packets are transmitted one data type at a time so my Acurite 592TXR towers result in several MQTT messages each time they transmit though I really only care about 3 (temperature, humidity, battery). Currently, I have rtl_433 send the message with the topic based on the type of sensor, the unit number of that sensor, and the data being transmitted.

rtl_433/Acurite-Tower/245/time 2022-03-28 00:56:03
rtl_433/Acurite-Tower/245/id 245
rtl_433/Acurite-Tower/245/channel A
rtl_433/Acurite-Tower/245/battery_ok 0
rtl_433/Acurite-Tower/245/temperature_C 19.6
rtl_433/Acurite-Tower/245/humidity 41
rtl_433/Acurite-Tower/245/mic CHECKSUM

Right now I have a block of code for each sensor ID which seems redundant. I would prefer to consolidate the code such that one block can take care of as many sensors as there happen to be on the MQTT stream. Each sensor would output to a separate ID into grafana like I currently have but not having to hard code things.

[{"id":"2850d44b.400a84","type":"tab","label":"Acurite tower","disabled":false,"info":""},{"id":"9bbb50b9.5cbb28","type":"mqtt in","z":"2850d44b.400a84","name":"tempC_A","topic":"rtl_433/Acurite-Tower/245/temperature_C","qos":"2","datatype":"buffer","broker":"b2400571.717f88","x":80,"y":100,"wires":[["6a324fe1.1882b"]]},{"id":"32f24980.f76f46","type":"mqtt in","z":"2850d44b.400a84","name":"Humidity_A","topic":"rtl_433/Acurite-Tower/245/humidity","qos":"2","datatype":"buffer","broker":"b2400571.717f88","x":80,"y":200,"wires":[["66fa83f2.18c4bc"]]},{"id":"fa26ba27.9b17f","type":"comment","z":"2850d44b.400a84","name":"Acurite tower temperature/humidity sensor (channel A)","info":"","x":205,"y":20,"wires":[]},{"id":"15f90a5a.8ae39e","type":"mqtt in","z":"2850d44b.400a84","name":"Battery_A","topic":"rtl_433/Acurite-Tower/245/battery_ok","qos":"2","datatype":"buffer","broker":"b2400571.717f88","x":80,"y":300,"wires":[["4a23f687.ecf4b8"]]},{"id":"3e17c4e4.4063e4","type":"mqtt in","z":"2850d44b.400a84","name":"tempC_B","topic":"rtl_433/Acurite-Tower/1066/temperature_C","qos":"2","datatype":"buffer","broker":"b2400571.717f88","x":80,"y":480,"wires":[["ea5d1366.0dd49"]]},{"id":"8b0fdf40.56f4e8","type":"mqtt in","z":"2850d44b.400a84","name":"Humidity_B","topic":"rtl_433/Acurite-Tower/1066/humidity","qos":"2","datatype":"buffer","broker":"b2400571.717f88","x":80,"y":580,"wires":[["b46923e1.071f5"]]},{"id":"9f430c02.752e48","type":"comment","z":"2850d44b.400a84","name":"Acurite tower temperature/humidity sensor (channel B)","info":"","x":205,"y":400,"wires":[]},{"id":"fac0c01e.bf1578","type":"mqtt in","z":"2850d44b.400a84","name":"Battery_B","topic":"rtl_433/Acurite-Tower/1066/battery_ok","qos":"2","datatype":"buffer","broker":"b2400571.717f88","x":80,"y":680,"wires":[["3bef14f9.cf230c"]]},{"id":"eeb45354.66fb48","type":"mqtt in","z":"2850d44b.400a84","name":"tempC_C","topic":"rtl_433/Acurite-Tower/1878/temperature_C","qos":"2","datatype":"buffer","broker":"b2400571.717f88","x":80,"y":860,"wires":[["dca2b2d9.c3c2c"]]},{"id":"9edaacdc.db739","type":"mqtt in","z":"2850d44b.400a84","name":"Humidity_C","topic":"rtl_433/Acurite-Tower/1878/C/humidity","qos":"2","datatype":"buffer","broker":"b2400571.717f88","x":90,"y":962,"wires":[["2ce4d5c3.fde7a2"]]},{"id":"ffbe6bd4.8fc2a","type":"comment","z":"2850d44b.400a84","name":"Acurite tower temperature/humidity sensor (channel C)","info":"","x":205,"y":780,"wires":[]},{"id":"f0fa2830.cb629","type":"mqtt in","z":"2850d44b.400a84","name":"Battery_C","topic":"rtl_433/Acurite-Tower/1878/battery_ok","qos":"2","datatype":"buffer","broker":"b2400571.717f88","x":80,"y":1060,"wires":[["9ec96693.9e7d6"]]},{"id":"aa941b94.cad38","type":"change","z":"2850d44b.400a84","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Temp sensor A battery low","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"Acurite tower temperature/humidity sensor A battery has dropped below 100%.  Replace at soonest convenience.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":340,"wires":[[]]},{"id":"1fc9f33e.220035","type":"change","z":"2850d44b.400a84","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Temp sensor B battery low","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"Acurite tower temperature/humidity sensor B battery has dropped below 100%.  Replace at soonest convenience.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":720,"wires":[[]]},{"id":"d0818b6b.21cc78","type":"change","z":"2850d44b.400a84","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Temp sensor C battery low","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"Acurite tower temperature/humidity sensor C battery has dropped below 100%.  Replace at soonest convenience.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":1100,"wires":[[]]},{"id":"898ffad.3e99f88","type":"influxdb out","z":"2850d44b.400a84","influxdb":"5b91dbad.94ba7c","name":"tempF_A","measurement":"rtl_433/Acurite-Tower/A/temperature_F","precision":"","retentionPolicy":"","database":"sensors","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":760,"y":100,"wires":[]},{"id":"203e957d.cde70a","type":"influxdb out","z":"2850d44b.400a84","influxdb":"5b91dbad.94ba7c","name":"Battery_A","measurement":"rtl_433/Acurite-Tower/A/battery_ok","precision":"","retentionPolicy":"","database":"sensors","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":520,"y":300,"wires":[]},{"id":"26521657.4a84b2","type":"influxdb out","z":"2850d44b.400a84","influxdb":"5b91dbad.94ba7c","name":"tempF_B","measurement":"rtl_433/Acurite-Tower/B/temperature_F","precision":"","retentionPolicy":"","database":"sensors","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":760,"y":480,"wires":[]},{"id":"b64e7b00.19fde8","type":"influxdb out","z":"2850d44b.400a84","influxdb":"5b91dbad.94ba7c","name":"Humidity_B","measurement":"rtl_433/Acurite-Tower/B/humidity","precision":"","retentionPolicy":"","database":"sensors","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":530,"y":580,"wires":[]},{"id":"6e539acf.d8a984","type":"influxdb out","z":"2850d44b.400a84","influxdb":"5b91dbad.94ba7c","name":"Battery_B","measurement":"rtl_433/Acurite-Tower/B/battery_ok","precision":"","retentionPolicy":"","database":"sensors","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":520,"y":683,"wires":[]},{"id":"eb40ab87.4c1d78","type":"influxdb out","z":"2850d44b.400a84","influxdb":"5b91dbad.94ba7c","name":"tempF_C","measurement":"rtl_433/Acurite-Tower/C/temperature_F","precision":"","retentionPolicy":"","database":"sensors","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":620,"y":860,"wires":[]},{"id":"517ee1.7dafd12","type":"influxdb out","z":"2850d44b.400a84","influxdb":"5b91dbad.94ba7c","name":"Humidity_C","measurement":"rtl_433/Acurite-Tower/C/humidity","precision":"","retentionPolicy":"","database":"sensors","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":530,"y":960,"wires":[]},{"id":"eb85d316.cf2b58","type":"influxdb out","z":"2850d44b.400a84","influxdb":"5b91dbad.94ba7c","name":"Battery_C","measurement":"rtl_433/Acurite-Tower/C/battery_ok","precision":"","retentionPolicy":"","database":"sensors","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":520,"y":1060,"wires":[]},{"id":"6a324fe1.1882b","type":"deduplicate","z":"2850d44b.400a84","name":"","keyproperty":"","expiry":"5","x":290,"y":100,"wires":[["32c8adec.8f308a"],[]]},{"id":"66fa83f2.18c4bc","type":"deduplicate","z":"2850d44b.400a84","name":"","keyproperty":"","expiry":"5","x":290,"y":200,"wires":[["dfeac77b.0c8e98"],[]]},{"id":"4a23f687.ecf4b8","type":"deduplicate","z":"2850d44b.400a84","name":"","keyproperty":"","expiry":"5","x":290,"y":300,"wires":[["203e957d.cde70a"],["eb51cc9b.519ea8"]]},{"id":"ea5d1366.0dd49","type":"deduplicate","z":"2850d44b.400a84","name":"","keyproperty":"","expiry":"5","x":290,"y":480,"wires":[["63bdbe3b.d8901"],[]]},{"id":"b46923e1.071f5","type":"deduplicate","z":"2850d44b.400a84","name":"","keyproperty":"","expiry":"5","x":290,"y":580,"wires":[["b64e7b00.19fde8"],[]]},{"id":"3bef14f9.cf230c","type":"deduplicate","z":"2850d44b.400a84","name":"","keyproperty":"","expiry":"5","x":290,"y":680,"wires":[["6e539acf.d8a984","4223527b.b0521c"],[]]},{"id":"dca2b2d9.c3c2c","type":"deduplicate","z":"2850d44b.400a84","name":"","keyproperty":"","expiry":"5","x":290,"y":860,"wires":[["25a23cf0.647534"],[]]},{"id":"2ce4d5c3.fde7a2","type":"deduplicate","z":"2850d44b.400a84","name":"","keyproperty":"","expiry":"5","x":290,"y":960,"wires":[["517ee1.7dafd12"],[]]},{"id":"9ec96693.9e7d6","type":"deduplicate","z":"2850d44b.400a84","name":"","keyproperty":"","expiry":"5","x":290,"y":1060,"wires":[["eb85d316.cf2b58","b0f32340.f69e1"],[]]},{"id":"eb51cc9b.519ea8","type":"falling-edge","z":"2850d44b.400a84","name":"<0.5","threshold":"0.5","x":430,"y":340,"wires":[["2aaaa03a.ba17b"]]},{"id":"4223527b.b0521c","type":"falling-edge","z":"2850d44b.400a84","name":"<0.5","threshold":"0.5","x":430,"y":720,"wires":[["8e336d6d.7e6048"]]},{"id":"b0f32340.f69e1","type":"falling-edge","z":"2850d44b.400a84","name":"<0.5","threshold":"0.5","x":430,"y":1100,"wires":[["4e32eef6.cbc418"]]},{"id":"32c8adec.8f308a","type":"unit-converter","z":"2850d44b.400a84","category":"temperature","inputUnit":"C","outputUnit":"F","inputField":"payload","outputField":"payload","inputFieldType":"msg","outputFieldType":"msg","roundOutputField":false,"outputFieldDecimals":2,"name":"TempC2F","x":460,"y":100,"wires":[["50ed743f.3d62d4"]]},{"id":"63bdbe3b.d8901","type":"unit-converter","z":"2850d44b.400a84","category":"temperature","inputUnit":"C","outputUnit":"F","inputField":"payload","outputField":"payload","inputFieldType":"msg","outputFieldType":"msg","roundOutputField":false,"outputFieldDecimals":2,"name":"TempC2F","x":460,"y":480,"wires":[["4cc92905.1d2c28"]]},{"id":"25a23cf0.647534","type":"unit-converter","z":"2850d44b.400a84","category":"temperature","inputUnit":"C","outputUnit":"F","inputField":"payload","outputField":"payload","inputFieldType":"msg","outputFieldType":"msg","roundOutputField":false,"outputFieldDecimals":2,"name":"TempC2F","x":460,"y":860,"wires":[["eb40ab87.4c1d78"]]},{"id":"dfeac77b.0c8e98","type":"influxdb out","z":"2850d44b.400a84","influxdb":"5b91dbad.94ba7c","name":"Humidity_A","measurement":"rtl_433/Acurite-Tower/A/humidity","precision":"","retentionPolicy":"","database":"sensors","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":530,"y":200,"wires":[]},{"id":"2aaaa03a.ba17b","type":"deduplicate","z":"2850d44b.400a84","name":"","keyproperty":"","registryclass":"","expiry":"86400","x":570,"y":340,"wires":[["aa941b94.cad38"],[]]},{"id":"8e336d6d.7e6048","type":"deduplicate","z":"2850d44b.400a84","name":"","keyproperty":"","registryclass":"","expiry":"86400","x":570,"y":720,"wires":[["1fc9f33e.220035"],[]]},{"id":"4e32eef6.cbc418","type":"deduplicate","z":"2850d44b.400a84","name":"","keyproperty":"","registryclass":"","expiry":"86400","x":570,"y":1100,"wires":[["d0818b6b.21cc78"],[]]},{"id":"50ed743f.3d62d4","type":"switch","z":"2850d44b.400a84","name":"Filter >150","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"150","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":610,"y":100,"wires":[["898ffad.3e99f88"]]},{"id":"4cc92905.1d2c28","type":"switch","z":"2850d44b.400a84","name":"Filter >150","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"150","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":610,"y":480,"wires":[["26521657.4a84b2"]]},{"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":""},{"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}]

Right now I am transmitting the data to grafana based on the hard coded Acurite channel but I want to store the data in grafana based on the received ID.

I can't look at your flow at the moment, but, if I understand correctly, you should be able to subscribe to rtl_433/Acurite-Tower/# which will give you data for all the devices and then extract the id from the topic to use when writing to influx.

Oh, duh! I forgot I could just use the "#" as a generic flag to grab all of the towers and then pull the unit number from the topic. I was thinking it needed to be pulled from the data which would only be 1 out of 7 and in the wrong order. If I pull it from the topic the same way I did the channel number in the past I'll be set. I knew I was overthinking it!

1 Like

I have the simplified flow so that it can see all sensors. I had to use a "+" rather than "#". I see a split function that can split the payload but not a direct way to split the topic. Also, it looks like that function is designed to send each portion of the split payload to separately but I only care about the 3rd chunk. I assume I should be looking to use a function here which isn't a problem. I'm just relatively new with NR so I'd rather use best practices rather than cobbling something together that is non-standard.

[{"id":"b76701c5.7313f","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"8e95be5a.1b61c","type":"mqtt in","z":"b76701c5.7313f","name":"tempC","topic":"rtl_433/Acurite-Tower/+/temperature_C","qos":"2","datatype":"buffer","broker":"b2400571.717f88","x":70,"y":100,"wires":[["5164f6e2.211958"]]},{"id":"f4c412a3.ff6728","type":"mqtt in","z":"b76701c5.7313f","name":"Humidity","topic":"rtl_433/Acurite-Tower/+/humidity","qos":"2","datatype":"buffer","broker":"b2400571.717f88","x":70,"y":200,"wires":[["847d857b.0a5c"]]},{"id":"44f14398.730d94","type":"comment","z":"b76701c5.7313f","name":"Acurite tower temperature/humidity sensor","info":"","x":165,"y":20,"wires":[]},{"id":"87b313d6.6689d","type":"mqtt in","z":"b76701c5.7313f","name":"Battery","topic":"rtl_433/Acurite-Tower/+/battery_ok","qos":"2","datatype":"buffer","broker":"b2400571.717f88","x":70,"y":300,"wires":[["b6ed43c1.a1afb8"]]},{"id":"200a738a.dd9bcc","type":"influxdb out","z":"b76701c5.7313f","d":true,"influxdb":"5b91dbad.94ba7c","name":"tempF_A","measurement":"rtl_433/Acurite-Tower/A/temperature_F","precision":"","retentionPolicy":"","database":"sensors","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":760,"y":100,"wires":[]},{"id":"2c84503f.9ce45","type":"influxdb out","z":"b76701c5.7313f","d":true,"influxdb":"5b91dbad.94ba7c","name":"Battery_A","measurement":"rtl_433/Acurite-Tower/A/battery_ok","precision":"","retentionPolicy":"","database":"sensors","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":520,"y":300,"wires":[]},{"id":"5164f6e2.211958","type":"deduplicate","z":"b76701c5.7313f","name":"","keyproperty":"","expiry":"5","x":290,"y":100,"wires":[["ff3ea7b4.46f578"],[]]},{"id":"847d857b.0a5c","type":"deduplicate","z":"b76701c5.7313f","name":"","keyproperty":"","expiry":"5","x":290,"y":200,"wires":[["da2d256.56eedd8"],[]]},{"id":"b6ed43c1.a1afb8","type":"deduplicate","z":"b76701c5.7313f","name":"","keyproperty":"","expiry":"5","x":290,"y":300,"wires":[["2c84503f.9ce45"],["f40e6d56.a5f2d8"]]},{"id":"f40e6d56.a5f2d8","type":"falling-edge","z":"b76701c5.7313f","d":true,"name":"<0.5","threshold":"0.5","x":430,"y":340,"wires":[["2408e6d5.2ff99a"]]},{"id":"ff3ea7b4.46f578","type":"unit-converter","z":"b76701c5.7313f","category":"temperature","inputUnit":"C","outputUnit":"F","inputField":"payload","outputField":"payload","inputFieldType":"msg","outputFieldType":"msg","roundOutputField":false,"outputFieldDecimals":2,"name":"TempC2F","x":460,"y":100,"wires":[["ad759e67.7a00d"]]},{"id":"da2d256.56eedd8","type":"influxdb out","z":"b76701c5.7313f","d":true,"influxdb":"5b91dbad.94ba7c","name":"Humidity_A","measurement":"rtl_433/Acurite-Tower/A/humidity","precision":"","retentionPolicy":"","database":"sensors","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":530,"y":200,"wires":[]},{"id":"2408e6d5.2ff99a","type":"deduplicate","z":"b76701c5.7313f","d":true,"name":"","keyproperty":"","registryclass":"","expiry":"86400","x":570,"y":340,"wires":[["7d9cb6f3.cc489"],[]]},{"id":"ad759e67.7a00d","type":"switch","z":"b76701c5.7313f","name":"Filter >150","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"150","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":610,"y":100,"wires":[["200a738a.dd9bcc"]]},{"id":"7d9cb6f3.cc489","type":"change","z":"b76701c5.7313f","d":true,"name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Temp sensor A battery low","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"Acurite tower temperature/humidity sensor A battery has dropped below 100%.  Replace at soonest convenience.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":340,"wires":[[]]},{"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":""},{"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}]

Put a change node after the MQTT in - you should be able to turn it into an Obj - then use a switch node to test on the property you are interested in (node ID) and send it out to different outputs based on the NODE ID

Put a debug node after your MQTT in and let us see what it looks like

You should be able to have a single MQTT in node and then parse that with the Change and switch nodes

Craig

When I implemented MQTT output on rtl_433 it defaults to outputing one message for each data type for each sensor. As a result, each Acurite tower generates 7 messages and repeats 3 times. With my old code, I used a duplicate node with a 5 second delay such that only the 1st message was processed. The old code looks at the channel and I was only using 3 sensors with one on each channel. I'm not sure how to pivot so that I can process only the first message for each sensor ID, but that's a problem for the future.

I added a switch and split node as suggested and now I'm seeing a flood of messages each time data comes in.

[{"id":"8e95be5a.1b61c","type":"mqtt in","z":"b76701c5.7313f","name":"tempC","topic":"rtl_433/Acurite-Tower/+/temperature_C","qos":"2","datatype":"buffer","broker":"b2400571.717f88","x":70,"y":100,"wires":[["ccc657af.9f044","ff3ea7b4.46f578"]]},{"id":"ff3ea7b4.46f578","type":"unit-converter","z":"b76701c5.7313f","category":"temperature","inputUnit":"C","outputUnit":"F","inputField":"payload","outputField":"payload","inputFieldType":"msg","outputFieldType":"msg","roundOutputField":false,"outputFieldDecimals":2,"name":"TempC2F","x":220,"y":100,"wires":[["6f83a654.96a348","e1e9cdee.e991e"]]},{"id":"e1e9cdee.e991e","type":"change","z":"b76701c5.7313f","name":"topic to payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":100,"wires":[["ff0c90a1.1d8798"]]},{"id":"ff0c90a1.1d8798","type":"split","z":"b76701c5.7313f","name":"","splt":"/","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":590,"y":100,"wires":[["8b20ab79.8a3338"]]},{"id":"ccc657af.9f044","type":"debug","z":"b76701c5.7313f","name":"tempC","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":210,"y":60,"wires":[]},{"id":"6f83a654.96a348","type":"debug","z":"b76701c5.7313f","name":"tempF","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":370,"y":60,"wires":[]},{"id":"8b20ab79.8a3338","type":"debug","z":"b76701c5.7313f","name":"split","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":60,"wires":[]},{"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":""}]
3/28/2022, 10:23:48 PMnode: split
rtl_433/Acurite-Tower/245/temperature_C : msg.payload : string[7]
"rtl_433"
3/28/2022, 10:23:48 PMnode: split
rtl_433/Acurite-Tower/245/temperature_C : msg.payload : string[13]
"Acurite-Tower"
3/28/2022, 10:23:48 PMnode: split
rtl_433/Acurite-Tower/245/temperature_C : msg.payload : string[3]
"245"
3/28/2022, 10:23:48 PMnode: split
rtl_433/Acurite-Tower/245/temperature_C : msg.payload : string[13]
"temperature_C"
3/28/2022, 10:23:48 PMnode: split
rtl_433/Acurite-Tower/245/temperature_C : msg.payload : string[7]
"rtl_433"
3/28/2022, 10:23:48 PMnode: split
rtl_433/Acurite-Tower/245/temperature_C : msg.payload : string[13]
"Acurite-Tower"
3/28/2022, 10:23:48 PMnode: split
rtl_433/Acurite-Tower/245/temperature_C : msg.payload : string[3]
"245"
3/28/2022, 10:23:48 PMnode: split
rtl_433/Acurite-Tower/245/temperature_C : msg.payload : string[13]
"temperature_C"
3/28/2022, 10:23:48 PMnode: split
rtl_433/Acurite-Tower/245/temperature_C : msg.payload : string[7]
"rtl_433"
3/28/2022, 10:23:48 PMnode: split
rtl_433/Acurite-Tower/245/temperature_C : msg.payload : string[13]
"Acurite-Tower"
3/28/2022, 10:23:48 PMnode: split
rtl_433/Acurite-Tower/245/temperature_C : msg.payload : string[3]
"245"
3/28/2022, 10:23:48 PMnode: split
rtl_433/Acurite-Tower/245/temperature_C : msg.payload : string[13]
"temperature_C"

We need a picture of the debug window.

But i would suggest changing the MQTT node to output an object

Once you have that you could then (for instance) use a change node and then a smooth node - the smooth node could accept (say) 10 readings and just average them and send the resulting number out

Craig

I switched the MQTT to a parsed JSON object.

Is that the Object output above - it does not look like one ?

Try having a single MQTT node catch all the incoming packets using the wildcard as suggested by Colin - and outputting as an object - and show us the debug of that - it may give you more options in terms of parsing then

Craig

I switched it over to a JSON object. It does use a wildcard but I'm only looking for temperature since it seemed better to just process each (temp, humidity, battery) in their own blocks. I could combine but then I'd have to split downstream. I guess either way works.

image

If you look at the smooth node it has a reduce feature - so you can feed it 10 values and it will only put out 1 output (as an example)

That might help you to cut down on your volume of data

Craig

I had an issue with my InfluxDB that I had to fix. Now that it's back up, I'm looking at this again. I have created a simple MQTT node that uses "parse JSON object" and then sends to a debug node. When data comes in, it seems to error on each MQTT packet. I assume that's because the data coming in is just a string rather than a block of JSON data.

There may be a better way to get the data from rtl_433 into MQTT, but I'm using the following:

/rtl_433 -R 11 -R 40 -R 176:10752 -M utc -F rtl_tcp:mqtt://localhost:1883,devices=rtl_433[/model][/id]

I don't know of any other way of doing it and the rest of my flows are built around this single message per data packet approach. I have seen where other people have all of their data from sensors send together for each sensor but I could not get that to work.

I found a post on the home assistant forum that looks like it may help get my rtl_433 output in json format with all data coming in one message. If that works, then I should be able to close this topic out I think.

So after switching to json objects in the rtl_433 output, I see that things should be a lot easier. It looks like I can use the object to keep the messages all organized when processing. But how would I use the sensor ID when I want to output to influxdb?

[{"id":"5164f6e2.211958","type":"deduplicate","z":"b76701c5.7313f","name":"","keyproperty":"","expirypolicy":"keep","registryclass":"","expiry":"5","x":210,"y":200,"wires":[["a788c5e7.6759","5eddbf3.46d07c"],[]]},{"id":"d30d485c.e00178","type":"mqtt in","z":"b76701c5.7313f","name":"MQTT","topic":"rtl_433/Acurite-Tower/#","qos":"2","datatype":"json","broker":"b2400571.717f88","x":70,"y":200,"wires":[["5164f6e2.211958"]]},{"id":"a788c5e7.6759","type":"debug","z":"b76701c5.7313f","name":"MQTT debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":370,"y":160,"wires":[]},{"id":"5eddbf3.46d07c","type":"unit-converter","z":"b76701c5.7313f","category":"temperature","inputUnit":"C","outputUnit":"F","inputField":"payload.temperature_C","outputField":"payload","inputFieldType":"msg","outputFieldType":"msg","roundOutputField":false,"outputFieldDecimals":2,"name":"TempC2F","x":380,"y":200,"wires":[["8fb38d14.f6293","bdbbb53e.a7d1e8"]]},{"id":"8fb38d14.f6293","type":"debug","z":"b76701c5.7313f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":570,"y":160,"wires":[]},{"id":"bdbbb53e.a7d1e8","type":"influxdb out","z":"b76701c5.7313f","influxdb":"5b91dbad.94ba7c","name":"Temperature","measurement":"rtl_433/Acurite-Tower/ID/Temperature","precision":"","retentionPolicy":"","database":"sensors","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":570,"y":200,"wires":[]},{"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":""},{"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}]

It appears that I need to make the ID a variable somehow so that it pulls from the JSON object's id field.

image

Here's an example of the JSON object and the calculated tempF.

image

Do you mean that, in the case you show, msg.topic is rtl_433/Acurite-Tower/245 and you want to get the 245 out of it? If so then in a function node you can do

const topicArray = msg.topic.split("/")
const id = topicArray[topicArray.length - 1]

In Influxdb consider making the id a tag rather than part of the measurement name. Then in the query you can use WHERE id = 245, for example and have the data for all devices in the same measurement, which will be more efficient.
Also perhaps Accurite-Tower should be a tag. Tell us a bit more about the full set of measurements that you have and we can likely suggest better ways of organising it.

I cobbled things together originally based on various tutorials I found so I am sure my database is not efficient. Right now I have each data type going to a measurement with the name of the MQTT topic. My measurements look like this (which seems ugly to me):

rtl_433/Acurite-5n1/A/battery_ok
rtl_433/Acurite-5n1/A/humidity
rtl_433/Acurite-5n1/A/rain_in
rtl_433/Acurite-5n1/A/rain_increment_in
rtl_433/Acurite-5n1/A/rain_increment_in_test
rtl_433/Acurite-5n1/A/temperature_F
rtl_433/Acurite-5n1/A/wind_dir_deg
rtl_433/Acurite-5n1/A/wind_mph
rtl_433/Acurite-Tower/A/battery_ok
rtl_433/Acurite-Tower/A/humidity
rtl_433/Acurite-Tower/A/temperature_F
rtl_433/Acurite-Tower/B/battery_ok
rtl_433/Acurite-Tower/B/humidity
rtl_433/Acurite-Tower/B/temperature_F
rtl_433/Acurite-Tower/C/battery_ok
rtl_433/Acurite-Tower/C/humidity
rtl_433/Acurite-Tower/C/temperature_F
rtl_433/Blueline_PowerCost_Monitor/Cost
rtl_433/Blueline_PowerCost_Monitor/battery_ok
rtl_433/Blueline_PowerCost_Monitor/gap
rtl_433/Blueline_PowerCost_Monitor/impulses
rtl_433/Blueline_PowerCost_Monitor/impulses_increment
rtl_433/Blueline_PowerCost_Monitor/kW
rtl_433/Blueline_PowerCost_Monitor/kWh
rtl_433/Blueline_PowerCost_Monitor/kWh_increment
rtl_433/Blueline_PowerCost_Monitor/temperature_F
rtl_433/Nexus-TH/1/battery_ok
rtl_433/Nexus-TH/1/temperature_F

I am completely open to redoing the database if there are better options. This was literally just the first take and it stuck because it worked on day 1.

Do your receive all the data for unit A (or B or C) in a single message from the device or do they come in separate messages? Similarly does all the blueline data come in one message? Generally if you get a set of data in one message then you should save it in a single measurement.

[Edit] I meant the tower units A B and C. Presumable the 5n1 is a different type of device. Does the A there relate to the A Tower?

I have 7 of the tower sensors (3 are in use currently as channel A, B, and C), 1 of a different type of sensor (may not use it because it has a variable ID), and the one 5n1 weather station. All of these have a different ID. The 5n1 has a different name than the towers due to using a different set of code to decode it in rtl_433.

I was receiving all of the data one message for each data type (e.g., temp, humidity, battery, etc). Now that it is json it is a single message holding all data. This is cleaner and what I wanted originally.

For your tower sensors put them all in one measurement, tower_data or whatever, with fields battery_ok, humidity and temperature, and with a tag which is the ID.

Does the ID come from the device itself? If one failed and you had to replace it would the id change? If so then don't put the ID in the database at all, map it some meaningful name identifiying the postion and use that as the tag, so that if you have to change a device it does not mess up the databasel

If you only have on 5n1 device then put that in a separate measurment, you don't need the ID at all in the database as there is only one of them. Similarly your power monitor can go in its own measurement.

The ID for the 5n1 and these tower sensors is set at the factory and does not change. If one fails and I need to replace it, the new one would have a new unique ID. I was hoping to have a generic code to detect all sensors but you are correct that the data would be difficult to use. I would still like to have a code that was universal to work with these but then place them in a data structure as you have described that is meaningful.

Is there any way to have a lookup so that I could have a list of sensor ID's and a meaningful name for them to be associated with in the database? Sort of like a programmed in channel? I probably wouldn't use A, B, C... but something like North Attic, South Attic, etc.