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

2 Likes

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.

Just ran into this issue still today and I think I figured out why. I would also consider this a bug in the call service node.

When you use a msg variable that is not payload the call service node is merging your variable with whatever is in payload.

So say I have this in payload:

{"title":"something","message":"a message","url":"https://url"}

If you put this in the call service node:

{"value":"{{{message}}}"}

I would expect this to only pass my msg.message contents to the service call. Instead what you end up with is a merge of whatever you already had in payload with what you had in your call. Something like this which results in the extra keys error:

{"title":"something","message":"{{{message}}}","url":"https://url"}

My solution was to just put a change node in front of my service call and delete payload since I no longer needed it. If you did need it later you probably need to copy it elsewhere so you can clear payload.

The way

The way you have it is that payload is an object, so the path would be payload.message

if msg.message is undefinded, message = msg and should return everything.

No, my msg.message is different than what it is in payload.message. payload.message is in my case was used in a different branch further back in the flow. msg.message was constructed for this specific service call. Passing the way I did, msg.message is copied to payload.message over-writing the original payload.message and then the full payload object including title and url is passed to the service call. This all happens within the service call node. Since title and url are invalid keys for the service call, you get an error.

This may be by design but it’s not documented and not intuitive. If I tell the service call to use {{{message}}} this does not mean msg.payload.message, it means msg.message which is not what occurs. It certainly does not mean copy msg.message to msg.payload.message and then include all of payload which IS what is happening.

That is not the behavior I see. Without the flow where this error occurred it hard to say why. I can pass both msg.message and msg.payload.message and have their values sent. Admittedly there are some quirks to using mustache templates, to avoid this use jsonata instead.

[{"id":"e5350cf19f8f24ef","type":"inject","z":"0a325c35fc29f44e","name":"","props":[{"p":"payload"},{"p":"message","v":"this is msg.message","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"title\":\"something\",\"message\":\"this is payload.message\",\"url\":\"https://url\"}","payloadType":"json","x":210,"y":6600,"wires":[["062af45dab8f53d4"]]},{"id":"062af45dab8f53d4","type":"api-call-service","z":"0a325c35fc29f44e","name":"","server":"6b1110b5.183a4","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_pixel_7","areaId":[],"deviceId":[],"entityId":[],"data":"{\"title\":\"{{message}}\",\"message\":\"{{payload.message}}\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"all","x":490,"y":6600,"wires":[[]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"id","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Edit: to add removing msg.message from the flow above does not return the entire msg, that was an assumption on my part.