Node-Red Service-Call to Update Input Text Helper

I am using a service call to update an input_text value in HomeAssistant.

The service call works perfectly if I use {"value":"test message"} in the data field.

What I want to do is use the msg.payload however if I use {"value":msg.payload} I get the follow error.
"Call-service API error. Error Message: extra keys not allowed @ data['0']"
encasing the msg.payload in {} does not help and encasing the msg.payload in "" results in the input_text being updated with "msg.payload" and not the content of the payload.

For completeness the payload is a 36 character string coming from a function node.

Screen shot below:

Thanks in advance

I don’t know if this should work but I always did it with msg.payload.data going into the node.

EDIT:
This is the right way:

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

You can use mustache templating:
https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/mustache-templates.html

That doesn’t work. The "{{payload}}" is treated as a string.
See below.

you have to turn off the “Use alternative template tags for the Data field” checkbox

Perfect! Thanks heaps this was drive me nuts. Learned something valuable.

I tried this just now and no luck. Has something changed in Node-Red Home Assistant requirements?
I get the ERROR message:
msg : string[74]
“Call-service API error. Error Message: extra keys not allowed @ data[‘0’]”

And, Yes I unchecked the “Use alternative template tags for the Data field” checkbox!

Post your flow, likely it is your settings.

[{"id":"0e33eaf6b871fc0e","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"e20157c6e15317af","type":"api-call-service","z":"0e33eaf6b871fc0e","name":"Store SimpliSafe Successful Pong Date","server":"af0ca6be.a229c8","version":1,"debugenabled":true,"service_domain":"input_text","service":"set_value","entityId":"input_text.saved_pongdate","data":"{\"value\":\"{{payload}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":948.0000038146973,"y":527.6667079925537,"wires":[[]]},{"id":"7a6bcf3d376ce037","type":"exec","z":"0e33eaf6b871fc0e","command":"date","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":554.3334045410156,"y":438.1666793823242,"wires":[["e20157c6e15317af","3ae1a44c2110cf96"],[],[]]},{"id":"298ce43d44f74571","type":"inject","z":"0e33eaf6b871fc0e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":374.0000305175781,"y":430.99999237060547,"wires":[["7a6bcf3d376ce037"]]},{"id":"3ae1a44c2110cf96","type":"debug","z":"0e33eaf6b871fc0e","name":"XXXX","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":934.6666641235352,"y":478.33338165283203,"wires":[]},{"id":"af0ca6be.a229c8","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

The call service is coming up yellow for me, means it needs to be updated. You should have a nodered update available.

1 Like

Updated to Node-red 2.0.6. Still Broken. Here is the debug output from Store SimpliSafe Successful Pong Date Node:

5/6/2022, 11:23:18 AM[node: Store SimpliSafe Successful Pong Date](http://192.168.5.49:8123/api/hassio_ingress/HN_gUaZ1VIwsW5l_DfSeuHsJ-TppWLGKZ4cZiADZ7I4/#)msg :

object

domain: "input_text"

service: "set_value"

data: object

0: "{"

1: """

2: "v"

3: "a"

4: "l"

5: "u"

6: "e"

7: """

8: ":"

9: """

10: "F"

11: "r"

12: "i"

13: " "

14: "M"

15: "a"

16: "y"

17: " "

18: " "

19: "6"

20: " "

21: "1"

22: "1"

23: ":"

24: "2"

25: "3"

26: ":"

27: "1"

28: "8"

29: " "

30: "M"

31: "D"

32: "T"

33: " "

34: "2"

35: "0"

36: "2"

37: "2"

38: "↔"

39: """

40: "}"

entity_id: "input_text.saved_pongdate"

Your msg.payload is a object not a string. Try using {{payload.value}}

1 Like

I’m getting api errors using call service in node-red too, it’s just passing the content of a tweet to HomeAssistant. A test message works fine, sometimes tweets work fine, mostly they don’t. I think the call service node is bugged. Everything is up to date including the todays update.

Now the value is blank. WTF?

5/6/2022, 12:15:14 PM[node: Store SimpliSafe Successful Pong Date](http://192.168.5.49:8123/api/hassio_ingress/HN_gUaZ1VIwsW5l_DfSeuHsJ-TppWLGKZ4cZiADZ7I4/#)msg :

object

domain: "input_text"

service: "set_value"

data: object

value: ""

entity_id: "input_text.saved_pongdate"

I read the error wrong. Change the data type from JSON to J: expression and try { "value": payload}

pretty sure it has to do with the return character you have in msg.payload

1 Like

It worked, thank you very much

Special characters can cause errors when passing variables. Try wrapping the variable with a triple mustache {{{payload}}} or the jsonata(J;expression) method above.