# CT value from Domoticz to MQTT

**URL:** https://discourse.nodered.org/t/ct-value-from-domoticz-to-mqtt/38939
**Category:** General
**Created:** [11 January 2021 09:56 UTC](https://discourse.nodered.org/t/ct-value-from-domoticz-to-mqtt/38939 "2021-01-11T09:56:38Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![dheuts](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dheuts/32/35159_2.png) [@dheuts](https://discourse.nodered.org/u/dheuts)
#### Post date: [11 January 2021 09:56 UTC](https://discourse.nodered.org/t/ct-value-from-domoticz-to-mqtt/38939/1 "2021-01-11T09:56:39Z")

</div>

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:

```auto
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?

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

```

My total function:

```auto
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;
}

```

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [11 January 2021 10:22 UTC](https://discourse.nodered.org/t/ct-value-from-domoticz-to-mqtt/38939/2 "2021-01-11T10:22:32Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![dheuts](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dheuts/32/35159_2.png) [@dheuts](https://discourse.nodered.org/u/dheuts)
#### Post date: [11 January 2021 11:44 UTC](https://discourse.nodered.org/t/ct-value-from-domoticz-to-mqtt/38939/3 "2021-01-11T11:44:09Z")

</div>

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

```auto
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

```

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [11 January 2021 11:47 UTC](https://discourse.nodered.org/t/ct-value-from-domoticz-to-mqtt/38939/4 "2021-01-11T11:47:10Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dheuts](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dheuts/32/35159_2.png) [@dheuts](https://discourse.nodered.org/u/dheuts)
#### Post date: [11 January 2021 11:49 UTC](https://discourse.nodered.org/t/ct-value-from-domoticz-to-mqtt/38939/5 "2021-01-11T11:49:24Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/d/ed8360cdbeffcad70e8fde2f1df127ee085ebcfa.png)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [11 January 2021 11:56 UTC](https://discourse.nodered.org/t/ct-value-from-domoticz-to-mqtt/38939/6 "2021-01-11T11:56:12Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dheuts](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dheuts/32/35159_2.png) [@dheuts](https://discourse.nodered.org/u/dheuts)
#### Post date: [11 January 2021 12:45 UTC](https://discourse.nodered.org/t/ct-value-from-domoticz-to-mqtt/38939/7 "2021-01-11T12:45:11Z")

</div>

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

Here is the debug output:

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

```

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [11 January 2021 12:49 UTC](https://discourse.nodered.org/t/ct-value-from-domoticz-to-mqtt/38939/8 "2021-01-11T12:49:03Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dheuts](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dheuts/32/35159_2.png) [@dheuts](https://discourse.nodered.org/u/dheuts)
#### Post date: [11 January 2021 13:25 UTC](https://discourse.nodered.org/t/ct-value-from-domoticz-to-mqtt/38939/9 "2021-01-11T13:25:45Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/d/6d7514b9ed198e657d5a458072a20b6ec1cbabd5.png)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [12 March 2021 13:25 UTC](https://discourse.nodered.org/t/ct-value-from-domoticz-to-mqtt/38939/10 "2021-03-12T13:25:48Z")

</div>

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