CT value from Domoticz to MQTT

Good morning,

I am trying to get the color, brightness and state from a Domoticz virtual device.
Whe brightness and state are working, but can't get the color temp working.
In the debug node, I see:

domoticz/out : msg.payload : Object
object
Battery: 255
Color: object
b: 0
cw: 0
g: 0
m: 2
r: 0
t: 255
ww: 255
Level: 37
RSSI: 12
description: ""
dtype: "Color Switch"
hwid: "4"
id: "00084654"
idx: 2654
name: "Zolder Kantoor Gerrie Spots"
nvalue: 15
stype: "RGBWW"
svalue1: "37"
switchType: "Dimmer"
unit: 1

When I click the Color object and check the path to the ww variable, I see: payload.Color.ww
When using msg.payload.Color.ww in a function as variable, I get an error:

The function I use is:
var colortemp = msg.payload.Color.ww;

What am I doing wrong?

function : (error)
"TypeError: Cannot read property 'ww' of undefined"

My total function:

var idx = msg.payload.idx;
var nvalue = msg.payload.nvalue;
var level = msg.payload.Level * 2.55;
var levelr = level.toFixed();
var colortemp = msg.payload.Color.ww;
msg.payload = {}

if (idx == '2654' && typeof idx !== 'undefined' && idx !== null){
if(nvalue == '0') {
    msg.payload.state = 'OFF'
}
if(nvalue >= '1') {
    msg.payload.state = 'ON';
    msg.payload.brightness = levelr;
    msg.payload.color_temp = colortemp;
}

return msg;
}

Your error is saying the property ww can not be found as Color is not defined.

What does a debug before the function node show?

It's like the one in the top of my previous post:

domoticz/out : msg.payload : Object
object
Battery: 255
Color: object
b: 0
cw: 50
g: 0
m: 2
r: 0
t: 205
ww: 205
Level: 38
RSSI: 12
description: ""
dtype: "Color Switch"
hwid: "4"
id: "00084654"
idx: 2654
name: "Zolder Kantoor Gerrie Spots"
nvalue: 10
stype: "RGBWW"
svalue1: "38"
switchType: "Dimmer"
unit: 1

Yes i saw that but it does not show the structue, and error contradicts it. so can we see the debug values copied directly or and image with objects expanded.

Thanks for your quick reply!
Hope you can see it this way:

If that is the object being fed into the function node, then the error is wrong.

Add
node.send({payload:msg.payload});
to the top line of the function and post the output of a debug.

After adding the line in the top of the function, it's working!
Thanks a lot.

Here is the debug output:

domoticz/out : msg.payload : Object
object
state: "ON"
brightness: "171"
color_temp: 234

That code did not fix it, It was to help debug.

I would think your payload did not have the properties in it (that why you got the error). Something else you did fixed the issue. You can remove that line as it was just to confirm that the payload did exist in the function , and if it existed what properties it had.

OK, thanks a lot!
I know what fixed it.

I added a switch node before the function, because after adding the extra line I got a lot of logs from other idx from Domoticz. This is the switch node I added, to only filter out the idx I needed.

image