Min-max per period in a subflow

[{"id":"dcd21a88cfb7198c","type":"subflow","name":"min-max","info":"","category":"","in":[{"x":60,"y":200,"wires":[{"id":"e944cd23c54485ed"}]}],"out":[{"x":1280,"y":100,"wires":[{"id":"9e1efc208998899a","port":0}]},{"x":1280,"y":160,"wires":[{"id":"e5a128b19a073798","port":0}]},{"x":1280,"y":240,"wires":[{"id":"ce5640cc05a5e539","port":0}]}],"env":[],"meta":{},"color":"#DDAA99","status":{"x":580,"y":280,"wires":[{"id":"6bc11d503c8a53b3","port":0}]}},{"id":"233b8a38e12503ee","type":"smooth","z":"dcd21a88cfb7198c","name":"smooth min","property":"payload","action":"min","count":"100","round":"2","mult":"single","reduce":false,"x":470,"y":120,"wires":[["87c6c098c32bc3e5"]]},{"id":"fdc01609d01b12a8","type":"smooth","z":"dcd21a88cfb7198c","name":"smooth max","property":"payload","action":"max","count":"100","round":"2","mult":"single","reduce":false,"x":470,"y":200,"wires":[["9d0fea4a74249faa"]]},{"id":"87c6c098c32bc3e5","type":"function","z":"dcd21a88cfb7198c","name":"minimum","func":"const type = \"minimum\";\nconst time = time_str(Date.now(), \"HH:MM:SS DD.MM.YYYY\");\nnode.status({ fill: \"red\", shape: \"dot\", text: (\"min \" + msg.payload + \" | \" + time)});\nreturn msg;\n\n//----------------------------------------------------------------------------------------------\n\nfunction time_str(timestamp, format) {\n    const date = new Date(timestamp);\n    const day = date.getDate().toString().padStart(2, '0');\n    const month = (date.getMonth() + 1).toString().padStart(2, '0');\n    const year = date.getFullYear().toString();\n    const hours = date.getHours().toString().padStart(2, '0');\n    const minutes = date.getMinutes().toString().padStart(2, '0');\n    const seconds = date.getSeconds().toString().padStart(2, '0');\n    switch (format) {\n        case \"HH:MM:SS DD.MM.YYYY\":\n            return `${hours}:${minutes}:${seconds} ${day}.${month}.${year}`;\n        case \"DD.MM.YYYY\":\n            return `${day}.${month}.${year}`;\n        case \"HH:MM:SS\":\n            return `${hours}:${minutes}:${seconds}`;\n        case \"HH:MM\":\n            return `${hours}:${minutes}`;\n    }\n}\n\n//----------------------------------------------------------------------------------------------","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":120,"wires":[["7032654a6039b9c1","f946ecb81a7257b2"]]},{"id":"9d0fea4a74249faa","type":"function","z":"dcd21a88cfb7198c","name":"maximum","func":"const type = \"maximum\";\nconst time = time_str(Date.now(), \"HH:MM:SS DD.MM.YYYY\");\nnode.status({ fill: \"red\", shape: \"dot\", text: (\"min \" + msg.payload + \" | \" + time) });\nreturn msg;\n\n//----------------------------------------------------------------------------------------------\n\nfunction time_str(timestamp, format) {\n    const date = new Date(timestamp);\n    const day = date.getDate().toString().padStart(2, '0');\n    const month = (date.getMonth() + 1).toString().padStart(2, '0');\n    const year = date.getFullYear().toString();\n    const hours = date.getHours().toString().padStart(2, '0');\n    const minutes = date.getMinutes().toString().padStart(2, '0');\n    const seconds = date.getSeconds().toString().padStart(2, '0');\n    switch (format) {\n        case \"HH:MM:SS DD.MM.YYYY\":\n            return `${hours}:${minutes}:${seconds} ${day}.${month}.${year}`;\n        case \"DD.MM.YYYY\":\n            return `${day}.${month}.${year}`;\n        case \"HH:MM:SS\":\n            return `${hours}:${minutes}:${seconds}`;\n        case \"HH:MM\":\n            return `${hours}:${minutes}`;\n    }\n}\n\n//----------------------------------------------------------------------------------------------","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":200,"wires":[["3cc5ed835c6345fe","baa8326bcf424a7c"]]},{"id":"9aaf0cf7b9fdea44","type":"function","z":"dcd21a88cfb7198c","name":"function 9","func":"if (context.get('counter') === 0) {\n    context.set(\"min\", msg.payload);\n    context.set('counter', 1);    \n}\nelse{\n    context.set('counter', 0);\n    return {payload: {\"min\" :context.get('min'), \"max\" : msg.payload}};\n}\nreturn null;","outputs":1,"timeout":0,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\ncontext.set(\"counter\",0);","finalize":"","libs":[],"x":1040,"y":160,"wires":[["e5a128b19a073798"]]},{"id":"baa8326bcf424a7c","type":"delay","z":"dcd21a88cfb7198c","name":"","pauseType":"delay","timeout":"20","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":830,"y":180,"wires":[["9aaf0cf7b9fdea44"]]},{"id":"e5a128b19a073798","type":"json","z":"dcd21a88cfb7198c","name":"","property":"payload","action":"","pretty":false,"x":1170,"y":160,"wires":[[]]},{"id":"6bc11d503c8a53b3","type":"status","z":"dcd21a88cfb7198c","name":"","scope":["4ba2d6ef5f06dd7a"],"x":460,"y":280,"wires":[[]]},{"id":"4ba2d6ef5f06dd7a","type":"function","z":"dcd21a88cfb7198c","name":"update","func":"const temp = msg.payload.toFixed(2);\nconst time = time_str(Date.now(), \"HH:MM:SS DD.MM.YYYY\");\nnode.status({ fill: \"red\", shape: \"dot\", text: (\"temp: \" + temp + \" | \" + time) });\nreturn null;\n//----------------------------------------------------------------------------------------------\n\nfunction time_str(timestamp, format) {\n    const date = new Date(timestamp);\n    const day = date.getDate().toString().padStart(2, '0');\n    const month = (date.getMonth() + 1).toString().padStart(2, '0');\n    const year = date.getFullYear().toString();\n    const hours = date.getHours().toString().padStart(2, '0');\n    const minutes = date.getMinutes().toString().padStart(2, '0');\n    const seconds = date.getSeconds().toString().padStart(2, '0');\n    switch (format) {\n        case \"HH:MM:SS DD.MM.YYYY\":\n            return `${hours}:${minutes}:${seconds} ${day}.${month}.${year}`;\n        case \"DD.MM.YYYY\":\n            return `${day}.${month}.${year}`;\n        case \"HH:MM:SS\":\n            return `${hours}:${minutes}:${seconds}`;\n        case \"HH:MM\":\n            return `${hours}:${minutes}`;\n    }\n}\n\n//----------------------------------------------------------------------------------------------","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":270,"y":280,"wires":[[]]},{"id":"7032654a6039b9c1","type":"rbe","z":"dcd21a88cfb7198c","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":790,"y":100,"wires":[["9e1efc208998899a"]]},{"id":"9e1efc208998899a","type":"function","z":"dcd21a88cfb7198c","name":"minimum","func":"const temp = msg.payload.toFixed(2);\nconst time = time_str(Date.now(), \"HH:MM:SS DD.MM.YYYY\");\nnode.status({ fill: \"red\", shape: \"dot\", text: (\"min \" + temp + \" | \" + time) });\nmsg.payload = (\"min \" + temp + \" | \" + time);\nreturn msg;\n\n//----------------------------------------------------------------------------------------------\n\nfunction time_str(timestamp, format) {\n    const date = new Date(timestamp);\n    const day = date.getDate().toString().padStart(2, '0');\n    const month = (date.getMonth() + 1).toString().padStart(2, '0');\n    const year = date.getFullYear().toString();\n    const hours = date.getHours().toString().padStart(2, '0');\n    const minutes = date.getMinutes().toString().padStart(2, '0');\n    const seconds = date.getSeconds().toString().padStart(2, '0');\n    switch (format) {\n        case \"HH:MM:SS DD.MM.YYYY\":\n            return `${hours}:${minutes}:${seconds} ${day}.${month}.${year}`;\n        case \"DD.MM.YYYY\":\n            return `${day}.${month}.${year}`;\n        case \"HH:MM:SS\":\n            return `${hours}:${minutes}:${seconds}`;\n        case \"HH:MM\":\n            return `${hours}:${minutes}`;\n    }\n}\n\n//----------------------------------------------------------------------------------------------","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":920,"y":100,"wires":[[]]},{"id":"3cc5ed835c6345fe","type":"rbe","z":"dcd21a88cfb7198c","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":790,"y":240,"wires":[["ce5640cc05a5e539"]]},{"id":"ce5640cc05a5e539","type":"function","z":"dcd21a88cfb7198c","name":"maximum","func":"const temp = msg.payload.toFixed(2);\nconst time = time_str(Date.now(), \"HH:MM:SS DD.MM.YYYY\");\nnode.status({ fill: \"red\", shape: \"dot\", text: (\"max \" + temp + \" | \" + time) });\nmsg.payload = (\"max \" + temp + \" | \" + time);\nreturn msg;\n\n//----------------------------------------------------------------------------------------------\n\nfunction time_str(timestamp, format) {\n    const date = new Date(timestamp);\n    const day = date.getDate().toString().padStart(2, '0');\n    const month = (date.getMonth() + 1).toString().padStart(2, '0');\n    const year = date.getFullYear().toString();\n    const hours = date.getHours().toString().padStart(2, '0');\n    const minutes = date.getMinutes().toString().padStart(2, '0');\n    const seconds = date.getSeconds().toString().padStart(2, '0');\n    switch (format) {\n        case \"HH:MM:SS DD.MM.YYYY\":\n            return `${hours}:${minutes}:${seconds} ${day}.${month}.${year}`;\n        case \"DD.MM.YYYY\":\n            return `${day}.${month}.${year}`;\n        case \"HH:MM:SS\":\n            return `${hours}:${minutes}:${seconds}`;\n        case \"HH:MM\":\n            return `${hours}:${minutes}`;\n    }\n}\n\n//----------------------------------------------------------------------------------------------","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":920,"y":240,"wires":[[]]},{"id":"8c4a6cac86b14772","type":"junction","z":"dcd21a88cfb7198c","x":220,"y":120,"wires":[["233b8a38e12503ee"]]},{"id":"e944cd23c54485ed","type":"junction","z":"dcd21a88cfb7198c","x":120,"y":200,"wires":[["8c4a6cac86b14772","4ba2d6ef5f06dd7a","fdc01609d01b12a8"]]},{"id":"f946ecb81a7257b2","type":"junction","z":"dcd21a88cfb7198c","x":740,"y":140,"wires":[["8e3f3be1f19e158d"]]},{"id":"8e3f3be1f19e158d","type":"junction","z":"dcd21a88cfb7198c","x":920,"y":140,"wires":[["9aaf0cf7b9fdea44"]]},{"id":"05c0550d54119a3a","type":"tab","label":"test min-max-subflow","disabled":false,"info":"","env":[]},{"id":"5d4e5cf6922aed31","type":"group","z":"05c0550d54119a3a","name":"","style":{"fill":"#ffefbf","fill-opacity":"0.18","label":true},"nodes":["423eb6cdeabf482a","d7ae60839ab3d0a0","5defb83b8fd005fa","35095317a845ff14","a3bea545b8634a7f","f7ad9d2a379c9c39","473cd1c8608f85cd","77958812a56ce178","a2521ab0de259328","135f35ad9b0a6a63"],"x":74,"y":119,"w":1052,"h":242},{"id":"a2521ab0de259328","type":"junction","z":"05c0550d54119a3a","g":"5d4e5cf6922aed31","x":740,"y":260,"wires":[["77958812a56ce178"]]},{"id":"423eb6cdeabf482a","type":"mqtt in","z":"05c0550d54119a3a","g":"5d4e5cf6922aed31","name":"","topic":"enocean/AUSSEN-HT/Temperature","qos":"0","datatype":"auto-detect","broker":"7b465961f8f7d2d0","nl":false,"rap":true,"rh":0,"inputs":0,"x":240,"y":240,"wires":[["5defb83b8fd005fa","473cd1c8608f85cd"]]},{"id":"d7ae60839ab3d0a0","type":"debug","z":"05c0550d54119a3a","g":"5d4e5cf6922aed31","name":"min","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":790,"y":160,"wires":[]},{"id":"5defb83b8fd005fa","type":"subflow:dcd21a88cfb7198c","z":"05c0550d54119a3a","g":"5d4e5cf6922aed31","name":"min-max-calculation","x":540,"y":240,"wires":[["d7ae60839ab3d0a0"],["f7ad9d2a379c9c39","a2521ab0de259328"],["a3bea545b8634a7f"]]},{"id":"35095317a845ff14","type":"debug","z":"05c0550d54119a3a","g":"5d4e5cf6922aed31","name":"min-max-object-1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":220,"wires":[]},{"id":"a3bea545b8634a7f","type":"debug","z":"05c0550d54119a3a","g":"5d4e5cf6922aed31","name":"max","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":790,"y":300,"wires":[]},{"id":"f7ad9d2a379c9c39","type":"json","z":"05c0550d54119a3a","g":"5d4e5cf6922aed31","name":"","property":"payload","action":"","pretty":false,"x":790,"y":220,"wires":[["35095317a845ff14"]]},{"id":"473cd1c8608f85cd","type":"debug","z":"05c0550d54119a3a","g":"5d4e5cf6922aed31","name":"debug 6","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"counter","x":300,"y":320,"wires":[]},{"id":"77958812a56ce178","type":"debug","z":"05c0550d54119a3a","g":"5d4e5cf6922aed31","name":"min-max-object-2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":260,"wires":[]},{"id":"135f35ad9b0a6a63","type":"inject","z":"05c0550d54119a3a","g":"5d4e5cf6922aed31","name":"","props":[{"p":"reset","v":"0","vt":"num"}],"repeat":"","crontab":"00 00 * * *","once":false,"onceDelay":0.1,"topic":"","x":330,"y":200,"wires":[["5defb83b8fd005fa"]]},{"id":"7b465961f8f7d2d0","type":"mqtt-broker","broker":"10.0.0.43","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":4,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]