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