Hi, i’ve try to do a simple array of numbers (temperature from 3 sensors) and an average of this 3, but i don’t know why the average is wrong.
This is my code
[{"id":"87042901f1358814","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"dca3cca7.f1566","type":"inject","z":"87042901f1358814","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":80,"y":520,"wires":[["960b7ca3e71bc732","6d65c3dc8b03afb7","785eeec847419e54"]]},{"id":"960b7ca3e71bc732","type":"api-current-state","z":"87042901f1358814","name":"","server":"5342fb6.0acd404","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.temp_bagno_temperature","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":340,"y":440,"wires":[["3255d1fa.3cf55e"]]},{"id":"6d65c3dc8b03afb7","type":"api-current-state","z":"87042901f1358814","name":"","server":"5342fb6.0acd404","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.wellbeing_temp","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":370,"y":520,"wires":[["3255d1fa.3cf55e"]]},{"id":"3255d1fa.3cf55e","type":"join","z":"87042901f1358814","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"payload","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":630,"y":520,"wires":[["77c2f63818d5ef4c"]]},{"id":"6c921b40.2a0964","type":"debug","z":"87042901f1358814","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1000,"y":520,"wires":[]},{"id":"785eeec847419e54","type":"api-current-state","z":"87042901f1358814","name":"","server":"5342fb6.0acd404","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"climate.riscaldamento","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"$entity().attributes.current_temperature","valueType":"jsonata"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":370,"y":600,"wires":[["3255d1fa.3cf55e"]]},{"id":"77c2f63818d5ef4c","type":"function","z":"87042901f1358814","name":"","func":"function sumArray(array) {\nvar sum = 0;\n for (var index = 0; index < array.length; index++){ // 3 values in a for loop\n if(!isNaN(array[index])){ // check if value is a number\n sum += array[index] // Add number on each iteration\n }\n }\n return sum;\n}\n\nmsg.payload = sumArray(msg.payload) // send value to function\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":520,"wires":[["6c921b40.2a0964"]]},{"id":"5342fb6.0acd404","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]