Call service node Data inject msg.payload

I’m using a call service node to call alexa_tts. I want her to say the string from the msg.payload from the previous node.
A working Data field looks like this:

{"message":"This is a test"}

How do i replace “This is a test” with the string in the payload from the calling Node?

If you using the latest node-red-contrib-home-assistant-websocket

{"message":"{{payload}}"}

Otherwise you’re going to have to use a template or function node.

Thanks Kermit. Worked perfectly!!

Can I piggy back off of this? I need to do the same thing, but I need to send an integer not a string.

If I try {"value":"{{payload}}"} HA complains that extra keys not allowed @ data['0']

If I try {"value":{{payload}}} the node in Node-RED won’t accept it…

This has to with you sending more data than the service call was expecting. Make sure you’re not passing any extra data in msg.payload.data for the previous nodes.

I finally managed to work it out. I had to use a template in the end to send the data through to the call service node.

I was actually trying to send the contents of a flow variable, so in my case it was {"data" : { "value" : {{flow.MinCool}} } }

I’m having the same troubles, thanks to this thread I can use a string but having problems with a value.

Say for example I want to call a brightness percentage of 80% my json would be

{"brightness_pct":80}

I have tried all of these with no luck

{"brightness_pct":{{payload}}}
{"brightness_pct":"{{payload}}"}
{"brightness_pct":{ "value" : {{msg.payload}} }
{"brightness_pct": {"data" : { "value" : {{msg.payload}} } }}
{"brightness_pct": "{"data" : { "value" : {{msg.payload}} } }"}

Is there anyone who can point me in the right direction, I simply want to insert a value into the json data field of the “Call Service Node”?

I have tried both string and number and the debug confirms both of these is a value/number.

I’m also happy to use a function of some type but the following doesn’t work due to these " being required for json and mean string in java.

msg.payload="{"brightness_pct":"+msg.payload+"}";
return msg;

and then just have {{payload}} in the data field.

I also tried:

msg.payload='{"brightness_pct":'+msg.payload+'}';
return msg;

and this passes through the correct looking string but back to the following error:

10/2/2019, 4:41:39 PMnode: RGB1 brightnessmsg : string[73]

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

I think I’m having the same type of trouble in this threat

If I find a solution I’ll try posting it here too.

To to this you need to send a data package in the function node:
Then either add the other values to your service call node, or just leave it empty.

newmsg = {}

newmsg.payload = { data: { “brightess_pct”:msg.payload} }

return newmsg;

Is the correct way to have

Msg.Payload
Msg.data.value1
msg.data.value2

or as I think you are writing

msg.payload.data.value1
msg.payload.data.value2

?

You can easily check as well as copy the path to your message using the debug node. Usually it would be msg.data.value1

Hi Wayne

Take a look in the thread I linked earlier, I think I have a solution you might need.

I FOUND IT!!! I’m sure there is an easier way but I can make it work!!

I watched this vid and used the first two functions and got it to work. https://www.youtube.com/watch?v=24ZY3CEsiow&t=970s

Just to explain my test situation…
I have an input slider called “brightness” that goes from 0-100.
I have an event state reading this slider which outputs a string consisting of a number between 0 & 100.
This goes into a function node with the following code. This converts to JSON.

var data={"brightness_pct":+msg.payload};
node.log(typeof data);
msg.payload= JSON.stringify(data);
return msg;

This goes to another function node with the following code. This gets the number back (in a different format???). This is where I think it could be more direct but yet to find a way.

p=JSON.parse(msg.payload);
node.log(typeof p);
msg.payload=p.brightness_pct;
return msg;

Now this gets passed to a call service node and the data field looks like this.

{"brightness_pct":{{payload}}}

And now my slider controls the brightness. The reason behind all this is I have 3 RGB strips in one project and would like the one slider to control all three at the same time, also by doing this I can “sync” patterns across all three.

I hope this helps people out.

You are all going to laugh…

I changed the event state reading the slider to output the value (state type) as a number instead of a string…

wired this directly to the call service nodes with the following in the data field

{"brightness_pct":{{payload}}}

AND IT WORKS PERFECTLY!!!

I learned to sync different lights, put them together in a light group, works wonderfull!

But can you link the flow/configs for your slider and nodes? I’d like to see it :slight_smile:

Well I also wanted to have better control over custom patterns that actually sync together and this is the beginning of that.

image

image
Excuse the name, it is just a test at this stage

Truth be told, I use the light group to see if it’s on or off and turn them on individual.

I’ll link what I do later.
At the moment I’m struggling with the correct light color temperature!
Do made a long array with Kelvin colors in that I’m using atm.