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

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.

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)

Luckily, this is JavaScript :wink:

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

[{"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'.

Steve

The debug node shows this

" 09/08/2023, 10:42:43node: debug 3msg.payload : number

24.5 "

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

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.

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 !!

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.

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.

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 :grinning:

1 Like

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.




John

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

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.

1 Like

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.

2 Likes

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.

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

1 Like

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

1 Like

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.

2 Likes

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