Temperature Sensor Email alerts help

460 views
Skip to first unread message

Martin Crosbie

unread,
Jan 10, 2018, 7:00:25 PM1/10/18
to Node-RED
Hi All,

Sort of new to Node-Red and still working my around this excellent software :) 

My problem is temperature sensor Email alerts, and too many alerts! 

The way in which I would like the flow to work is upon my sensor reaching either the "upperThreshold of 80°c" and or the "lowerThreshold of 21°c" to send me one Email alert upon reaching the said upper / lower thresholds. what I'm currently experiencing is when the my sensor reaches, the lowerThreshold of 21°c, I receive and alert, yes that's great, but if the temperature continues to drop below 21°c I continue receiving the Email alerts, the same said for the upperThreshold temperature. 

How I would love the sensor Email alert to work, is to send me an Email alert once, upon either of target temperatures has been met. 
Below is a copy of the function node code only in which I'm using. my setup is as follows, "MQTT input node is connected to the Function node then out to the Email node".

[{"id":"40bfe527.4b492c","type":"function","z":"d4c29411.d0cb48","name":"Hot Water","func":"context.previousTemp = context.previousTemp || 0;\nvar temp = msg.payload;\n\nvar upperThreshold = 40;\nvar lowerThreshold = 22;\n\n// Check if the new temp is different from the previous\nif (context.previousTemp != temp){\n\tif ( temp >= upperThreshold){\n\t\tmsg.payload = \"Turn Hot Water Off! Current temperature is \" + String(temp) + \"°C\";\n\t\treturn msg;\n\t}\n\telse if ( temp <= lowerThreshold){\n\t\tmsg.payload = \"Hot Water Required! Current temperature is \" + String(temp) + \"°C\";\n\t\treturn msg;\n\t}\n}","outputs":1,"noerr":0,"x":280,"y":300,"wires":[["46f66ca7.5db9b4","621c0749.ad7098"]]}]


Any help would be gratefully received as I've been tearing my hair out for days on this! 

Thanks

Martin 



Dean Cording

unread,
Jan 10, 2018, 7:12:55 PM1/10/18
to Node-RED
Try this

[{"id":"90dc1e31.cee9d","type":"function","z":"e316ac4b.c85a2","name":"Hot Water","func":"var upperThreshold = 40;\nvar lowerThreshold = 22;\n\n\nvar previousTemp = context.previousTemp || \n        (upperThreshold - lowerThreshold)/2;\n        \nvar temp = msg.payload;\n\ncontext.previousTemp = temp;\n\n\n// Check if the new temp is different from the previous\nif (previousTemp != temp){\n\tif ((previousTemp < upperThreshold) \n\t    && (temp >= upperThreshold)){\n\t\tmsg.payload = \"Turn Hot Water Off! Current temperature is \" + String(temp) + \"°C\";\n\t\treturn msg;\n\t}\n\telse if ((previousTemp > lowerThreshold) \n\t && (temp <= lowerThreshold)){\n\t\tmsg.payload = \"Hot Water Required! Current temperature is \" + String(temp) + \"°C\";\n\t\treturn msg;\n\t}\n}","outputs":1,"noerr":0,"x":268,"y":149,"wires":[[]]}]


Dean

Martin Crosbie

unread,
Jan 10, 2018, 7:40:05 PM1/10/18
to Node-RED
Hi Dean, 

Magic, now works how I wished it to :)

Thank You very much for your quick response and help

Best Regards

Martin

steve rickus

unread,
Jan 11, 2018, 8:52:35 AM1/11/18
to Node-RED

Hi Martin, and welcome to the Node-RED community!

Whenever I have a use case like this, I check for sample flows or contributed nodes on the flows.nodered.org site (although you may have already done this). A quick search for the word "range" returns this node, which may be useful for you:

node-red-contrib-excursion 0.1.7

A node that reports when a value leaves a specified range for a specified period of time.


If you have not used it yet, there is a "Palette Manager" menu option that will install that node, and make it immediately available for use. If it's not what you need, you can remove it the same way. If you get stuck, feel free to ask here, or for more immediate (and shorter) answers, join us on node-red.slack.com (most of us monitor both groups).
--
Steve

Dave Cason

unread,
Apr 8, 2018, 2:27:37 PM4/8/18
to Node-RED
Hi Martin,

I'm doing the same thing ...... sorta.

I have a hot tub that has a sensor in the water and I want to use my node red setup to email me if the tub quits and the water hit a specific temperature.

In my case 93 deg F - can I ask where you found that code you reference below.  I'm a total newbie as well.......

Cheers'
Dave

Colin Law

unread,
Apr 8, 2018, 3:13:57 PM4/8/18
to node...@googlegroups.com
Which bit don't you know how to do? First you have to get the
temperature, then check against the limit, then send the email. Which
bit is causing the problem.

Colin
> --
> http://nodered.org
>
> Join us on Slack to continue the conversation: http://nodered.org/slack
> ---
> You received this message because you are subscribed to the Google Groups
> "Node-RED" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-red+u...@googlegroups.com.
> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/9f1c1912-370c-4329-bf81-201136aa6aa3%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages