How to disgard NaN messages

A readout of my energy Smart meter gives me different values. Sometimes it gives a NaN value and sometimes the real value of the Gas-meter. How do I change my fow to disguard the NaN values and only let the real values pass.

flows.json (2.2 KB)

Thanks for a reply.

A quick easy solution is to use isNaN in a function node...

if(isNaN(msg.payload)) {
  return null; //halt flow
}
return msg;

Note, isNaN expects a number.

1 Like

Thank you Steve, it works just fine.:+1:

Does using a Switch node to test for is of type Number reject NaN? I can't test it at the moment. If so then that could be used to pass only good numbers.
image

That does not work because NaN is also of type number. The sollution Steve gave does work.

I did wonder whether that would be the case. So NaN is a Number and is Not a Number at the same time!

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