Skip to content

Node Red Temperature

diverjoe edited this page May 16, 2018 · 7 revisions

Temperature Flow

Notes

  • Uses an inexpensive ($3) waterproof digital sensor - DS18B20. This was chosen over an RTD because it does not need signal condition or ANY extra circuits. Just connect it to the Pi and it just works. Also, specs are pretty darn good as well! The DS18B20 uses the 1-Wire protocol that is address based. The sensor has a pre-stamped, unique address in each one made.
  • Used the node-red-contrib-ds18b20-sensor node to connect to the sensor. It is more mature than others and will auto-detect any/all DS18B20's on the system.
  • Values are sent to
    • Dashboard big numbers along with Red/Lime color changes
    • Chart (disconnect right now)
    • InfluxDB/Grafana for graphing
  • Temperature msg goes out for other flows to use like the pH and EC sensors that make Temperature corrections
  • Temperature is changed to a heater command based on a temperature set in the UI

 

README.txt

 

<iframe src="https://raw.githubusercontent.com/diverjoe/FishNet/master/Node%20Red/Temperature/flow.json" frameborder="0" height="400" width="95%"></iframe>

Flow (Node Red Code)

[{"id":"cf2d9801.1a4cc8","type":"function","z":"32844adc.db94a6","name":"C to F","func":"var tempc = msg.payload;\n    tempf = tempc * 9/5 + 32;\n    tempf = Math.round(tempf * 10) / 10;\n    msg.payload = tempf;\n    msg.timestamp = Date.now();\n    msg.topic =  \"temp\";\n    return msg;","outputs":1,"noerr":0,"x":291.00005531311035,"y":222.0000238418579,"wires":[["32119e14.cd37f2","a3b087e.641be78","c5038467.7d9628","29398a10.2fbed6","c5a7db5a.84ae98","97079fa6.a482a"]]},{"id":"8b2c888e.6d8758","type":"ui_chart","z":"32844adc.db94a6","name":"","group":"87c42826.ad3378","order":0,"width":"0","height":"0","label":"Tank Temp &deg; F","chartType":"line","legend":"false","xformat":"dd HH:mm","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"1","removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":true,"x":640,"y":150,"wires":[[],[]]},{"id":"32119e14.cd37f2","type":"ui_text","z":"32844adc.db94a6","group":"87c42826.ad3378","order":0,"width":0,"height":0,"name":"Current Temp on Charts tab","label":"Temp","format":"  {{msg.payload}}&deg; F","layout":"row-left","x":670,"y":280,"wires":[]},{"id":"a3b087e.641be78","type":"mqtt out","z":"32844adc.db94a6","name":"","topic":"Sensor\\TankTemp","qos":"0","retain":"false","broker":"63980a12.cc7494","x":530,"y":552,"wires":[]},{"id":"4a0a42cc.e7050c","type":"influxdb out","z":"32844adc.db94a6","influxdb":"db0b264a.daf448","name":"SensorReadings","measurement":"SensorReadings","precision":"","retentionPolicy":"","x":890,"y":240,"wires":[]},{"id":"c5038467.7d9628","type":"debug","z":"32844adc.db94a6","name":"","active":false,"console":"false","complete":"true","x":460,"y":632,"wires":[]},{"id":"4a3e1296.d4493c","type":"ds18b20","z":"32844adc.db94a6","name":"Temp","sensorid":"28-0516a4256bff","timer":"1","x":131.00005531311035,"y":222.0000238418579,"wires":[["cf2d9801.1a4cc8","36126e8c.269c32"]]},{"id":"36126e8c.269c32","type":"debug","z":"32844adc.db94a6","name":"","active":false,"console":"false","complete":"true","x":290,"y":312,"wires":[]},{"id":"192b51c8.469e0e","type":"inject","z":"32844adc.db94a6","name":"","topic":"","payload":"[]","payloadType":"json","repeat":"","crontab":"","once":false,"x":440,"y":150,"wires":[["8b2c888e.6d8758"]]},{"id":"29398a10.2fbed6","type":"function","z":"32844adc.db94a6","name":"InfluxDB Tags","func":"var origPayload = msg.payload;\n\nmsg.payload = [{\n    value: origPayload,\n},\n{\n    sensor:\"temperature\",\n    type:\"tank\"\n}];\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":240,"wires":[["4a0a42cc.e7050c","ad9467e3.bf9498"]]},{"id":"10bea6f9.1985c9","type":"ui_text","z":"32844adc.db94a6","group":"f09a5c43.cd2cb","order":2,"width":"2","height":"2","name":"Big Temp on Dashboard","label":"<font size='5'>Temp</font>","format":"<font size='4' color={{msg.color}}>{{msg.payload}}&deg; F</font>","layout":"col-center","x":880,"y":190,"wires":[]},{"id":"c5a7db5a.84ae98","type":"function","z":"32844adc.db94a6","name":"Set Color for UI","func":"var level = msg.payload;\nif (  level < 82 || level > 86)\n    {\n        msg.color = 'red';\n    }\nelse\n    {\n        msg.color = 'lime';\n    }\n\n\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":190,"wires":[["10bea6f9.1985c9"]]},{"id":"97079fa6.a482a","type":"function","z":"32844adc.db94a6","name":"Build Heater Msg","func":"var setTemp = context.get(\"setTemp\") || 82;\nvar currentTemp = context.get(\"currentTemp\") || 82;\n\nif (msg.topic === \"temp\")\n{\n    currentTemp = parseInt(msg.payload);\n    context.set(\"currentTemp\", currentTemp);\n}\n\nif (msg.topic === \"setTemp\")\n{\n    setTemp = msg.payload;\n    context.set(\"setTemp\", setTemp);\n}\n\nmsg.topic = \"relays/input/heater\";\nmsg.payload = currentTemp < setTemp ? 'on' : 'off';\nmsg.setTemp = setTemp;\nmsg.currentTemp = currentTemp;\nmsg.channel = 11;\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":420,"wires":[["af9b4193.ad159","caeb360d.1bc4a8"]]},{"id":"ed61fb7b.841cc8","type":"ui_numeric","z":"32844adc.db94a6","name":"Heater Set Temp","label":"Heater","group":"f09a5c43.cd2cb","order":0,"width":0,"height":0,"passthru":true,"topic":"setTemp","format":"{{value}}","min":"80","max":"90","step":1,"x":670,"y":420,"wires":[["97079fa6.a482a"]]},{"id":"af9b4193.ad159","type":"mqtt out","z":"32844adc.db94a6","name":"relays/input/heater","topic":"","qos":"2","retain":"true","broker":"63980a12.cc7494","x":1200,"y":420,"wires":[]},{"id":"caeb360d.1bc4a8","type":"debug","z":"32844adc.db94a6","name":"","active":false,"console":"false","complete":"true","x":1140,"y":320,"wires":[]},{"id":"9eaba993.2d7d98","type":"catch","z":"32844adc.db94a6","name":"","scope":null,"x":100,"y":80,"wires":[["33cd24b3.c037dc"]]},{"id":"33cd24b3.c037dc","type":"debug","z":"32844adc.db94a6","name":"","active":true,"console":"false","complete":"true","x":290,"y":80,"wires":[]},{"id":"ff2629c2.9ac998","type":"inject","z":"32844adc.db94a6","name":"","topic":"","payload":"82","payloadType":"num","repeat":"","crontab":"","once":true,"x":490,"y":420,"wires":[["ed61fb7b.841cc8"]]},{"id":"be3e942a.bc8828","type":"mqtt out","z":"32844adc.db94a6","name":"Heater (3)","topic":"ESP/socket8/3","qos":"2","retain":"true","broker":"63980a12.cc7494","x":710,"y":770,"wires":[]},{"id":"7d33dbdb.99a754","type":"function","z":"32844adc.db94a6","name":"ESP Msg","func":"msg.payload  = msg.payload === \"on\" ? 1 : 0;\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":800,"wires":[["be3e942a.bc8828","a33fcc10.99352"]]},{"id":"a33fcc10.99352","type":"mqtt out","z":"32844adc.db94a6","name":"Heater (4)","topic":"ESP/socket8/4","qos":"2","retain":"true","broker":"63980a12.cc7494","x":720,"y":850,"wires":[]},{"id":"9b1ff512.c8d6d8","type":"mqtt in","z":"32844adc.db94a6","name":"","topic":"relays/input/heater","qos":"2","broker":"63980a12.cc7494","x":280,"y":800,"wires":[["7d33dbdb.99a754"]]},{"id":"ad9467e3.bf9498","type":"debug","z":"32844adc.db94a6","name":"","active":false,"console":"false","complete":"true","x":910,"y":280,"wires":[]},{"id":"dbb0e1b3.89a31","type":"comment","z":"32844adc.db94a6","name":"Send Heater msg to power socket","info":"","x":250,"y":740,"wires":[]},{"id":"87c42826.ad3378","type":"ui_group","z":"","name":"Temperature","tab":"1958420f.a42bfe","order":1,"disp":true,"width":"7"},{"id":"63980a12.cc7494","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"db0b264a.daf448","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"AquaEscape","name":"AquaEscape","usetls":false,"tls":""},{"id":"f09a5c43.cd2cb","type":"ui_group","z":"","name":"Water","tab":"a0b6dffb.c6749","order":1,"disp":true,"width":"7"},{"id":"1958420f.a42bfe","type":"ui_tab","z":"","name":"Charts","icon":"fa-line-chart","order":3},{"id":"a0b6dffb.c6749","type":"ui_tab","z":"","name":"Dashboard","icon":"dashboard","order":1}]

How to hookup 1 or more DS18B20 sensors to a Pi

Clone this wiki locally