hi, I have to calculate the perceived temperature in a home, up to now I have used temperature and humidity (from Knx) to calculate it and the node function has always worked correctly. I would also like to insert the external temperature to improve the calculation but I can't add the variable that comes from openweathermap, is there anyone who can help me. this is the code.
[
{
"id": "a5eb3cc40ea57cab",
"type": "knxUltimate",
"z": "fc02e74f6dca80d1",
"server": "7c03740f.1cbf6c",
"topic": "1/2/10",
"outputtopic": "temp",
"dpt": "9.001",
"initialread": "1",
"notifyreadrequest": false,
"notifyresponse": true,
"notifywrite": true,
"notifyreadrequestalsorespondtobus": true,
"notifyreadrequestalsorespondtobusdefaultvalueifnotinitialized": "0",
"listenallga": false,
"name": "Soggiorno Temperatura",
"outputtype": "write",
"outputRBE": true,
"inputRBE": false,
"formatmultiplyvalue": 1,
"formatnegativevalue": "leave",
"formatdecimalsvalue": "1",
"passthrough": "yes",
"x": 160,
"y": 200,
"wires": [
[
"11eff6c70d4428b1"
]
]
},
{
"id": "0ed21e27550b1391",
"type": "knxUltimate",
"z": "fc02e74f6dca80d1",
"server": "7c03740f.1cbf6c",
"topic": "1/2/5",
"outputtopic": "hum",
"dpt": "5.001",
"initialread": "1",
"notifyreadrequest": false,
"notifyresponse": true,
"notifywrite": true,
"notifyreadrequestalsorespondtobus": true,
"notifyreadrequestalsorespondtobusdefaultvalueifnotinitialized": "0",
"listenallga": false,
"name": "Umidità Soggiorno",
"outputtype": "write",
"outputRBE": true,
"inputRBE": false,
"formatmultiplyvalue": 1,
"formatnegativevalue": "leave",
"formatdecimalsvalue": "1",
"passthrough": "yes",
"x": 150,
"y": 140,
"wires": [
[
"4b44f90c89089c0a"
]
]
},
{
"id": "d573c01db6fe9c8d",
"type": "link in",
"z": "fc02e74f6dca80d1",
"name": "Temperatura_Esterna",
"links": [
"203c779ca6e10649"
],
"x": 385,
"y": 300,
"wires": [
[
"cc9e95ab7dc64387"
]
]
},
{
"id": "c1e1ec04af4f9de0",
"type": "join",
"z": "fc02e74f6dca80d1",
"name": "",
"mode": "custom",
"build": "object",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": true,
"timeout": "",
"count": "3",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 710,
"y": 220,
"wires": [
[
"05f7bc481b3f5606"
]
]
},
{
"id": "cc9e95ab7dc64387",
"type": "change",
"z": "fc02e74f6dca80d1",
"name": "",
"rules": [
{
"t": "set",
"p": "tempc",
"pt": "msg",
"to": "tempc",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 540,
"y": 300,
"wires": [
[
"c1e1ec04af4f9de0"
]
]
},
{
"id": "03ffe1b1a5061a1f",
"type": "debug",
"z": "fc02e74f6dca80d1",
"name": "debug 18",
"active": true,
"tosidebar": true,
"console": true,
"tostatus": true,
"complete": "true",
"targetType": "full",
"statusVal": "payload",
"statusType": "auto",
"x": 910,
"y": 320,
"wires": []
},
{
"id": "11eff6c70d4428b1",
"type": "change",
"z": "fc02e74f6dca80d1",
"name": "temp",
"rules": [
{
"t": "set",
"p": "temp",
"pt": "msg",
"to": "temp",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 550,
"y": 220,
"wires": [
[
"c1e1ec04af4f9de0"
]
]
},
{
"id": "4b44f90c89089c0a",
"type": "change",
"z": "fc02e74f6dca80d1",
"name": "",
"rules": [
{
"t": "set",
"p": "hum",
"pt": "msg",
"to": "hum",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 530,
"y": 160,
"wires": [
[
"c1e1ec04af4f9de0"
]
]
},
{
"id": "05f7bc481b3f5606",
"type": "function",
"z": "fc02e74f6dca80d1",
"name": "Calcolo Ciclo Circadiano",
"func": "// Estrai le letture di temperatura e umidità dal payload\nconst temp = msg.temp;\nconst tempc = msg.tempc;\nconst hum = msg.hum;\n\n// Verifica se siamo in estate (mesi da maggio ad agosto)\nconst isSummer = (new Date().getMonth() >= 5 && new Date().getMonth() <= 8);\n\n// Calcola l'ora corrente\nconst currentHour = new Date().getHours();\n\n// Calcola la variazione oraria in base alla temperatura circadiana\nconst hourlyCorrection = calculateHourlyCorrection(currentHour);\n\n// Applica la variazione oraria alla temperatura interna\nconst adjustedTemp = temp + hourlyCorrection;\n\n// Calcola la temperatura percepita considerando la temperatura esterna\nconst feelsLikeTemperature = calculateFeelsLikeTemperature(adjustedTemp, tempc, hum);\n\n// Restituisci il messaggio modificato\nmsg.payload = feelsLikeTemperature;\nreturn msg;\n\n// Funzione per calcolare la temperatura percepita considerando la temperatura esterna\nfunction calculateFeelsLikeTemperature(temp, tempc, hum) {\n const index = isSummer\n ? calculateSummerDiscomfortIndex(temp, hum)\n : calculateWinterDiscomfortIndex(temp, hum);\n\n // Considera la differenza tra la temperatura interna e la temperatura esterna\n const temperatureDifference = temp - tempc;\n\n // Applica una correzione basata sulla differenza di temperatura interna ed esterna\n const correctedIndex = index + 0.1 * temperatureDifference;\n\n return correctedIndex;\n}\n\n// Funzione per calcolare l'indice di disagio termico in estate\nfunction calculateSummerDiscomfortIndex(temp, hum) {\n return -2.653 + 0.994 * temp + 0.0153 * hum - 0.00878 * temp * hum +\n 0.000817 * Math.pow(temp, 2) + 0.000133 * Math.pow(hum, 2) -\n 0.000344 * Math.pow(temp, 2) * hum + 0.00000714 * Math.pow(temp, 2) * Math.pow(hum, 2) -\n 0.000000127 * Math.pow(temp, 2) * Math.pow(hum, 3);\n}\n\n// Funzione per calcolare l'indice di disagio termico in inverno\nfunction calculateWinterDiscomfortIndex(temp, hum) {\n return 13.12 + 0.6215 * temp - 11.37 * Math.pow(hum, 0.16) + 0.3965 * temp * Math.pow(hum, 0.16);\n}\n\n// Funzione per calcolare la variazione oraria in base alla temperatura circadiana\nfunction calculateHourlyCorrection(hour) {\n // Variazione massima di 0.5 gradi sia in negativo che in positivo\n const amplitude = 0.5;\n const period = 24;\n const offset = 6;\n\n const correction = amplitude * Math.sin(((hour - offset) / period) * (2 * Math.PI));\n\n return correction;\n}",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 930,
"y": 220,
"wires": [
[
"03ffe1b1a5061a1f"
]
]
},
{
"id": "cada1989997d389a",
"type": "comment",
"z": "fc02e74f6dca80d1",
"name": "Temperatura_Esterna",
"info": "",
"x": 160,
"y": 300,
"wires": []
},
{
"id": "7c03740f.1cbf6c",
"type": "knxUltimate-config",
"host": "192.168.1.130",
"port": "3671",
"physAddr": "15.15.22",
"hostProtocol": "TunnelUDP",
"suppressACKRequest": false,
"csv": "",
"KNXEthInterface": "Auto",
"KNXEthInterfaceManuallyInput": "",
"stopETSImportIfNoDatapoint": "stop",
"loglevel": "error",
"name": "Multicast KNX Gateway",
"localEchoInTunneling": true,
"delaybetweentelegrams": "40",
"delaybetweentelegramsfurtherdelayREAD": "1",
"ignoreTelegramsWithRepeatedFlag": false,
"keyringFileXML": "",
"knxSecureSelected": false,
"autoReconnect": "yes"
}
]
admin edit: surrounded code with triple back ticks to make code useable