Set Call Service Node Data to Payload Value

I've looked everywhere, but amazingly can't find an answer to this, seemingly simple problem.
I'm fairly new to Node Red, so please go gently on me.

I'm trying to use a call service node to set the brightness and ultimately cool white and warm white
states for a lamp.

Entering a specific value in the data will set the brightness to that figure. e.g. {"brightness":"190"}
Bur how do I replace "190" in this example with msg.payload and get it to work please?

I'll then need to try and adapt that solution to set the "c" and "w" states (independently) also.

Available lamp states>

{
"color_mode": "cwww",
"state": "ON",
"brightness": 190,
"color": {
"c": 255,
"w": 245
}
}

Any help much appreciated.

Welcome @Teleportist.

Firstly, what is a call service node - is it something to do with Home Assistant?

In your simple example {"brightness":"190"}, "190" is a string, but in the more complicated one

"state": "ON",
"brightness": 190,
"brightness": 51,`

it's a number .

So asuming msg.payload is a number, something like this should work
MessageForHA.brightness = msg.payload;
If it's a string, you will have to convert it to a number.

Thanks for your reply jbudd.

Sorry, there was an error in second string of my OP. Now corrected to remove the duplicated brightness value.

Yes, I'm using Node Red within Home Assistant.
image

I've tried pasting MessageForHA.brightness = msg.payload; into the nodes data field, but no joy. Should I be replacing 'MessageForHA' with something else?

Finally managed to solve this by using a separate function node for the data, rather than the data field of the call service node, which seems limited.

var newMsg = {
payload: {"data":{"color_temp":msg.payload}}
};
return newMsg;

Many thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.