I'm sure @Andrei has done it better than me.
But here's my flow.
[{"id":"e160bf63.005e38","type":"inject","z":"1d85b106.5dfcd7","name":"","topic":"","payload":"25","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":480,"wires":[["a48b7956.f51108"]]},{"id":"fe1338c3.00e4c","type":"inject","z":"1d85b106.5dfcd7","name":"","topic":"","payload":"26","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":430,"wires":[["a48b7956.f51108"]]},{"id":"343da64f.95298a","type":"inject","z":"1d85b106.5dfcd7","name":"","topic":"","payload":"24","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":530,"wires":[["a48b7956.f51108"]]},{"id":"f2a0f4c.a975a08","type":"inject","z":"1d85b106.5dfcd7","name":"","topic":"","payload":"40","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":330,"wires":[["a48b7956.f51108"]]},{"id":"c689a861.885c08","type":"inject","z":"1d85b106.5dfcd7","name":"","topic":"","payload":"41","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":280,"wires":[["a48b7956.f51108"]]},{"id":"a955a7e8.cf2868","type":"inject","z":"1d85b106.5dfcd7","name":"","topic":"","payload":"42","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":230,"wires":[["a48b7956.f51108"]]},{"id":"a48b7956.f51108","type":"function","z":"1d85b106.5dfcd7","name":"Dummy","func":"\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":530,"wires":[["56cc6c42.c53dc4","1e5f8ed2.d8db39"]]},{"id":"56cc6c42.c53dc4","type":"change","z":"1d85b106.5dfcd7","name":"","rules":[{"t":"set","p":"last_temp","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":470,"wires":[[]]},{"id":"1e5f8ed2.d8db39","type":"function","z":"1d85b106.5dfcd7","name":"monitor temperatures","func":"let previous = context.get('previous') || 40;\nlet hot = flow.get('hot') || 0;\n\nnode.warn(hot);\n\nlet t = parseInt(msg.payload);\nif (t < 40)\n{\n // Too HOT.\n flow.set('hot', hot + 1); // Increment counter\n}\nif (t >= 40)\n{\n // Ok range.\n if (hot > 0)\n {\n flow.set('hot', hot - 1); // Decrement counter\n }\n}\nif (t > 45)\n{\n // Really good.\n flow.set('hot',0); // All good. Forget past.\n}\nif (hot > 3) // Change the 3 as needed\n{\n msg.payload = \"ALARM\";\n}\nreturn msg;\n","outputs":1,"noerr":0,"x":520,"y":530,"wires":[["cbbf3b89.c4d308"]]},{"id":"cbbf3b89.c4d308","type":"switch","z":"1d85b106.5dfcd7","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ALARM","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":720,"y":530,"wires":[["20f2fdab.b72002","a5896cf9.e0b028"]]},{"id":"20f2fdab.b72002","type":"function","z":"1d85b106.5dfcd7","name":"DO WHAT IS NEEDED","func":"\nreturn msg;","outputs":1,"noerr":0,"x":930,"y":530,"wires":[[]]},{"id":"a5896cf9.e0b028","type":"debug","z":"1d85b106.5dfcd7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":890,"y":460,"wires":[]},{"id":"c7307bb2.28f5f8","type":"comment","z":"1d85b106.5dfcd7","name":"Bad range","info":"","x":320,"y":480,"wires":[]},{"id":"7624f879.220f8","type":"comment","z":"1d85b106.5dfcd7","name":"Around the danger range","info":"","x":390,"y":330,"wires":[]},{"id":"6d865fea.346908","type":"inject","z":"1d85b106.5dfcd7","name":"","topic":"","payload":"39","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":380,"wires":[["a48b7956.f51108"]]},{"id":"1cb5496d.9ad22f","type":"inject","z":"1d85b106.5dfcd7","name":"","topic":"","payload":"49","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":170,"wires":[["a48b7956.f51108"]]},{"id":"ae98c64d.90d998","type":"inject","z":"1d85b106.5dfcd7","name":"","topic":"","payload":"50","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":120,"wires":[["a48b7956.f51108"]]},{"id":"d407ab65.bc2ef","type":"inject","z":"1d85b106.5dfcd7","name":"","topic":"","payload":"51","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":70,"wires":[["a48b7956.f51108"]]},{"id":"6703ef5e.4cf508","type":"comment","z":"1d85b106.5dfcd7","name":"Good range COLD","info":"","x":380,"y":120,"wires":[]}]
And his use of the delay
node (and reset
) to handle the 2 hour time is way better than how I did it.