Help ME with calculating the percentage

I want to add two values received from OPC UA, calculate the percentage of one of these values in the sum, and display it on the screen. How can I do this?"

It would help if you shared an example of the data you are receiving and perhaps share what you've tried already?

Do you have Dashboard working for example? If so, which one?


I want to calcculate percentage fo Kenet 1 Çıkış OK and Kenet 1 Çıkış 1 NOK value

Due to the fact items arriving from seprate are always separate messages, you need to combine the items of interest into one message so that you can access them both at the same time.

Luckily this is pretty simple - see this article in the cookbook for an example of how to join messages into one object.

Once you have both values in a single message, your calculation is pretty simple.

Use debug nodes to understand what is happening in your flows

between the input link node and the ui display node, add either a function node or a change node.

For a function node, something like this should work (untested):

msg.percent = 100 * msg.NOK / msg.OK
return msg

For a change node, you can use an Expression to do a similar calculation.

it didnt work . ı saw only NOK value.

I think we need to see a few of the messages that contain Kenet 1 Çıkış data.

Can you put some debug nodes in your flow and post the output here?
An image might be OK but the actual data is better, copied from the debug pane and posted between lines with backticks like this
image

DEBUG

Thats my data

As I said before...

A pretty minimal response, yet enough to confirm that the values are in two separate messages and as @Steve-Mcl says, you need to get them into a single message.

It looks like msg.topic is a JavaScript object rather than a string. I wonder if that will hamper the join node.

These values coming from opc ua and data types are Uınt16 .

Yes, that is clear from your screenshots.

You STILL need to get both payloads into a single msg to you can compare the two.

this is fairly basic but important knowledge in order to be successful in Node-RED.

It may be worth you spending a little time learning the basics?

I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

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