I need help with node red and a temp sensor

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 :slight_smile:
If you have any questions feel free to ask!
Chearz Rens,

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. :smile:

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)

Hi Christian,

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

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.

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.

Or in in your case import this flow:

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

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

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

2 Likes

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,

Difficult, since you have not shown us the error.

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`

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

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?

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

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

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

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.

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

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.

1 Like

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