Problem topic switch + node function

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

Hi,
I would use a context which allows you to store all the states and avoid having a message that does not contain all elements. The join node expects 3 msgs but does not guarantee that it is a message from each element.

I haven't tested it but it's normally good:

[{"id":"a5eb3cc40ea57cab","type":"knxUltimate","z":"15cdbf1d258ebb57","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":260,"y":820,"wires":[["6c0849769e44e776"]]},{"id":"0ed21e27550b1391","type":"knxUltimate","z":"15cdbf1d258ebb57","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":260,"y":760,"wires":[["6c0849769e44e776"]]},{"id":"d573c01db6fe9c8d","type":"link in","z":"15cdbf1d258ebb57","name":"Temperatura_Esterna","links":["203c779ca6e10649"],"x":345,"y":880,"wires":[["6c0849769e44e776"]]},{"id":"03ffe1b1a5061a1f","type":"debug","z":"15cdbf1d258ebb57","name":"debug 18","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":970,"y":800,"wires":[]},{"id":"05f7bc481b3f5606","type":"function","z":"15cdbf1d258ebb57","name":"Calcolo Ciclo Circadiano","func":"// Estrai le letture di temperatura e umidità dal payload\nconst temp = msg.payload.temp;\nconst tempc = msg.payload.tempc;\nconst hum = msg.payload.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":750,"y":800,"wires":[["03ffe1b1a5061a1f"]]},{"id":"cada1989997d389a","type":"comment","z":"15cdbf1d258ebb57","name":"Temperatura_Esterna","info":"","x":200,"y":880,"wires":[]},{"id":"6c0849769e44e776","type":"function","z":"15cdbf1d258ebb57","name":"function 1","func":"const oldState = context.get(\"weather\") || {};\nconst newState = {\n    ...oldState,\n    [msg.topic]: msg.payload,\n};\n\ncontext.set(\"weather\", newState);\n\nreturn { payload: newState };","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":800,"wires":[["05f7bc481b3f5606"]]}]

You can also add a default value to your calculation node - because the first two calculations will not be good because the last element is still missing in the message.

const temp = msg.paylad.temp || 20;

What do you mean by that? If it is set to object mode and there are 3 different messages with individual topics, then the join node most definitely will (guaranteed) provide a message with all three values (regardless of order or multiple same messages).

You're right, I forgot that this node can count topics. Thanks Steve

The only "drawback" is that this node waits 3 messages to send one to calculation node, you have the choice between calculating at each new status (use the code above) or waiting for the three statuses to calculate (use the code below).

[{"id":"a5eb3cc40ea57cab","type":"knxUltimate","z":"15cdbf1d258ebb57","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":260,"y":820,"wires":[["0ef762bcec2e7f15"]]},{"id":"0ed21e27550b1391","type":"knxUltimate","z":"15cdbf1d258ebb57","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":260,"y":760,"wires":[["0ef762bcec2e7f15"]]},{"id":"d573c01db6fe9c8d","type":"link in","z":"15cdbf1d258ebb57","name":"Temperatura_Esterna","links":["203c779ca6e10649"],"x":345,"y":880,"wires":[["0ef762bcec2e7f15"]]},{"id":"03ffe1b1a5061a1f","type":"debug","z":"15cdbf1d258ebb57","name":"debug 18","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":970,"y":800,"wires":[]},{"id":"05f7bc481b3f5606","type":"function","z":"15cdbf1d258ebb57","name":"Calcolo Ciclo Circadiano","func":"// Estrai le letture di temperatura e umidità dal payload\nconst temp = msg.payload.temp;\nconst tempc = msg.payload.tempc;\nconst hum = msg.payload.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":750,"y":800,"wires":[["03ffe1b1a5061a1f"]]},{"id":"cada1989997d389a","type":"comment","z":"15cdbf1d258ebb57","name":"Temperatura_Esterna","info":"","x":200,"y":880,"wires":[]},{"id":"0ef762bcec2e7f15","type":"join","z":"15cdbf1d258ebb57","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":"num","reduceFixup":"","x":540,"y":800,"wires":[["05f7bc481b3f5606"]]}]

thank you, GogoVega and Steve-Mci,

I tried both ways and the result is this:

And does it work? I see a NaN
Does the link in return the following topic property?

{
  payload: 8.6,
  topic: "tempc"
}

it doesn't work, even though using some changes on the function node it started to work.
even if the perceived temperature value is not correct I can work on it to achieve the result. I attach current screenshot.
many thanks for the support.

Ok i see, try with this:

[{"id":"a5eb3cc40ea57cab","type":"knxUltimate","z":"15cdbf1d258ebb57","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":200,"y":680,"wires":[["6c0849769e44e776"]]},{"id":"0ed21e27550b1391","type":"knxUltimate","z":"15cdbf1d258ebb57","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":200,"y":620,"wires":[["6c0849769e44e776"]]},{"id":"d573c01db6fe9c8d","type":"link in","z":"15cdbf1d258ebb57","name":"Temperatura_Esterna","links":["203c779ca6e10649"],"x":285,"y":740,"wires":[["0ef20b49defae0db"]]},{"id":"03ffe1b1a5061a1f","type":"debug","z":"15cdbf1d258ebb57","name":"debug 18","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":910,"y":660,"wires":[]},{"id":"05f7bc481b3f5606","type":"function","z":"15cdbf1d258ebb57","name":"Calcolo Ciclo Circadiano","func":"// Estrai le letture di temperatura e umidità dal payload\nconst temp = msg.payload.temp;\nconst tempc = msg.payload.tempc;\nconst hum = msg.payload.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":690,"y":660,"wires":[["03ffe1b1a5061a1f"]]},{"id":"cada1989997d389a","type":"comment","z":"15cdbf1d258ebb57","name":"Temperatura_Esterna","info":"","x":140,"y":740,"wires":[]},{"id":"6c0849769e44e776","type":"function","z":"15cdbf1d258ebb57","name":"function 1","func":"const oldState = context.get(\"weather\") || {};\nconst newState = {\n    ...oldState,\n    [msg.topic]: msg.payload,\n};\n\ncontext.set(\"weather\", newState);\n\nreturn { payload: newState };","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":660,"wires":[["05f7bc481b3f5606"]]},{"id":"0ef20b49defae0db","type":"function","z":"15cdbf1d258ebb57","name":"Set tempc","func":"return {\n    payload: msg.tempc,\n    topic: \"tempc\"\n};","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":740,"wires":[["6c0849769e44e776"]]}]

According to your image, the link in node does not return the message in the following form:

{
  payload: 8.6,
  topic: "tempc"
}

Adapt the tempc node as needed to match the tempc payload received

hi, I tried the code you provided but it's the same, I confirm that the ''tempc'' arrives from openweathermap.
I'm currently trying to work on your previous code, which ''seems'' to also work using the external values ​​that influence the temperature perceived inside the house. the result is still not good because the temperature is not correct. thanks again for your support.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.