# Temperature in Node red

**URL:** <https://discourse.nodered.org/t/temperature-in-node-red/45981>\
**Category:** General\
**Created:** [20 May 2021 14:00 UTC](https://discourse.nodered.org/t/temperature-in-node-red/45981 "2021-05-20T14:00:56Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Warren](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@Warren](https://discourse.nodered.org/u/Warren)\
**Post date:** [20 May 2021 14:00 UTC](https://discourse.nodered.org/t/temperature-in-node-red/45981/1 "2021-05-20T14:00:56Z")

</div>

Hi . Trying to get some help

I have the following setup  
Rapsberry pi  
Relays  
Temperature sensor ds18d20  
So what I'm trying to do is setup the temperature with a slider . Then if the temp from the sensor is below the temp set in the slider, then the relay some switch on or off if temp is above the set temp.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 May 2021 19:48 UTC](https://discourse.nodered.org/t/temperature-in-node-red/45981/2 "2021-05-20T19:48:51Z")

</div>

Hi Warren, welcome to the forum!

It sounds like you have made a stab at creating your flow. If so, providing a copy of the flow would be helpful if you are having problems.

Also letting us know what 'extra' nodes (i.e. node-red-contrib-???) you are using will help and what version of Node-RED and node,js and the dashboare are you using. You can find all three in the startup log for node-red.

What have you tried so far?

---

<div class="post-metadata">

**Author:** ![Warren](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@Warren](https://discourse.nodered.org/u/Warren)\
**Post date:** [20 May 2021 23:23 UTC](https://discourse.nodered.org/t/temperature-in-node-red/45981/3 "2021-05-20T23:23:50Z")

</div>

Hi Zenofmud

Thank you for the replay

The following is install  
node-red-dashboard 2.29.0  
node-red-contrib-ds18b20-sensor  
node-red-contrib-sensor-ds18b20  
node-red-contrib-ui-digital-display  
Node red v1.3.4 on raspberry pi

I have it working with the slider or the senor but with both of them at the some time.

Here is the flow .

```auto
[{"id":"8af81048.8fd3","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"dfc4d3fa.da9c3","type":"change","z":"8af81048.8fd3","name":"","rules":[{"t":"set","p":"router","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":260,"wires":[["e9f22e.53019dd","6a3cb876.bda2c8"]]},{"id":"e8c699c1.7bd3d","type":"inject","z":"8af81048.8fd3","name":"","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"","vt":"string"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":400,"wires":[["f57f5c83.093b4"]]},{"id":"f57f5c83.093b4","type":"switch","z":"8af81048.8fd3","name":"","property":"router","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"lte","v":"25","vt":"str"},{"t":"gte","v":"25","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":310,"y":400,"wires":[["6eea1b84.8be9ac"],["a2c95c56.ee0cd","c6075a73.eb74c8"],["cc7a93bb.557c4","7a36d7b.28cc328"]]},{"id":"6eea1b84.8be9ac","type":"debug","z":"8af81048.8fd3","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1150,"y":340,"wires":[]},{"id":"a2c95c56.ee0cd","type":"debug","z":"8af81048.8fd3","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1110,"y":500,"wires":[]},{"id":"e9f22e.53019dd","type":"debug","z":"8af81048.8fd3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":860,"y":240,"wires":[]},{"id":"fe56a2a0.62a95","type":"ui_slider","z":"8af81048.8fd3","name":"","label":"slider","tooltip":"","group":"415ff655.a1d8f8","order":4,"width":0,"height":0,"passthru":true,"outs":"all","topic":"topic","topicType":"msg","min":"1","max":"60","step":"2","x":340,"y":120,"wires":[["dfc4d3fa.da9c3"]]},{"id":"6a3cb876.bda2c8","type":"ui_digital_display","z":"8af81048.8fd3","name":"","group":"415ff655.a1d8f8","order":5,"width":0,"height":0,"digits":5,"decimals":1,"x":770,"y":180,"wires":[]},{"id":"cc7a93bb.557c4","type":"debug","z":"8af81048.8fd3","name":"25","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1060,"y":640,"wires":[]},{"id":"9d708e6d.a4fdf","type":"sensor-ds18b20","z":"8af81048.8fd3","name":"Temp","topic":"","sensorid":"28-3c01d607c958","timer":"1","repeat":true,"x":450,"y":60,"wires":[["bee69718.fd14c8"]]},{"id":"4b7d05ce.27cf1c","type":"inject","z":"8af81048.8fd3","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":80,"wires":[["9d708e6d.a4fdf"]]},{"id":"65fe6f63.dfffa","type":"rpi-gpio out","z":"8af81048.8fd3","name":"","pin":"40","set":"","level":"0","freq":"","out":"out","x":810,"y":660,"wires":[]},{"id":"c6075a73.eb74c8","type":"change","z":"8af81048.8fd3","name":"on","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":600,"wires":[["65fe6f63.dfffa"]]},{"id":"7a36d7b.28cc328","type":"change","z":"8af81048.8fd3","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":760,"wires":[["735602e3.93ca1c"]]},{"id":"735602e3.93ca1c","type":"rpi-gpio out","z":"8af81048.8fd3","name":"","pin":"40","set":"","level":"0","freq":"","out":"out","x":890,"y":780,"wires":[]},{"id":"bee69718.fd14c8","type":"debug","z":"8af81048.8fd3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1010,"y":60,"wires":[]},{"id":"415ff655.a1d8f8","type":"ui_group","name":"Test","tab":"622a3108.4411e","order":1,"disp":true,"width":"6","collapse":false},{"id":"622a3108.4411e","type":"ui_tab","name":"Test machine","icon":"dashboard","disabled":false,"hidden":false}]

```

post editied to add ``` before and after code paste to make it importable

---

<div class="post-metadata">

**Author:** ![Cyprus125](https://avatars.discourse-cdn.com/v4/letter/c/4bbf92/32.png) [@Cyprus125](https://discourse.nodered.org/u/Cyprus125)\
**Post date:** [20 May 2021 23:51 UTC](https://discourse.nodered.org/t/temperature-in-node-red/45981/4 "2021-05-20T23:51:21Z")

</div>

Are you doing something for aquariums?

---

<div class="post-metadata">

**Author:** ![Warren](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@Warren](https://discourse.nodered.org/u/Warren)\
**Post date:** [21 May 2021 05:50 UTC](https://discourse.nodered.org/t/temperature-in-node-red/45981/5 "2021-05-21T05:50:19Z")

</div>

Yes basically the same principle.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [21 May 2021 08:28 UTC](https://discourse.nodered.org/t/temperature-in-node-red/45981/6 "2021-05-21T08:28:37Z")

</div>

> [@Warren](#):
>
> node-red-contrib-ds18b20-sensor  
> node-red-contrib-sensor-ds18b20

Why have you got both of these installed?

---

<div class="post-metadata">

**Author:** ![Warren](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@Warren](https://discourse.nodered.org/u/Warren)\
**Post date:** [21 May 2021 08:42 UTC](https://discourse.nodered.org/t/temperature-in-node-red/45981/7 "2021-05-21T08:42:11Z")

</div>

sorry I'm using rpi-ds18b20

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [21 May 2021 08:46 UTC](https://discourse.nodered.org/t/temperature-in-node-red/45981/8 "2021-05-21T08:46:27Z")

</div>

> [@Warren](#):
>
> So what I'm trying to do is setup the temperature with a slider . Then if the temp from the sensor is below the temp set in the slider, then the relay some switch on or off if temp is above the set temp.

ok, looking at your flow, you need to compare the incoming temperature from the sensor to the value you have stored in the flow variable and have that result control the relays

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [21 May 2021 08:49 UTC](https://discourse.nodered.org/t/temperature-in-node-red/45981/9 "2021-05-21T08:49:41Z")

</div>

> [@Warren](#):
>
> sorry I'm using rpi-ds18b20

you are using node-red-contrib-sensor-ds18b20 so you should get rid of the other one to keep from confusing your self (and others 😁)

---

<div class="post-metadata">

**Author:** ![sfedo](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@sfedo](https://discourse.nodered.org/u/sfedo)\
**Post date:** [21 May 2021 13:13 UTC](https://discourse.nodered.org/t/temperature-in-node-red/45981/10 "2021-05-21T13:13:29Z")

</div>

I dont know if I got you right, but here is what you can do:

you can store the value from the sensor into context with flow.set into e.g. sensorTemp and the value of slider: setupTemp.

then you create a function where you compare this both values triggered with an interval.

```auto
[{"id":"1c42a283.991b2d","type":"ui_slider","z":"8af81048.8fd3","name":"","label":"slider","tooltip":"","group":"415ff655.a1d8f8","order":4,"width":0,"height":0,"passthru":true,"outs":"all","topic":"topic","topicType":"msg","min":"1","max":"60","step":"2","x":170,"y":680,"wires":[["c6a4cb7.69a5d38"]]},{"id":"c6a4cb7.69a5d38","type":"change","z":"8af81048.8fd3","name":"","rules":[{"t":"set","p":"setupTemp","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":680,"wires":[[]]},{"id":"f0814783.f25ae8","type":"sensor-ds18b20","z":"8af81048.8fd3","name":"Temp","topic":"","sensorid":"28-3c01d607c958","timer":"1","repeat":true,"x":230,"y":760,"wires":[["355ac5d4.71a31a"]]},{"id":"355ac5d4.71a31a","type":"change","z":"8af81048.8fd3","name":"","rules":[{"t":"set","p":"sensorTemp","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":760,"wires":[[]]},{"id":"812dd060.a385c","type":"inject","z":"8af81048.8fd3","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"10","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":860,"wires":[["59225cb3.f2b664"]]},{"id":"59225cb3.f2b664","type":"function","z":"8af81048.8fd3","name":"","func":"if (flow.get(\"setupTemp\")>flow.get(\"sensorTemp\")){\n msg.payload = true;\n}else if (flow.get(\"setupTemp\")<flow.get(\"sensorTemp\")){\n msg.payload = false;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":400,"y":860,"wires":[["428a56cd.031548"]]},{"id":"428a56cd.031548","type":"rpi-gpio out","z":"8af81048.8fd3","name":"","pin":"40","set":"","level":"0","freq":"","out":"out","x":600,"y":860,"wires":[]},{"id":"415ff655.a1d8f8","type":"ui_group","name":"Test","tab":"622a3108.4411e","order":1,"disp":true,"width":"6","collapse":false},{"id":"622a3108.4411e","type":"ui_tab","name":"Test machine","icon":"dashboard","disabled":false,"hidden":false}]

```

or you can compare your output of the sensor directly with your stored value from the slider. In this case you need to change the function like this:

```auto
if (msg.payload < flow.get("sliderValue")){
msg.payload=true;
}else if (msg.payload > flow.get("sliderValue")){
msg.payload=false;
}
return msg;

```

---

<div class="post-metadata">

**Author:** ![MecatronicaMADE](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@MecatronicaMADE](https://discourse.nodered.org/u/MecatronicaMADE)\
**Post date:** [21 May 2021 16:35 UTC](https://discourse.nodered.org/t/temperature-in-node-red/45981/11 "2021-05-21T16:35:10Z")

</div>

Hi @Warren, you could store the value from the sensor into context with flow.set, you can use "Change node":

![Captura de pantalla 2021-05-21 a la(s) 11.26.02 a. m.](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/f/5fc82045e0898d8af2fdc225d80cc6fffddb02a4.png)

![Captura de pantalla 2021-05-21 a la(s) 11.26.12 a. m.](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/3/635fa03cfa5829a792d27161af988ef07d7303c8.png)

and then with a "switch node" compare your output of the slider, with your stored value from sensor, "flow.temperature":

![Captura de pantalla 2021-05-21 a la(s) 11.33.51 a. m.](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/e/8ee1647897de9bedb853e17f3f64dd18cdfcba64.png)  
 ![Captura de pantalla 2021-05-21 a la(s) 11.34.09 a. m.](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3c1042bb67b685406d9f01915a95c3bc564087c4.png)

---

<div class="post-metadata">

**Author:** ![Warren](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@Warren](https://discourse.nodered.org/u/Warren)\
**Post date:** [26 May 2021 09:53 UTC](https://discourse.nodered.org/t/temperature-in-node-red/45981/12 "2021-05-26T09:53:18Z")

</div>

Hi All . Thank you for the information . It's helped alot

---

<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:** [25 July 2021 09:53 UTC](https://discourse.nodered.org/t/temperature-in-node-red/45981/13 "2021-07-25T09:53:46Z")

</div>

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