Multiply and add (manually entered) numbers

I have three manually entered numbers. I want to multiply two numbers and then add third numbers.
Can someone please assist in choosing right palette and flow.

Manually entered where? And where should the result go? On the dashboard? Show us what you have and what you want to achieve

You should be able to enter and add numbers using the ui dasboard node
here is an example

[{"id":"c80bbf28.a5eed8","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"colour","v":"red","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$round($random()*9)","payloadType":"jsonata","x":90,"y":3660,"wires":[["755df129.aebf08"]]},{"id":"755df129.aebf08","type":"ui_slider","z":"5a245aa1.510164","name":"","label":"1000","tooltip":"","group":"8b5cde76.edd58","order":4,"width":0,"height":0,"passthru":true,"outs":"end","topic":"thousand","topicType":"str","min":0,"max":"10","step":1,"x":230,"y":3680,"wires":[["c900bea7.7f1108"]]},{"id":"c900bea7.7f1108","type":"join","z":"5a245aa1.510164","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":400,"y":3740,"wires":[["46e3c0d7.c48b5"]]},{"id":"46e3c0d7.c48b5","type":"function","z":"5a245aa1.510164","name":"","func":"let thousands = (msg.payload.thousand || 0) * 1000,\nhundreds = (msg.payload.hundred || 0) * 100,\ntens = (msg.payload.ten || 0) * 10,\nunits = msg.payload.unit || 0;\nmsg.payload.total = thousands + hundreds + tens + units;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":3800,"wires":[["8fb379e3.1e2938","64a84df4.8ed5cc"]]},{"id":"4c944021.62a4a","type":"ui_slider","z":"5a245aa1.510164","name":"","label":"100","tooltip":"","group":"8b5cde76.edd58","order":4,"width":0,"height":0,"passthru":true,"outs":"end","topic":"hundred","topicType":"str","min":0,"max":10,"step":1,"x":230,"y":3740,"wires":[["c900bea7.7f1108"]]},{"id":"2f0e72cd.eba9b6","type":"ui_slider","z":"5a245aa1.510164","name":"","label":"10","tooltip":"","group":"8b5cde76.edd58","order":4,"width":0,"height":0,"passthru":true,"outs":"end","topic":"ten","topicType":"str","min":0,"max":10,"step":1,"x":230,"y":3800,"wires":[["c900bea7.7f1108"]]},{"id":"8aea7870.00324","type":"ui_slider","z":"5a245aa1.510164","name":"","label":"1","tooltip":"","group":"8b5cde76.edd58","order":4,"width":0,"height":0,"passthru":true,"outs":"end","topic":"unit","topicType":"str","min":0,"max":10,"step":1,"x":230,"y":3860,"wires":[["c900bea7.7f1108"]]},{"id":"9a2d6f08.539b5","type":"inject","z":"5a245aa1.510164","name":"reset","props":[{"p":"reset","v":"","vt":"date"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":3940,"wires":[["c900bea7.7f1108"]]},{"id":"8fb379e3.1e2938","type":"debug","z":"5a245aa1.510164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":600,"y":3740,"wires":[]},{"id":"64a84df4.8ed5cc","type":"ui_text","z":"5a245aa1.510164","group":"8b5cde76.edd58","order":8,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload.total}}","layout":"row-spread","x":580,"y":3880,"wires":[]},{"id":"33e2c29b.3e992e","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$round($random()*9)","payloadType":"jsonata","x":90,"y":3740,"wires":[["4c944021.62a4a"]]},{"id":"34423f11.ece648","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$round($random()*9)","payloadType":"jsonata","x":90,"y":3800,"wires":[["2f0e72cd.eba9b6"]]},{"id":"f4ec0a9.aefdcf8","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$round($random()*9)","payloadType":"jsonata","x":90,"y":3880,"wires":[["8aea7870.00324"]]},{"id":"8b5cde76.edd58","type":"ui_group","name":"","tab":"8f03e639.85956","order":1,"disp":true,"width":"6","collapse":false},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

If this does not help you will need to give more info.

Left hand side figures are manually entered, to get Target temp.
Target temp = (Actual temp+ (Duration*(heating-cooling-rate(C/min))))

Also please let me know how can i keep C/min figure restricted to two decimals.

Lets take this in steps. The first step is to get all values in one place so you can do the maths.

Step 1

  • Set the topic of each UI input to something suitable
    • avoid spaces and symbols. e.g. actualTemp instead of Actual Temp
  • feed the values of these UI inputs into a join node
    • Set the join node to key/value object & a count of 4.
  • Connect a debug node to the join node & try entering some values - you SHOULD see all values in one payload.

Step 2

  • after you complete step 1
1 Like

image

So close :slight_smile:

Change the "using the value of msg._______ as the key" back to msg.topic

That way, your 4 values in the payload will be named as the topic you entered on the UI elements.

image

ok, so now you have all values in one place...

Step 2.

Connect the join node to a function node & enter...

//Target temp = (Actual temp+ (Duration*(heating-cooling-rate(C/min))))

var ActualTemp = msg.payload.ActualTemp;
var Ratehr = msg.payload.Ratehr;
var RateMin = msg.payload.RateMin;
var DurationMin = msg.payload.DurationMin;
msg.topic = "Target Temp";
msg.payload = (ActualTemp + (DurationMin * (Ratehr / RateMin))); // or whatever your calculation is
return msg;

Add a debug node after the function to check the output

Thanks a lot Steve, Just one query, How can we restrict Function outcome to round figure?

You should never really round the value before display (as you lose precision)

However for display purposes, you can use angular decimal pipe for formatting in the UI text.

I don't remember the format off the top of my head. Something like {payload | number:0} Search the forum.

Thanks Steve,
I used .toFixed(0) at the end of msg.Payload.
It works fine.

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