Strange NaN reply

I am getting a bit confused here, I am trying to do an hourly calculation of my energy consumption:

The problem is that I still get the NaN from the last Function node (Hourcons). There are two messages, consisting of numbers, going in to that node for subtraction. Why does it reply Not a Number!?

Without seeing the actual code in that function it's impossible to say.

The usual cause will be some maths operation using undefined rather than a number value.

You could add some node.warn(value) statements in the function to check your values are what you expect and to see where the NaN value is being generated.

Her is the code for the last Node:

image

Copy and pasting the function text is much more helpful than a screenshot as it saves me having to type out any suggestions.

  1. Don't use -= - use -
  2. Have you checked that thishourread and lasthourread are always defined?

Ok, I have changed the -= to just -.

I think that variables thishourread and lasthourread are defined as they returns in the debug as blue figures when the inject node triggers.

This is what I get:

There is an extra , at the end of the key:value.

The debug shows you have thishourread and lasthourread in separate messages.

If you want to perform a calculation using both values you need to get them into the same message. Otherwise, when the function node receives the messages it only has one or the other value.

You can use the Join node to combine the messages into one.

1 Like

This is how this ended up, it is now working!

Thank you very much!

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