# DS18b20 80deg readings can it be filter out in Node Red

**URL:** <https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429>\
**Category:** General\
**Created:** [9 August 2023 08:05 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429 "2023-08-09T08:05:11Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![holmesjohnnyh](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@holmesjohnnyh](https://discourse.nodered.org/u/holmesjohnnyh)\
**Post date:** [9 August 2023 08:05 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/1 "2023-08-09T08:05:11Z")

</div>

Hi I am using the 1 wire node to read 3 ds18b20 sensors on the Raspberry Pi 4 they are the only things I have connected to it. I only read the sensors every 10 minutes via a trigger node. Every now and then I get a reading come through saying 80 DEG C, My question is is there away I could filter the reading so I only get readings say between 10 DEG C and 40 DEG C. I am new to Java so please be gentle with me.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [9 August 2023 08:37 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/2 "2023-08-09T08:37:48Z")

</div>

> [@holmesjohnnyh](#):
>
> My question is is there away I could filter the reading so I only get readings say between 10 DEG C and 40 DEG C.

Yes, but we have to be sure of what your sensor sends exactly. Show us the debug output of this sensor.

For example:

- If it is a number (e.g. `10` / `40` / `80`) then a simple `switch node` will filter this.
- If it _really is_ a string of `10 DEG C` then my first recommendation would be to change the source to output numbers, but if that is not possible then you need to first parse the text into a number. The quickest way is in a function node using `parseInt(msg.payload)` (I am asuming `msg.payload` until you show us the debug output of this sensor)

> [@holmesjohnnyh](#):
>
> I am new to Java

Luckily, this is JavaScript 😉

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [9 August 2023 08:46 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/3 "2023-08-09T08:46:53Z")

</div>

Here's a simple demo flow using a switch node and a function node to filter between 10 and 40 inclusive.

 ![filter_flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/0/2051515c2577b40af02aef74094659c3dcb9ff65.png)

```auto
[{"id":"f41342762ef4551f","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"c4aa58c34193145f","type":"inject","z":"f41342762ef4551f","name":"6","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"6","payloadType":"num","x":190,"y":200,"wires":[["b32c4e317a48dc83","05398bce4bbea395"]]},{"id":"b32c4e317a48dc83","type":"switch","z":"f41342762ef4551f","name":"Check >= 10","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"10","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":200,"wires":[["31cc837d8ce9668e"]]},{"id":"31cc837d8ce9668e","type":"switch","z":"f41342762ef4551f","name":"Check <= 40","property":"payload","propertyType":"msg","rules":[{"t":"lte","v":"40","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":550,"y":200,"wires":[["d857cb8262ecad59"]]},{"id":"d857cb8262ecad59","type":"debug","z":"f41342762ef4551f","name":"debug10","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":200,"wires":[]},{"id":"48aed34f52ff9d92","type":"inject","z":"f41342762ef4551f","name":"10","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":190,"y":240,"wires":[["b32c4e317a48dc83","05398bce4bbea395"]]},{"id":"542dab8423d88945","type":"inject","z":"f41342762ef4551f","name":"40","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"40","payloadType":"num","x":190,"y":280,"wires":[["b32c4e317a48dc83","05398bce4bbea395"]]},{"id":"97dd1f73c1f3fdb8","type":"inject","z":"f41342762ef4551f","name":"41","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"41","payloadType":"num","x":190,"y":320,"wires":[["b32c4e317a48dc83","05398bce4bbea395"]]},{"id":"05398bce4bbea395","type":"function","z":"f41342762ef4551f","name":"Check range","func":"if (msg.payload >= 10 && msg.payload <= 40) {\n return msg;\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":360,"wires":[["ebcf704a9112b886"]]},{"id":"ebcf704a9112b886","type":"debug","z":"f41342762ef4551f","name":"debug11","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":360,"wires":[]},{"id":"5bd1ca2d3d7bc2b7","type":"comment","z":"f41342762ef4551f","name":"Filter on a numeric value in the payload","info":"","x":450,"y":160,"wires":[]}]

```

As @Steve-Mcl said, you need to make sure the input format is 'numeric'.

---

<div class="post-metadata">

**Author:** ![holmesjohnnyh](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@holmesjohnnyh](https://discourse.nodered.org/u/holmesjohnnyh)\
**Post date:** [9 August 2023 09:44 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/4 "2023-08-09T09:44:39Z")

</div>

Steve

The debug node shows this

" 09/08/2023, 10:42:43[node: debug 3](http://192.168.0.18:1880/#)msg.payload : number

24.5 "

---

<div class="post-metadata">

**Author:** ![holmesjohnnyh](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@holmesjohnnyh](https://discourse.nodered.org/u/holmesjohnnyh)\
**Post date:** [9 August 2023 09:46 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/5 "2023-08-09T09:46:35Z")

</div>

Thanks Dave I will have a play with Flow you have sent its very much appreciated.

---

<div class="post-metadata">

**Author:** ![holmesjohnnyh](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@holmesjohnnyh](https://discourse.nodered.org/u/holmesjohnnyh)\
**Post date:** [9 August 2023 10:12 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/6 "2023-08-09T10:12:59Z")

</div>

Thanks again Dave the Function Node is working spot on so was the Switch Node. I need to get my head around Java as Node Red is a great tool even for beginners to the Raspberry Pi.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [9 August 2023 10:15 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/7 "2023-08-09T10:15:34Z")

</div>

Really pleased it is working for you.

Please stop calling it "Java" as the language being used with Node-RED is "JavaScript".  
The two languages are VERY different - one is compiled the other one is interpreted.  
JavaScript (IMHO) is much easier to 'get to grips with' than Java.

Node-RED has many core nodes that will perform a number of things/functions for you. If you can't find a suitable node, then you can always use the 'function' node and write some JavaScript to perform the job !!

---

<div class="post-metadata">

**Author:** ![holmesjohnnyh](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@holmesjohnnyh](https://discourse.nodered.org/u/holmesjohnnyh)\
**Post date:** [9 August 2023 10:29 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/8 "2023-08-09T10:29:26Z")

</div>

Thanks to both I missed the JavaScript bit and am now looking at a number of tutorial site to get a better idea of what I can do with it in the future. Its one big learning curve which I am keen to learn.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [9 August 2023 10:34 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/9 "2023-08-09T10:34:31Z")

</div>

No idea what you are doing with your Raspberry Pi-4 - which is an expensive piece of kit.

Just to say... most of my IoT students make use of Wemos D1 Mini or ESP-32 S2-Mini microcontrollers (really inexpensive devices less than GBP £2 each) to which they connect their sensors/transducers. Then using MQTT they send readings to Node-RED running on a Raspberry Pi (which is sort of acting as a server). I have the same set-up at home running my home-automation and security lighting system.

 ![bme280_LEDS](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/558c109a67483888985c7724503fa436c26cb73f.jpeg)

 ![three_leds](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/b/db28611fd561c1640d74f2356f10aa05260fb3be.jpeg)

 ![neo-pixels](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/0/d03a98ec6c03e611c2dd73b6f77520853c63aaee.jpeg)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [9 August 2023 11:07 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/10 "2023-08-09T11:07:00Z")

</div>

Dave's advice about connecting sensors, leds etc to a Wemos D1 Mini is wise.  
The white board in his photos is called a breadboard.

A Raspberry Pi is surprisingly easy to damage, either by knocking tiny chips off the surface or by connecting wires to the wrong GPIO pins.

If your Pi (in a case of some sort) sits quietly on the desk while you experiment on a breadboard, the Pi will probably last much longer.

In Node-red you have chosen the best language to use on the Pi, though some knowledge of Bash and Python will be useful too.  
Personally I use either C with the Arduino IDE or Tasmota to run my Wemos boards.

Enjoy your explorations 😀

---

<div class="post-metadata">

**Author:** ![holmesjohnnyh](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@holmesjohnnyh](https://discourse.nodered.org/u/holmesjohnnyh)\
**Post date:** [9 August 2023 11:50 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/11 "2023-08-09T11:50:02Z")

</div>

I am experimenting with both approaches at the moment I use a ESP32 with one sensor but this may get changed to having the 3 sensor, and as suggested just use the PI as a serve as the main point is having access from anywhere using VNC.

 ![IMG_3048](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/5/055df77481ee88565baf7b6a1e94c1fb64868650.jpeg)  
 ![IMG_3049](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/472f248e50641b6c68d01a31f3387a4be7204566.jpeg)  
 ![Node ReD Dashboard](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/4/4432b37a5ad9c545768912172e3c26f788854b0d.jpeg)  
 ![Node RED Flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/8/88465a025850294f463575149385895abf9affd1.jpeg)

John

---

<div class="post-metadata">

**Author:** ![holmesjohnnyh](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@holmesjohnnyh](https://discourse.nodered.org/u/holmesjohnnyh)\
**Post date:** [9 August 2023 11:52 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/12 "2023-08-09T11:52:52Z")

</div>

The ESP32 is planned to also have a solid state relay to control a heater.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [9 August 2023 12:04 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/13 "2023-08-09T12:04:50Z")

</div>

Thanks for sharing your photos as to what you are doing.

I think the point @jbudd was trying to make was... it is very easy to destroy a Raspberry Pi by connecting an input wire to the wrong pin. OK, you may not destroy the Pi but more than likely 'kill' the I/O pin. It's much safer and less costly to use a cheap microcontroller to act as an interface to the outside world.

Quite a few people on the forum run a lite version of Raspbery Pi OS on their Pi(es) together with Node-RED and MQTT (Mosquitto) and connect to it via a browser on their PC/Laptop/Tablet/Phone.

The only mishap I've had with my IoT students over a number of years was a tiny USB connector came off one of our Wemos D1 Mini boards. No way could it be soldered on again, but we managed to connect +3.3V and Gnd to the header pins so could still make use of it.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [9 August 2023 12:21 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/14 "2023-08-09T12:21:10Z")

</div>

I have fried one Pi 3a+ by some sort of short circuit (sweaty finger touching the metal WiFi system cover and gpio perhaps) but two or three Pi 3b and zero 2s by bunging them in a drawer without a case/putting them down on a conductive surface/dropping things on them.  
So I have learned to beware of their physical fragility.

---

<div class="post-metadata">

**Author:** ![holmesjohnnyh](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@holmesjohnnyh](https://discourse.nodered.org/u/holmesjohnnyh)\
**Post date:** [9 August 2023 12:43 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/15 "2023-08-09T12:43:19Z")

</div>

This is great advise in my previous project I had everything hardwired to the Pi which was a nightmare to be honest it was working for 4 years. In this version I did plan on just having the 3 sensor attached, but slowly thinking to just go with the ESP32 doing the sensors. The 1 sensor sketch is working great and has been working for 6 months already during testing. Just need to rewrite the sketch to read the 3 sensors. C/C++ is another language I an learning slowly.

---

<div class="post-metadata">

**Author:** ![holmesjohnnyh](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@holmesjohnnyh](https://discourse.nodered.org/u/holmesjohnnyh)\
**Post date:** [14 August 2023 08:56 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/16 "2023-08-14T08:56:29Z")

</div>

Well I have taken the advise and just setup the pi as the server and now working my way through various improvements to the Esp32 sketch. I am well pleased and feeling a lot happier with this approach.

I have been documenting the progress on github as well

> **[GitHub - johnmholmes/Aquarium\_Monitor\_V2: The Raspberry Pi 4 4 Gig next...](https://github.com/johnmholmes/Aquarium_Monitor_V2/tree/main)**
>
> main

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [14 August 2023 09:05 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/17 "2023-08-14T09:05:52Z")

</div>

I'm impressed with your comprehensive documentation. It 'reads' really well. Keep up the good work.

---

<div class="post-metadata">

**Author:** ![holmesjohnnyh](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@holmesjohnnyh](https://discourse.nodered.org/u/holmesjohnnyh)\
**Post date:** [14 August 2023 09:36 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/18 "2023-08-14T09:36:25Z")

</div>

Thank you sadly with getting older the brain cells forget a lot of good stuff. The first project was built when I was still working and I did not keep a record, so build the new version is like starting from scratch. Hence github and youtube.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [28 August 2023 09:37 UTC](https://discourse.nodered.org/t/ds18b20-80deg-readings-can-it-be-filter-out-in-node-red/80429/19 "2023-08-28T09:37:01Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
