[Solved] Need help with math conversion

Sorry for the silly newbie questions.

OK so I am getting milliamps and I want amps displayed on my dashboard.

So I use a function node with this and all works great.
var o = msg.payload
msg.payload = msg.payload / 1000
return msg;

Ok now the issue.
I am also getting in watt hours and I want to display that as kWh on the dashboard.
So the same math should work.
var o = msg.payload
msg.payload = msg.payload / 1000
return msg;

But for some reason it does not work the dashboard still displays watt hours.

I don't understand why the math operation is not working?

Running debug on the mqtt output shows.
5/14/2021, 2:36:04 PM[node: 1eeb439b.969b4c
wallcharger/wh : msg.payload : string[6]
"309794"

Running debug on the function node output shows nothing. This I think is telling me that the dashboard is not updating and it showing cached info and that nothing is flowing thru my function node.

I don't get it.

OK so I did figure this out and I wanted to post in case someone else has the same issue.

I just decided to delete the function node and add it again. Then all of a sudden the debug node had output and popped in the formula and its working.

This contains the clue. It is a string and not a number. While JavaScript isn't strongly typed like some languages, even so most Math will only work correctly on an actual number. You can also force a string to a number, there are a couple of different functions that will do that.

1 Like

IC thank you just for my education as I am new could you share in this example how I would go about changing the string to a number. Thanks again.

:upside_down_face:

Yea I deserved that one :rofl:

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