# I need help with node red and a temp sensor

**URL:** <https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999>\
**Category:** General\
**Created:** [29 January 2020 15:35 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999 "2020-01-29T15:35:37Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ikke68](https://avatars.discourse-cdn.com/v4/letter/i/b38774/32.png) [@ikke68](https://discourse.nodered.org/u/ikke68)\
**Post date:** [29 January 2020 15:35 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/1 "2020-01-29T15:35:37Z")

</div>

Hi Guys / Girls,

I'm running NodeRed on Home Assistant, i want a flashed sonoff (tasmota) to turn on when the temperature sensor see's its below 10 degrees and turn off when its above 17 degrees. Can anybody please help me i'm stuck on it for 2 days haha. I'm completely new to NodeRed so sorry if it's a weird question or bad language, i'm from The Netherlands 🙂  
If you have any questions feel free to ask!  
Chearz Rens,

---

<div class="post-metadata">

**Author:** ![realjax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/realjax/32/895_2.png) [@realjax](https://discourse.nodered.org/u/realjax)\
**Post date:** [29 January 2020 15:51 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/2 "2020-01-29T15:51:17Z")

</div>

Hi Rens,

Depending on your programming skills you could keep a history of the temperature readings and then do something when the newest value is lower then 10 degrees and the previous value was above it ( when the previous reading was already below 10 do nothing so the sonoff remains switched on). Do something similar when it gets above 17 degrees.

good luck!

Ps. Nothing wrong with your english or question. Ik snapte hem prima. 😄

---

<div class="post-metadata">

**Author:** ![Christian-Me](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/christian-me/32/10774_2.png) [@Christian-Me](https://discourse.nodered.org/u/Christian-Me)\
**Post date:** [29 January 2020 16:01 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/3 "2020-01-29T16:01:40Z")

</div>

Quite difficult to find out what your problem is. Perhaps share the flow you developed so far (please use the compact form and the code \</\> feature and a screenshot (copy paste)

The easiest way to start is connect a switch node to your sensor in and send it to output 1 is if it is below your threshold and 2 if it is above your second threshold. Good that you plan to have a save distance between both otherwise you end up with a lot of on/off events. Then connect a on and off node depending how you send to the command to Tasmota (mqtt?)  
Use debug nodes to observe what is happening (or not)

---

<div class="post-metadata">

**Author:** ![ikke68](https://avatars.discourse-cdn.com/v4/letter/i/b38774/32.png) [@ikke68](https://discourse.nodered.org/u/ikke68)\
**Post date:** [29 January 2020 16:13 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/4 "2020-01-29T16:13:39Z")

</div>

Hi Christian,

```auto
[{"id":"aabfde28.774a2","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"406d0918.0ca6f8","type":"switch","z":"aabfde28.774a2","name":"On or Off","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"10","vt":"num"},{"t":"lte","v":"17","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":220,"wires":[["cdefc1d.f4b3c4"],["ff8350ab.1a7b8"]]},{"id":"cdefc1d.f4b3c4","type":"switch","z":"aabfde28.774a2","name":"aan","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"turn_on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":200,"wires":[["5ba82fc7.aa525","9dc04352.68177"]]},{"id":"ff8350ab.1a7b8","type":"switch","z":"aabfde28.774a2","name":"uit","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"turn_off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":240,"wires":[["5ba82fc7.aa525","9dc04352.68177"]]},{"id":"15e6840d.b878ec","type":"poll-state","z":"aabfde28.774a2","name":"Temp Sensor","server":"1918b849.e24058","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"5","updateIntervalUnits":"seconds","outputinitially":false,"outputonchanged":false,"entity_id":"sensor.sensor2_ds18b20_temperature","state_type":"num","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":150,"y":380,"wires":[["406d0918.0ca6f8","5ba82fc7.aa525"]]},{"id":"5ba82fc7.aa525","type":"debug","z":"aabfde28.774a2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":200,"wires":[]},{"id":"9dc04352.68177","type":"Tasmota Switch","z":"aabfde28.774a2","broker":"20252510.c9393a","device":"Sonoff_Over","name":"Kachel","fullTopic":"","cmndPrefix":"Sonoff_Over/stat/POWER = ON","statPrefix":"","telePrefix":"","outputs":"1","onValue":"ON","offValue":"OFF","toggleValue":"","x":590,"y":140,"wires":[[]]},{"id":"1918b849.e24058","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"20252510.c9393a","type":"mqtt-broker","z":"","name":"SensorWoonkamer","broker":"192.168.2.28","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

you mean this code? i also posted a screenshot of my flow.

 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/b/8b1a073ca522a3519385fcaf0e3940a0756e6c59.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 January 2020 16:38 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/5 "2020-01-29T16:38:40Z")

</div>

Have a look at node-red-contrib-ramp-thermostat, that will do exactly what you want. You don't need to use the ramp feature. Set the setpoint to 13.5 and the hysteresis to 7 (I think, you might need to experiment a bit with the settings). Drive it from some inject nodes first with output going to a debug node, to check it does what you want.

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [29 January 2020 17:04 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/6 "2020-01-29T17:04:49Z")

</div>

Besides using @Colin's suggestion, if you only need the hysteresis feature, you could use the `dsm` node. See the wiki [https://github.com/cflurin/node-red-contrib-dsm/wiki/Hysteresis](https://github.com/cflurin/node-red-contrib-dsm/wiki/Hysteresis).

Or in in your case import this flow:

```auto
[{"id":"2ae3d9f2.25af96","type":"inject","z":"6ff0723.8c6b78c","name":"","topic":"","payload":"13","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":3720,"wires":[["5d5d3469.17186c"]]},{"id":"fcf08853.c9e048","type":"inject","z":"6ff0723.8c6b78c","name":"","topic":"","payload":"18","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":3680,"wires":[["5d5d3469.17186c"]]},{"id":"74dfaf46.244bf","type":"inject","z":"6ff0723.8c6b78c","name":"","topic":"","payload":"9","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":3760,"wires":[["5d5d3469.17186c"]]},{"id":"b49fec79.ac7ed","type":"debug","z":"6ff0723.8c6b78c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","x":610,"y":3720,"wires":[]},{"id":"5d5d3469.17186c","type":"dsm","z":"6ff0723.8c6b78c","name":"hysteresis","sm_config":"{\n \"currentState\": \"undefined\",\n \"states\": {\n \"undefined\": {\n \"cross_high\": \"high\",\n \"cross_low\": \"low\",\n \"inter\": \"deadband\"\n },\n \"high\": {\n \"cross_low\": \"low\",\n \"inter\": \"deadband\"\n },\n \"low\": {\n \"cross_high\": \"high\",\n \"inter\": \"deadband\"\n },\n \"deadband\": {\n \"cross_high\": \"high\",\n \"cross_low\": \"low\"\n }\n },\n \"data\": {\n \"setpoint_high\": 17,\n \"setpoint_low\": 10,\n \"greater_high\": \"off\",\n \"less_low\": \"on\"\n },\n \"methods\": {\n \"setpoint_high\": {\n \"name\": \"setData\"\n },\n \"setpoint_low\": {\n \"name\": \"setData\"\n },\n \"onBeforeTransition\": [\n \"if (!msg.topic) msg.topic = 'evaluade';\"\n],\n \"evaluade\": [\n \"if(msg.payload > sm.data.setpoint_high)\",\n \" resume('cross_high', msg);\",\n \"else if (msg.payload < sm.data.setpoint_low)\",\n \" resume('cross_low', msg);\",\n \"else {\",\n \" resume('inter', msg);\",\n \"}\",\n \"output = false;\"\n],\n \"cross_high\": [\n \"msg.payload = sm.data.greater_high;\",\n \"sm.fill = 'yellow';\"\n],\n \"cross_low\": [\n \"msg.payload = sm.data.less_low;\",\n \"sm.fill = 'green';\"\n],\n \"inter\": [\n \"sm.fill = 'grey';\",\n \"output = false;\"\n],\n \"status\": {\n \"fill\": {\n \"get\": \"sm.fill;\"\n },\n \"shape\": \"dot\",\n \"text\": {\n \"get\": \"sm.currentState;\"\n }\n }\n }\n}","x":450,"y":3720,"wires":[["b49fec79.ac7ed"]]}]

```

Note: you need to install the contrib node `dsm`.

---

<div class="post-metadata">

**Author:** ![ikke68](https://avatars.discourse-cdn.com/v4/letter/i/b38774/32.png) [@ikke68](https://discourse.nodered.org/u/ikke68)\
**Post date:** [29 January 2020 19:30 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/7 "2020-01-29T19:30:30Z")

</div>

Hi Cflurin,

What do you mean by import this flow? Im new to node, and i dont get much off it but that will change hopefully soon 🙂 any change you could make a preview for me or a list of wich nodes and wich config for each one, and possibly what variables i can config myself:)

Have a nice day or evening depending on where you are!

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [29 January 2020 19:42 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/8 "2020-01-29T19:42:52Z")

</div>

> [@ikke68](#):
>
> What do you mean by import this flow?

If you first install the `dsm` node, then highlight & copy the code that cflurin has posted.  
Go to your node-RED hamburger and select `import`.  
Paste the code in the box and press the `import` button. Finally `deploy` the imported flow.

That will create a flow in your node-RED which cflurin is referring to.

![import](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/e/ee4045cc347f0371af59337d3bbd16277eceb0ab.jpeg)

---

<div class="post-metadata">

**Author:** ![ikke68](https://avatars.discourse-cdn.com/v4/letter/i/b38774/32.png) [@ikke68](https://discourse.nodered.org/u/ikke68)\
**Post date:** [1 February 2020 13:15 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/9 "2020-02-01T13:15:22Z")

</div>

Hi Paul,

i tryed to install the dsm node, but i get an error...`2020-02-01T12:36:50.868Z npm install --no-audit --no-update-notifier --save --save-prefix="~" --production node-red-contrib-dsm@0.14.1` any idea how to fix this?

Greatings Rens,

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 February 2020 13:43 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/10 "2020-02-01T13:43:31Z")

</div>

Difficult, since you have not shown us the error.

---

<div class="post-metadata">

**Author:** ![ikke68](https://avatars.discourse-cdn.com/v4/letter/i/b38774/32.png) [@ikke68](https://discourse.nodered.org/u/ikke68)\
**Post date:** [1 February 2020 13:46 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/11 "2020-02-01T13:46:21Z")

</div>

Hi,

Where do i find the error? i check the node red event log and this is al it shows me: `2020-02-01T13:44:41.694Z Install : node-red-contrib-dsm 0.14.1

2020-02-01T13:06:56.066Z npm install --no-audit --no-update-notifier --save --save-prefix="~" --production node-red-contrib-dsm@0.14.1`

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [1 February 2020 13:57 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/12 "2020-02-01T13:57:54Z")

</div>

Use the `Manage palette`.  
Got to the Menu \> Manage palette \> install

---

<div class="post-metadata">

**Author:** ![ikke68](https://avatars.discourse-cdn.com/v4/letter/i/b38774/32.png) [@ikke68](https://discourse.nodered.org/u/ikke68)\
**Post date:** [1 February 2020 14:38 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/13 "2020-02-01T14:38:48Z")

</div>

Hi,

I get the same error `2020-02-01T13:59:05.138Z npm install --no-audit --no-update-notifier --save --save-prefix="~" --production node-red-contrib-dsm@0.14.1`  
The Home Assistant log doesn't say anything about node red any other place i should look?

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [1 February 2020 15:28 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/14 "2020-02-01T15:28:35Z")

</div>

I don't use Home Assistant. Try to install another node. I don't think this is a dsm issue.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 February 2020 16:47 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/15 "2020-02-01T16:47:15Z")

</div>

> [@ikke68](#):
>
> Where do i find the error? i

That is not an error, that looks correct. What makes you think there is an error?

---

<div class="post-metadata">

**Author:** ![ikke68](https://avatars.discourse-cdn.com/v4/letter/i/b38774/32.png) [@ikke68](https://discourse.nodered.org/u/ikke68)\
**Post date:** [1 February 2020 18:16 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/16 "2020-02-01T18:16:08Z")

</div>

Hi,

Because it doesn't install the dsm, i'm not able to install any more plugins...  
I will reinstall the plugin and then hope it will work :}

---

<div class="post-metadata">

**Author:** ![ikke68](https://avatars.discourse-cdn.com/v4/letter/i/b38774/32.png) [@ikke68](https://discourse.nodered.org/u/ikke68)\
**Post date:** [1 February 2020 18:20 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/17 "2020-02-01T18:20:36Z")

</div>

i just removed it and im not able to install it again... if i click the button it doesnt do anything and it doesnt show in the log file.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 February 2020 18:24 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/18 "2020-02-01T18:24:47Z")

</div>

> [@ikke68](#):
>
> if i click the button it doesnt do anything

What button? I am having difficulty understanding what problem you are seeing.

---

<div class="post-metadata">

**Author:** ![risquare](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@risquare](https://discourse.nodered.org/u/risquare)\
**Post date:** [3 February 2020 16:49 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/19 "2020-02-03T16:49:14Z")

</div>

If you are comfortable with Tasmota than you should be able to flash the ESP8266 / ESP32 relay software from Zumungo that has this feature built-in. Just connect cheap and very accurate 1wire temperature sensor(s) DS18B20 to any GPIO port (cofigurable) and Zumungo will turn on / off up to 8 relays at any selected temperature and hysteresis.

---

<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:** [3 April 2020 16:49 UTC](https://discourse.nodered.org/t/i-need-help-with-node-red-and-a-temp-sensor/20999/20 "2020-04-03T16:49:20Z")

</div>

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