Set value input number not working

Hello,
i added to my dashboard a input_number slider. Now, i want to set the value from my modbus data. The data is there. The output of my modbus object is

polling : msg.payload : Object
object
data: array[2]
0: 2
1: 0
buffer: buffer[4][raw]
0: 0x0
1: 0x2
2: 0x0
3: 0x0

so i added to my flow an call service object and set it to input_number with server “set_value”
at data i tested some things. like

{"value":"{{payload}}"}

and also for simple testing

{"value":"1"}

but it doesnt matter what data i configure, i got everytime the same error message

“Call-service error. extra keys not allowed @ data[‘0’]”

What goes wrong here?

by putting quotes it passes the variable as a string.

{"value": {{payload}} }

and also for simple testing

{"value": 1 }

The value is also not at payload, you’ll need the path to the specific number you are trying to pass. use the copy path option next to the value in the debug widow .

Thanks for reply, but this also doesnt work. I copied the full path:

payload.data[0]

so that i configured the data field of the node to

{"value":{{payload.data[0]}}

But i also get the error message:

Call-service error. extra keys not allowed @ data[‘0’]

I added a function, to create a custom object.

var myFan = new Object();
myFan.value = 1.0;

return myFan;

and in my data field i enter

{"value":"{{myFan.value}}"}

but become the following error message:

Call-service error. expected float for dictionary value @ data[‘value’]

so i changed the data json from

{"value":"{{myFan.value}}"}

to

{"value":{{myFan.value}}}

after the change, i got the error message:

Call-service error. extra keys not allowed @ data['0']

Sorry, but i cant understand, what goes wrong here…

I believe the issue is that you have values in msg.payload that is used as input in the call service when it shouldn’t.

Can the node that sets the payload be configured to place the payload in say msg.load instead?
Then just change your call service to take the data from msg.load… instead.

I believe the issue is that you have values in msg.payload that is used as input in the call service when it shouldn’t.

thats possible and also my opinion. But i cannot change it. Because of this, i created a function node to delete the msg object and create a new object with the desired value.
But then, see above, its not working.

Then use a change node.

Try with J;expression and use

{ "value":  payload[0] }

if not force it to a number

{ "value":  $number(payload[0]) }

it may also be payload.[0]
I’d like to give you some hard and fast rule but sometimes you need to remove data from the path, sometimes you don’t.

If you still have problems post the exact message in json(copy value of payload in debug)

Thanks, with J

{"value":payload[0]}

is working. Please, can you explain why this is working, now?

Likely a formatting problem, J;expression or jsonata is the preferred language for nodered

I know this is late, but I’ve only just saw this and it wasn’t answered, so here’s some reasons:
Looking at your original post, you had 2 objects being stored in the msg.
msg.payload = an array of 2 numbers (numbered 0-1)
msg.payload.buffer = an array of 4 values (numbered 0-3)

Most computer languages count starting at 0… so thats why 4 items will be numbered 0-3 (position 0, 1, 2, 3)

Arrays in Javascript are passed within square brackets, for example; payload[0] is the first item in the array called payload. payload[1] would get the 2nd item (the 0).

Wrapping the payload[0] in quotes means you were trying to pass the number as a string (text) instead of a number. As it was expecting a number and you tried passing it as a string… it spat out an error.