2 msg.topic in calculation function node

i am trying to make a calculation in a function node with 2 input msg.topic value's.
can sombody tell me wath i am doing wrong.

[{"id":"6cbfa85e.a749a8","type":"debug","z":"d5546796.194978","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":570,"y":140,"wires":[]},{"id":"a3818b6a.0226e8","type":"function","z":"d5546796.194978","name":"gekozen dim percentage","func":"msg.payload = 100 - (msg.payload);\nmsg.topic = \"procent2\";\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":320,"wires":[["e32ad161.289ea","55d05e31.bcfa7"]]},{"id":"e32ad161.289ea","type":"debug","z":"d5546796.194978","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":890,"y":320,"wires":[]},{"id":"55d05e31.bcfa7","type":"function","z":"d5546796.194978","name":"r waarde","func":"val1 = msg.r1\nval2 = msg.procent2\n\nmsg.payload = val2 / 100 * val1;\nmsg.topic = \"r\";\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":220,"wires":[["701e536.6d647ac"]]},{"id":"701e536.6d647ac","type":"debug","z":"d5546796.194978","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":890,"y":140,"wires":[]},{"id":"4f36d145.d98a4","type":"ui_slider","z":"d5546796.194978","name":"","label":"Dimmer","group":"fca18ac4.088f68","order":4,"width":"6","height":"1","passthru":true,"topic":"procent","min":"0","max":"100","step":"2","x":380,"y":320,"wires":[["928022ac.2d3ec","a3818b6a.0226e8"]]},{"id":"928022ac.2d3ec","type":"debug","z":"d5546796.194978","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":390,"y":260,"wires":[]},{"id":"958278b7.d96368","type":"ui_numeric","z":"d5546796.194978","name":"","label":"","group":"fca18ac4.088f68","order":6,"width":"2","height":"1","passthru":true,"topic":"r1","format":"{{value}}","min":"0","max":"255","step":"5","x":400,"y":220,"wires":[["55d05e31.bcfa7","6cbfa85e.a749a8"]]},{"id":"aecd66cc.eb29c8","type":"inject","z":"d5546796.194978","name":"","topic":"","payload":"255","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":220,"wires":[["958278b7.d96368"]]},{"id":"afbd0522.4334c8","type":"inject","z":"d5546796.194978","name":"","topic":"","payload":"20","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":320,"wires":[["4f36d145.d98a4"]]},{"id":"fca18ac4.088f68","type":"ui_group","z":"","name":"H801","tab":"92b25a8d.c33e18","order":1,"disp":true,"width":"6"},{"id":"92b25a8d.c33e18","type":"ui_tab","z":"","name":"Test","icon":"dashboard","order":4}]

Well the first mistake you have made (actually the last I suppose) is that you haven't put a line before the pasted flow containing just three backtick characters, nor have you put another such line after the flow. Without those we cannot import your flow.

1 Like

In the second change node (outgoing) on the 'to' get rid of the period before payload

so wat i want to do make a calculation.

val1 = msg.payload.r1
val2 = msg.payload.procent2

msg.payload = val2 / 100 * val1;
msg.payload = "r";
return msg;

val1 and val2 are both connected to the input of the function node

You have not said what is not working and what is, and you still haven't allowed us to import your flow.

can you impot it like this? if you can the problem that i have is that the calculation in the function node r waarde is not working.

[

{

"id": "6cbfa85e.a749a8",

"type": "debug",

"z": "d5546796.194978",

"name": "",

"active": true,

"tosidebar": true,

"console": false,

"tostatus": false,

"complete": "true",

"x": 570,

"y": 140,

"wires": []

},

{

"id": "a3818b6a.0226e8",

"type": "function",

"z": "d5546796.194978",

"name": "gekozen dim percentage",

"func": "msg.payload = 100 - (msg.payload);\nmsg.topic = \"procent2\";\nreturn msg;",

"outputs": 1,

"noerr": 0,

"x": 590,

"y": 320,

"wires": [

[

"e32ad161.289ea",

"55d05e31.bcfa7"

]

]

},

{

"id": "e32ad161.289ea",

"type": "debug",

"z": "d5546796.194978",

"name": "",

"active": true,

"tosidebar": true,

"console": false,

"tostatus": false,

"complete": "true",

"x": 890,

"y": 320,

"wires": []

},

{

"id": "55d05e31.bcfa7",

"type": "function",

"z": "d5546796.194978",

"name": "r waarde",

"func": "val1 = msg.r1\nval2 = msg.procent2\n\nmsg.payload = val2 / 100 * val1;\nmsg.topic = \"r\";\nreturn msg;",

"outputs": 1,

"noerr": 0,

"x": 640,

"y": 220,

"wires": [

[

"701e536.6d647ac"

]

]

},

{

"id": "701e536.6d647ac",

"type": "debug",

"z": "d5546796.194978",

"name": "",

"active": true,

"tosidebar": true,

"console": false,

"tostatus": false,

"complete": "true",

  "x": 890,

"y": 140,

"wires": []

},

{

"id": "4f36d145.d98a4",

"type": "ui_slider",

"z": "d5546796.194978",

"name": "",

"label": "Dimmer",

"group": "fca18ac4.088f68",

"order": 4,

"width": "6",

"height": "1",

"passthru": true,

"topic": "procent",

"min": "0",

"max": "100",

"step": "2",

"x": 380,

"y": 320,

"wires": [

[

"928022ac.2d3ec",

"a3818b6a.0226e8"

]

]

},

{

"id": "928022ac.2d3ec",

"type": "debug",

"z": "d5546796.194978",

"name": "",

"active": true,

"tosidebar": true,

"console": false,

"tostatus": false,

"complete": "true",

"x": 390,

"y": 260,

"wires": []

},

{

"id": "958278b7.d96368",

"type": "ui_numeric",

"z": "d5546796.194978",

"name": "",

"label": "",

"group": "fca18ac4.088f68",

"order": 6,

"width": "2",

"height": "1",

"passthru": true,

"topic": "r1",

"format": "{{value}}",

"min": "0",

"max": "255",

"step": "5",

"x": 400,

"y": 220,

"wires": [

[

"55d05e31.bcfa7",

"6cbfa85e.a749a8"

]

]

},

{

"id": "aecd66cc.eb29c8",

"type": "inject",

"z": "d5546796.194978",

"name": "",

"topic": "",

"payload": "255",

"payloadType": "num",

"repeat": "",

"crontab": "",

"once": false,

"onceDelay": 0.1,

"x": 190,

"y": 220,

"wires": [

[

"958278b7.d96368"

]

]

},

{

"id": "afbd0522.4334c8",

"type": "inject",

"z": "d5546796.194978",

"name": "",

"topic": "",

"payload": "20",

"payloadType": "num",

"repeat": "",

"crontab": "",

"once": false,

"onceDelay": 0.1,

"x": 170,

"y": 320,

"wires": [

[

"4f36d145.d98a4"

]

]

},

{

"id": "fca18ac4.088f68",

"type": "ui_group",

"z": "",

"name": "H801",

"tab": "92b25a8d.c33e18",

"order": 1,

"disp": true,

"width": "6"

},

{

 "id": "92b25a8d.c33e18",

"type": "ui_tab",

"z": "",

"name": "Test",

"icon": "dashboard",

"order": 4

}

]

I managed to get enough to see what is going on. I presume, though you have not said, that you don't know where the backtick character is on your keyboard otherwise you would just have done as I asked. On a UK English keyboard it is in the top left corner. If you google for
backtick US Keyboard
or whatever your keyboard is then I expect it will show you.
The problem is that you are using msg.r1 and msg.procent and am sending in two messages, neither of which have msg.r1 or msg.procent. One has r1 in msg.topic and the other has procent as the topic. First you need to combine the two messages together so you can get at both values. You can do this using a Join node in key/value pair mode. Then the values will be in msg.payload.r1 and msg.payload.procent (which is what you said in the post above, but not what is in the flow).

@nick - Do you realize the first flow you posted is not the same as the second?

yes, i added 2 inject nodes

You need to edit the post with the second flow and put the three back tic's ``` before and after it. As it is, it can not be imported.

You should also do that for the first flow you posted.

Almost... the backticks must be on a line of their own. Regardless, the flow itself is already badly formatted from wherever you copied it from. Go back and edit your previous posts to add the backticks. Do not add another post.

[{"id":"6cbfa85e.a749a8","type":"debug","z":"d5546796.194978","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":570,"y":140,"wires":[]},{"id":"a3818b6a.0226e8","type":"function","z":"d5546796.194978","name":"gekozen dim percentage","func":"msg.payload = 100 - (msg.payload);\nmsg.topic = \"procent2\";\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":320,"wires":[["e32ad161.289ea","55d05e31.bcfa7"]]},{"id":"e32ad161.289ea","type":"debug","z":"d5546796.194978","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":890,"y":320,"wires":[]},{"id":"55d05e31.bcfa7","type":"function","z":"d5546796.194978","name":"r waarde","func":"val1 = msg.r1\nval2 = msg.procent2\n\nmsg.payload = val2 / 100 * val1;\nmsg.topic = \"r\";\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":220,"wires":[["701e536.6d647ac"]]},{"id":"701e536.6d647ac","type":"debug","z":"d5546796.194978","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":890,"y":140,"wires":[]},{"id":"4f36d145.d98a4","type":"ui_slider","z":"d5546796.194978","name":"","label":"Dimmer","group":"fca18ac4.088f68","order":4,"width":"6","height":"1","passthru":true,"topic":"procent","min":"0","max":"100","step":"2","x":380,"y":320,"wires":[["928022ac.2d3ec","a3818b6a.0226e8"]]},{"id":"928022ac.2d3ec","type":"debug","z":"d5546796.194978","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":390,"y":260,"wires":[]},{"id":"958278b7.d96368","type":"ui_numeric","z":"d5546796.194978","name":"","label":"","group":"fca18ac4.088f68","order":6,"width":"2","height":"1","passthru":true,"topic":"r1","format":"{{value}}","min":"0","max":"255","step":"5","x":400,"y":220,"wires":[["55d05e31.bcfa7","6cbfa85e.a749a8"]]},{"id":"aecd66cc.eb29c8","type":"inject","z":"d5546796.194978","name":"","topic":"","payload":"255","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":220,"wires":[["958278b7.d96368"]]},{"id":"afbd0522.4334c8","type":"inject","z":"d5546796.194978","name":"","topic":"","payload":"20","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":320,"wires":[["4f36d145.d98a4"]]},{"id":"fca18ac4.088f68","type":"ui_group","z":"","name":"H801","tab":"92b25a8d.c33e18","order":1,"disp":true,"width":"6"},{"id":"92b25a8d.c33e18","type":"ui_tab","z":"","name":"Test","icon":"dashboard","order":4}]

What did you not understand about "Go back and edit your previous posts to add the backticks. Do not add another post."?

Whatever, I have already pointed out the basic problem with your flow but you do not appear to have taken any notice. As I said, you need to merge the messages with a Join node. Go back and read my post and ask if you don't understand.

hi Colin,

i tried and i tried but i can not make it to work.
can you please show me?

Post your updated flow that contains the node that @colin suggested.

[{"id":"6cbfa85e.a749a8","type":"debug","z":"d5546796.194978","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":570,"y":140,"wires":[]},{"id":"a3818b6a.0226e8","type":"function","z":"d5546796.194978","name":"gekozen dim percentage","func":"msg.payload = 100 - (msg.payload);\nmsg.topic = \"procent2\";\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":320,"wires":[["e3475f55.c03fa"]]},{"id":"e32ad161.289ea","type":"debug","z":"d5546796.194978","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":890,"y":320,"wires":[]},{"id":"55d05e31.bcfa7","type":"function","z":"d5546796.194978","name":"r waarde","func":"val1 = msg.r1\nval2 = msg.procent2\n\nmsg.payload = val2 / 100 * val1;\nmsg.topic = \"r\";\nreturn msg;","outputs":1,"noerr":0,"x":860,"y":220,"wires":[["701e536.6d647ac"]]},{"id":"701e536.6d647ac","type":"debug","z":"d5546796.194978","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":890,"y":140,"wires":[]},{"id":"4f36d145.d98a4","type":"ui_slider","z":"d5546796.194978","name":"","label":"Dimmer","group":"fca18ac4.088f68","order":4,"width":"6","height":"1","passthru":true,"topic":"procent","min":"0","max":"100","step":"2","x":380,"y":320,"wires":[["928022ac.2d3ec","a3818b6a.0226e8"]]},{"id":"928022ac.2d3ec","type":"debug","z":"d5546796.194978","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":390,"y":260,"wires":[]},{"id":"958278b7.d96368","type":"ui_numeric","z":"d5546796.194978","name":"","label":"","group":"fca18ac4.088f68","order":6,"width":"2","height":"1","passthru":true,"topic":"r1","format":"{{value}}","min":"0","max":"255","step":"5","x":400,"y":220,"wires":[["6cbfa85e.a749a8","e3475f55.c03fa"]]},{"id":"aecd66cc.eb29c8","type":"inject","z":"d5546796.194978","name":"","topic":"","payload":"255","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":220,"wires":[["958278b7.d96368"]]},{"id":"afbd0522.4334c8","type":"inject","z":"d5546796.194978","name":"","topic":"","payload":"20","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":320,"wires":[["4f36d145.d98a4"]]},{"id":"e3475f55.c03fa","type":"join","z":"d5546796.194978","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":700,"y":220,"wires":[["55d05e31.bcfa7","e32ad161.289ea"]]},{"id":"fca18ac4.088f68","type":"ui_group","z":"","name":"H801","tab":"92b25a8d.c33e18","order":1,"disp":true,"width":"6"},{"id":"92b25a8d.c33e18","type":"ui_tab","z":"","name":"Test","icon":"dashboard","order":4}]

In a previous post I said

That is not the mode that you have selected in the Join node.

well the main problem is that i can not see what i select

What version of node-red are you using?

version: v0.19.3