Enviro monitoring with DHT22 and DS18B20 probes

This flow takes a DHT22 Temperature Humidity Probe output and a 1Wire DS18B20 Temperature probe output and sends it to a user UI. It also sends the the Raspberry Pi 4 CPU average usage and CPU temperature to the user UI. All outputs are then routed into an Influx DataBase, which is used to display the long term data using Grafana. The DHT22 would not display both temperature and humidity correctly at the same time. Humidity was reported as a bad type value in InfluxDB. The Humidity data was sent to the function "Convert to number" It takes the payload and converts it to a JSON $number(payload) output which works. I am not sure why this is needed, but this is how I got it to work. I also added a "Drop Reading Spike" switch to drop the bad readings from the DHT22. Due to timing or noise or something, it can on occasion report a number in the thousands skewing the data. The switches just limit the values. A drop in the data is better than a huge spike. There maybe better ways to do this error checking, but I am new to Node-Red and programming.
The DHT22 is on GPIO 4, and the DS18B20 (later on multiple DS18B20 probes) reside on GPIO 17.

[{"id":"3055dcb0.359de4","type":"tab","label":"Room Monitoring Flow","disabled":false,"info":""},{"id":"1aa31c2c.3154a4","type":"inject","z":"3055dcb0.359de4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"10","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":340,"wires":[["a75fee23.e4a9b","5c636fb8.0feaf","b5b0f31f.a0853","4c9e673f.4ce2d8"]]},{"id":"a75fee23.e4a9b","type":"rpi-dht22","z":"3055dcb0.359de4","name":"Indoor THI","topic":"rpi-dht22","dht":22,"pintype":"0","pin":4,"x":270,"y":180,"wires":[["49ec49f0.7b2138","1e2bb959.c0da27"]]},{"id":"49ec49f0.7b2138","type":"function","z":"3055dcb0.359de4","name":"Temperature","func":"msg.payload = msg.payload * 1.8 + 32\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":120,"wires":[["78c1dc33.7c7ad4"]]},{"id":"1e2bb959.c0da27","type":"function","z":"3055dcb0.359de4","name":"Humidity","func":"msg.payload = msg.humidity\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":460,"y":220,"wires":[["f33f5190.693bc","5dc0f0e3.cd67","a1a197e8.f86d18"]]},{"id":"dbba57c9.287298","type":"ui_gauge","z":"3055dcb0.359de4","name":"","group":"8ee6537d.cbbd2","order":1,"width":0,"height":0,"gtype":"gage","title":"Temperature","label":"F","format":"{{value | number:1}}","min":0,"max":"105","colors":["#00b500","#e6e600","#ca3838"],"seg1":"75","seg2":"80","x":1050,"y":160,"wires":[]},{"id":"5dc0f0e3.cd67","type":"ui_gauge","z":"3055dcb0.359de4","name":"","group":"f069ec14.d011f","order":1,"width":0,"height":0,"gtype":"gage","title":"Humidity","label":"RH%","format":"{{value | number:0}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"70","seg2":"80","x":800,"y":200,"wires":[]},{"id":"f33f5190.693bc","type":"ui_chart","z":"3055dcb0.359de4","name":"","group":"fd53e486.008958","order":2,"width":0,"height":0,"label":"Humidity","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"Awaiting Input","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":800,"y":240,"wires":[[]]},{"id":"65692ef6.94d39","type":"ui_chart","z":"3055dcb0.359de4","name":"","group":"fd53e486.008958","order":1,"width":0,"height":0,"label":"Temperature","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"Awaiting input","dot":false,"ymin":"50","ymax":"102","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#ec0e0e","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1050,"y":120,"wires":[[]]},{"id":"1267a6fd.ceeb29","type":"influxdb out","z":"3055dcb0.359de4","influxdb":"c752a989.fd0328","name":"Room Temperature","measurement":"temperature","precision":"","retentionPolicy":"","x":1070,"y":80,"wires":[]},{"id":"63ee4b02.50e294","type":"influxdb out","z":"3055dcb0.359de4","influxdb":"711e24e8.9062dc","name":"Room Humidity","measurement":"humidity","precision":"","retentionPolicy":"","x":1060,"y":300,"wires":[]},{"id":"5c636fb8.0feaf","type":"sensor-ds18b20","z":"3055dcb0.359de4","name":"DS18B20 Probe","topic":"","sensorid":"XX-YourProbeID","timer":"1","repeat":false,"x":280,"y":320,"wires":[["7eb2cf87.ecd1"]]},{"id":"2ec55f5.e6a67a","type":"ui_gauge","z":"3055dcb0.359de4","name":"T1","group":"8ee6537d.cbbd2","order":2,"width":0,"height":0,"gtype":"gage","title":"T1 Temp","label":"F","format":"{{value | number:1}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"70","seg2":"80","x":790,"y":320,"wires":[]},{"id":"7eb2cf87.ecd1","type":"function","z":"3055dcb0.359de4","name":"C to F Convert","func":"msg.payload = msg.payload * 1.8 + 32\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":320,"wires":[["2ec55f5.e6a67a","623cecfa.27a794"]]},{"id":"623cecfa.27a794","type":"influxdb out","z":"3055dcb0.359de4","influxdb":"b542abfa.747a18","name":"DS18B20 Probe","measurement":"tprobe1","precision":"","retentionPolicy":"","x":820,"y":360,"wires":[]},{"id":"b5b0f31f.a0853","type":"cpu","z":"3055dcb0.359de4","name":"","msgCore":false,"msgOverall":true,"msgArray":false,"msgTemp":false,"x":270,"y":440,"wires":[["a056e151.6afbf","c2802b7.5711dd8","dea412fc.542b"]]},{"id":"a056e151.6afbf","type":"ui_gauge","z":"3055dcb0.359de4","name":"","group":"e8bad183.6678b","order":2,"width":0,"height":0,"gtype":"gage","title":"CPU Avg Guage","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"60","seg2":"70","x":820,"y":400,"wires":[]},{"id":"4c9e673f.4ce2d8","type":"cpu","z":"3055dcb0.359de4","name":"CPU Temp","msgCore":false,"msgOverall":false,"msgArray":false,"msgTemp":true,"x":270,"y":560,"wires":[["8c861a3d.4c1a98"]]},{"id":"85143686.681f08","type":"ui_gauge","z":"3055dcb0.359de4","name":"","group":"e8bad183.6678b","order":1,"width":0,"height":0,"gtype":"gage","title":"CPU Temp","label":"C","format":"{{value | number:1}}","min":0,"max":"185","colors":["#00b500","#e6e600","#ca3838"],"seg1":"130","seg2":"160","x":810,"y":520,"wires":[]},{"id":"b13b7567.d0b838","type":"ui_chart","z":"3055dcb0.359de4","name":"","group":"f35a2a60.a84618","order":1,"width":0,"height":0,"label":"CPU Temp","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":810,"y":560,"wires":[[]]},{"id":"c2802b7.5711dd8","type":"ui_chart","z":"3055dcb0.359de4","name":"","group":"f35a2a60.a84618","order":2,"width":0,"height":0,"label":"CPU Avg","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":800,"y":440,"wires":[[]]},{"id":"8c861a3d.4c1a98","type":"function","z":"3055dcb0.359de4","name":"C to F Convert","func":"msg.payload = msg.payload * 1.8 + 32\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":560,"wires":[["85143686.681f08","b13b7567.d0b838","97c4dd26.ca0a4"]]},{"id":"97c4dd26.ca0a4","type":"influxdb out","z":"3055dcb0.359de4","influxdb":"4e091687.6e0998","name":"CPU Temp","measurement":"cputemp","precision":"","retentionPolicy":"","x":810,"y":600,"wires":[]},{"id":"dea412fc.542b","type":"influxdb out","z":"3055dcb0.359de4","influxdb":"908bc2f8.71f92","name":"CPU AVG","measurement":"cpuavg","precision":"","retentionPolicy":"","x":800,"y":480,"wires":[]},{"id":"a1a197e8.f86d18","type":"change","z":"3055dcb0.359de4","name":"Convert to number","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":280,"wires":[["bb015aa9.a6d6e8"]]},{"id":"bb015aa9.a6d6e8","type":"switch","z":"3055dcb0.359de4","name":"Drop Reading Spike","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"100","vt":"num"},{"t":"lt","v":"100.1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":840,"y":280,"wires":[["66cdf4ab.498ddc"],["63ee4b02.50e294"]]},{"id":"66cdf4ab.498ddc","type":"debug","z":"3055dcb0.359de4","name":"Bad Reading","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1050,"y":260,"wires":[]},{"id":"78c1dc33.7c7ad4","type":"switch","z":"3055dcb0.359de4","name":"Drop Reading Spike","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"170","vt":"num"},{"t":"lt","v":"170","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":670,"y":120,"wires":[["3988e8a3.ca4038"],["1267a6fd.ceeb29","65692ef6.94d39","dbba57c9.287298"]]},{"id":"3988e8a3.ca4038","type":"debug","z":"3055dcb0.359de4","name":"Bad Reading","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1050,"y":40,"wires":[]},{"id":"8ee6537d.cbbd2","type":"ui_group","z":"","name":"Enviromental Monitor","tab":"6d3d3d0e.1726b4","order":1,"disp":true,"width":"6","collapse":false},{"id":"f069ec14.d011f","type":"ui_group","z":"","name":"Environmental Monitor RH%","tab":"6d3d3d0e.1726b4","order":2,"disp":true,"width":"6","collapse":false},{"id":"fd53e486.008958","type":"ui_group","z":"","name":"Environmental Graphs","tab":"6d3d3d0e.1726b4","order":3,"disp":true,"width":"6","collapse":false},{"id":"c752a989.fd0328","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"monitor","name":"","usetls":false,"tls":""},{"id":"711e24e8.9062dc","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"monitor","name":"","usetls":false,"tls":""},{"id":"b542abfa.747a18","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"monitor","name":"","usetls":false,"tls":""},{"id":"e8bad183.6678b","type":"ui_group","z":"","name":"Systems Monitor","tab":"6d3d3d0e.1726b4","order":4,"disp":true,"width":"6","collapse":false},{"id":"f35a2a60.a84618","type":"ui_group","z":"","name":"Systems Graphs","tab":"6d3d3d0e.1726b4","order":5,"disp":true,"width":"6","collapse":false},{"id":"4e091687.6e0998","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"monitor","name":"","usetls":false,"tls":""},{"id":"908bc2f8.71f92","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"monitor","name":"","usetls":false,"tls":""},{"id":"6d3d3d0e.1726b4","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Flow Info

Created 3 years, 11 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x1)
  • debug (x2)
  • function (x4)
  • inject (x1)
  • switch (x2)
Other

Tags

  • DHT22
  • DS18B20
  • Temperature
  • humidity
  • InfluxDB
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option