currently have this code but it returns Nan error:
const val = Object.values(msg.payload)
function calculate(array) {
return array.reduce((a, b) => a + b) / array.length;
}
msg.payload = calculate(val)
return msg;
strange, after installation NodeRED Companion (I want to create sensor for average value) it stopped working (NaN error). Even when I uninstalled Node red Companion repository... my current function looks like this:
const val = Object.values(msg.payload)
function calculate(array) {
return array.reduce((a, b) => a + b.value, 0) / array.length;
}
msg.payload = calculate(val)
return msg;