Page 1 of 3

Node red flow

Posted: Sunday 12 October 2025 8:31
by edwin1234
IMG_6577.jpeg
IMG_6577.jpeg (91.72 KiB) Viewed 353 times
Cant get this flow working
I have a tuya socket device and want to get the usage in domoticz
Cant find the solution maybe someone can help me?
This is the flow:

Code: Select all

 [
{
"id": "34725c4ec27d40dd",
"type": "tab",
"label": "Tuya Koelkast",
"disabled": false,
"info": ""
},
{
"id": "24368e69f7b1414c",
"type": "tuya-local",
"z": "34725c4ec27d40dd",
"devName": "KoelKast",
"devIp": "192.168.2.160",
"devId": "48123468a4e57c1cfe2d",
"devKey": "n:]Kl1gqKfZ9||UA",
"protocolVer": "3.3",
"renameSchema": "",
"filterCB": "",
"x": 120,
"y": 100,
"wires": [
[
"82cc542778cd4923",
"d43deefd21f0a4b2"
]
]
},
{
"id": "466604012dd1ea0f",
"type": "debug",
"z": "34725c4ec27d40dd",
"name": "1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 630,
"y": 80,
"wires": []
},
{
"id": "45297eee97166e0c",
"type": "inject",
"z": "34725c4ec27d40dd",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payloadType": "date",
"x": 80,
"y": 200,
"wires": [
[
"24368e69f7b1414c",
"82cc542778cd4923"
]
]
},
{
"id": "82cc542778cd4923",
"type": "switch",
"z": "34725c4ec27d40dd",
"name": "Dps",
"property": "payload.data.dps",
"propertyType": "msg",
"rules": [
{
"t": "hask",
"v": "1",
"vt": "str"
},
{
"t": "hask",
"v": "18",
"vt": "str"
},
{
"t": "hask",
"v": "19",
"vt": "str"
},
{
"t": "hask",
"v": "20",
"vt": "str"
},
{
"t": "hask",
"v": "21",
"vt": "str"
},
{
"t": "hask",
"v": "22",
"vt": "str"
},
{
"t": "hask",
"v": "23",
"vt": "str"
},
{
"t": "hask",
"v": "24",
"vt": "str"
},
{
"t": "hask",
"v": "25",
"vt": "str"
},
{
"t": "hask",
"v": "26",
"vt": "str"
},
{
"t": "hask",
"v": "27",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 11,
"x": 330,
"y": 120,
"wires": [
[
"466604012dd1ea0f"
],
[
"cdb888cd43869940"
],
[
"db0b1cbd58cc4b7a"
],
[
"539c6c5b1aba69f5",
"9c978c70306ceabe"
],
[
"4864ef0c2423fc50"
],
[
"386b879582c1203b"
],
[
"653f084179d38675"
],
[
"7aaba566f7f31dfc"
],
[
"d2873b8c185ef97a"
],
[
"639736d6b5157a4f"
],
[
"5e3f5352ea154487"
]
]
},
{
"id": "cdb888cd43869940",
"type": "debug",
"z": "34725c4ec27d40dd",
"name": "18 ",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 630,
"y": 120,
"wires": []
},
{
"id": "db0b1cbd58cc4b7a",
"type": "debug",
"z": "34725c4ec27d40dd",
"name": "19 ",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 630,
"y": 160,
"wires": []
},
{
"id": "d43deefd21f0a4b2",
"type": "debug",
"z": "34725c4ec27d40dd",
"name": "Alle dps",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 340,
"y": 320,
"wires": []
},
{
"id": "539c6c5b1aba69f5",
"type": "debug",
"z": "34725c4ec27d40dd",
"name": "20 ",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 630,
"y": 200,
"wires": []
},
{
"id": "653f084179d38675",
"type": "debug",
"z": "34725c4ec27d40dd",
"name": "23",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 630,
"y": 320,
"wires": []
},
{
"id": "4864ef0c2423fc50",
"type": "debug",
"z": "34725c4ec27d40dd",
"name": "21",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 630,
"y": 240,
"wires": []
},
{
"id": "386b879582c1203b",
"type": "debug",
"z": "34725c4ec27d40dd",
"name": "22",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 630,
"y": 280,
"wires": []
},
{
"id": "7aaba566f7f31dfc",
"type": "debug",
"z": "34725c4ec27d40dd",
"name": "24",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 630,
"y": 360,
"wires": []
},
{
"id": "d2873b8c185ef97a",
"type": "debug",
"z": "34725c4ec27d40dd",
"name": "25",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 630,
"y": 400,
"wires": []
},
{
"id": "3a3a274ee7fb793b",
"type": "comment",
"z": "34725c4ec27d40dd",
"name": "hier vangen we het dps nummer op en sturen we het naar het juiste idx in domoticz ",
"info": "hier vangen we het dps nummer op en sturen we het naar het juiste device nummer in domoticz",
"x": 630,
"y": 440,
"wires": []
},
{
"id": "d2ac8d01f90af68f",
"type": "mqtt out",
"z": "34725c4ec27d40dd",
"name": "To Domoticz",
"topic": "domoticz/in",
"qos": "0",
"retain": "false",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "f9f13036.e28b58",
"x": 990,
"y": 360,
"wires": []
},
{
"id": "fd7e93bfa3d6054c",
"type": "debug",
"z": "34725c4ec27d40dd",
"name": "Uitkomst",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1020,
"y": 100,
"wires": []
},
{
"id": "9c978c70306ceabe",
"type": "function",
"z": "34725c4ec27d40dd",
"name": "Function 4",
"func": "msg.payload = { \"command\": \"udevice\", \"idx\": 2710, \"nvalue\": parseInt (msg.payload.data.dps[\"20\"]/10)}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 810,
"y": 40,
"wires": [
[
"d2ac8d01f90af68f",
"fd7e93bfa3d6054c"
]
]
},
{
"id": "639736d6b5157a4f",
"type": "debug",
"z": "34725c4ec27d40dd",
"name": "26",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 630,
"y": 480,
"wires": []
},
{
"id": "5e3f5352ea154487",
"type": "debug",
"z": "34725c4ec27d40dd",
"name": "27",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 630,
"y": 520,
"wires": []
},
{
"id": "2bad7d3ed48f0d62",
"type": "function",
"z": "34725c4ec27d40dd",
"name": "",
"func": "\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 550,
"y": 640,
"wires": [
[]
]
},
{
"id": "f9f13036.e28b58",
"type": "mqtt-broker",
"name": "127.0.0.1",
"broker": "127.0.0.1",
"port": "1883",
"clientid": "",
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthRetain": "false",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closeRetain": "false",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willRetain": "false",
"willPayload": "",
"willMsg": {},
"sessionExpiry": ""
}
]

Re: Node red flow

Posted: Sunday 12 October 2025 9:55
by habahabahaba
What exactly do you want?
To send some data in Domoticz?

Do you have mqtt broker installed?

More information please

Re: Node red flow

Posted: Sunday 12 October 2025 13:04
by edwin1234
I want the kwh from that socket and maybe later some more values
Yes i have a mqtt broker
And want to do it with node red

Re: Node red flow

Posted: Sunday 12 October 2025 15:02
by FireWizard
Hello @edwin1234,

I have loaded your flow from your first post in my test system.

I do not have any Tuya devices, so I can´t get the Tuya-local node connected to a device.

First question:

Why do you use
node-red-contrib-tuya-local
This node has been last updated 5 years and 5 month ago?
See: https://flows.nodered.org/node/node-red ... 3cYxQ0budG

I think: https://flows.nodered.org/node/node-red ... ya-devices, is newer and so more up to date.

If I look to your picture of the debug pane, I see that the data has been presented in e.g the key

Code: Select all

msg.payload.dps.1
However in your "Switch" node, I see that you split your objects, based on the key:

Code: Select all

msg.payload.data.dps
That does not match, with your picture. Where does "data" come from?

You use this in the Function node as well.

Have a look

Regards

Re: Node red flow

Posted: Sunday 12 October 2025 15:42
by edwin1234
Hi firewizard,
The data is a debug node connected to the tuya socket. Where alle .dps is written. See photo
Image

Re: Node red flow

Posted: Sunday 12 October 2025 16:01
by FireWizard
Hello @edwin1234,
The data is a debug node connected to the tuya socket. Where alle .dps is written. See photo
I know, but I mean that you have an object, called data

Open the "Switch" node:

Screenshot_switch_node_edwin.png
Screenshot_switch_node_edwin.png (40.82 KiB) Viewed 319 times
Your selection property is: msg.payload.data.dps.
"data" is not shown in the debug pane.

Heve a check

Regards

Re: Node red flow

Posted: Sunday 12 October 2025 16:02
by habahabahaba
viewtopic.php?p=323545#p323545

There you can find two different solutions - to use http or mqtt :)

Re: Node red flow

Posted: Sunday 12 October 2025 16:06
by FireWizard
@habahabahaba,

In the picture, you can see that Edwin has chosen for MQTT and not HTTP.

Regards

Re: Node red flow

Posted: Sunday 12 October 2025 16:16
by habahabahaba
FireWizard wrote: Sunday 12 October 2025 16:06 @habahabahaba,

In the picture, you can see that Edwin has chosen for MQTT and not HTTP.

Regards
@FireWizard , hi.

No i dont see that he chosen mqtt... Where did you see that?

Anyway, its better to have a choice.

Re: Node red flow

Posted: Sunday 12 October 2025 16:24
by edwin1234
FireWizard wrote: Sunday 12 October 2025 16:01 Hello @edwin1234,
The data is a debug node connected to the tuya socket. Where alle .dps is written. See photo
I know, but I mean that you have an object, called data

Open the "Switch" node:


Screenshot_switch_node_edwin.png

Your selection property is: msg.payload.data.dps.
"data" is not shown in the debug pane.

Heve a check

Regards
Hi firewizard i copied the switch node from another tuya device (not a socket)and that flow is working and there is no data.dps as far as i can see.
But im still a noob at this so i dont understand why “ koelkast “ is not working.

And where do you see : msg.payload.dps.1

You sad: I look to your picture of the debug pane, I see that the data has been presented in e.g the key
CODE: SELECT ALL
msg.payload.dps.1

Re: Node red flow

Posted: Monday 13 October 2025 18:58
by edwin1234
What should the property line be to make it working?

Re: Node red flow

Posted: Monday 13 October 2025 19:07
by FireWizard
Hi,

@habahabahaba,

You asked:
No i don't see that he chosen mqtt... Where did you see that?
If you go to the picture of the flow, you will see, at the far right side, a purple node, called "To Domoticz"
If you are a little familiar with Node-RED, you recognize the type of the node.
The MQTT nodes, looks like:

Screenshot_MQTT_In_Out_node.png
Screenshot_MQTT_In_Out_node.png (2.47 KiB) Viewed 276 times

Honestly said, @edwin1234 copied this from another flow. With that other flow, I supported him.
So I recognized this flow.

Alright

@edwin1234

You asked:
And where do you see : msg.payload.dps.1
This is a combination of observations in your debug node.
Screenshot_debug_Tuya.png
Screenshot_debug_Tuya.png (94.53 KiB) Viewed 276 times
Node-RED sends always an object to the next node and mostly this object is in msg.payload
This is also here. msg.payload is an object.
If you press the "triangle", it will show you the contents of the object. In this case it is devId and dps.
The devId you can safely ignore. The other part is dps, which is also an object.
Press the "triangle" and it will show the contents.
In this case a number of keys (1, 9,18,19,20, etc)

The Tuya protocol works with dps, which stands for DataPointS.
To find the Tuya data-points, look at: https://developer.tuya.com/en/docs/iot/ ... g4x1dt7a6j
or for Local Tuya: https://github.com/dulfer/localtuya-device-datapoints

So at the end the key is : msg.payload.dps.1 or msg.payload.dps.9, etc

You can find that path very easily, by hovering with your mouse over the buttons after each line.
See: https://nodered.org/docs/user-guide/messages

So to solve your issue:

In the Switch node: Change the property msg.payload.data.dps into msg.payload.dps
Do the same in "Function 4"node. Change msg.payload = { "command": "udevice", "idx": 2710, "nvalue": parseInt (msg.payload.data.dps["20"]/10)} into
msg.payload = { "command": "udevice", "idx": 2710, "nvalue": parseInt (msg.payload.dps["20"]/10)}

But I do not expect this to work. Which data (dps) do you want from your "Koelkast" to send to Domoticz?
Which type of sensor are you going to use?

Let us know and we can help you.

Regards

Re: Node red flow

Posted: Monday 13 October 2025 19:18
by habahabahaba
@FireWizard , yes, you are right.
I missed it

Re: Node red flow

Posted: Monday 13 October 2025 19:21
by edwin1234
Thank you firewizard,
I want the power to send to domoticz and i think its dps 20 and send it to a general kwh device.

Re: Node red flow

Posted: Monday 13 October 2025 19:37
by FireWizard
Hi @edwin1234,

You said:
I want the power to send to domoticz and i think its dps 20 and send it to a general kwh device.
Is that the only data, you want from the "Koelkast"
You think, it is 20, are you sure? Could it be 19?

In the links, I included in my previous post, 19 = power and 20 = voltage.
Can you check that?

Regards

Re: Node red flow

Posted: Monday 13 October 2025 19:54
by edwin1234
I think youre right it is 19

Re: Node red flow

Posted: Tuesday 14 October 2025 12:33
by FireWizard
Hello @edwin1234,

I have created a simulation for the Tuya node and tested the complete flow with Domoticz.

I assume that for "Power" the DataPoint is 19 and that the value has to be divided by 10.
At least that make sense, so the power usage of your refrigerator is 101.2 W.

Screenshot_Refrigerator_Power.png
Screenshot_Refrigerator_Power.png (43.14 KiB) Viewed 252 times
The most simple flow is as follows:

Screenshot_Tuya_flow.png
Screenshot_Tuya_flow.png (13.94 KiB) Viewed 252 times
Do as follows:

1. Create a virtual device, type Electric (Usage + Counter) in Domoticz
2. Click "Edit" and set "Energy read" to "Computed"
3. Replace the "inject" node, with your Tuya node.
4. Replace the MQTT output node with your own MQTT output node
4. If everything is working fine, remove the debug nodes. I assumed that the index of your device in Domoticz is 2710.

The flow:

Code: Select all

[
    {
        "id": "2bad7d3ed48f0d62",
        "type": "function",
        "z": "34725c4ec27d40dd",
        "name": "",
        "func": "msg.payload = { \"command\": \"udevice\", \"idx\": 2710, \"nvalue\" : 0, \"svalue\": (msg.payload.dps[\"19\"]/10).toString() + \";0\"};\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 640,
        "y": 640,
        "wires": [
            [
                "4259c8d387b3011b",
                "ec99d917d0de1c21"
            ]
        ]
    },
    {
        "id": "40a56f7737cf61c6",
        "type": "inject",
        "z": "34725c4ec27d40dd",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "Koelkast",
        "payload": "{\"dps\":{\"1\":true,\"9\":0,\"18\":484,\"19\":1012,\"20\":2307,\"21\":1,\"22\":558,\"23\":28166,\"24\":15267,\"25\":1364}}",
        "payloadType": "json",
        "x": 450,
        "y": 640,
        "wires": [
            [
                "ef81bdf4c52e2c55",
                "2bad7d3ed48f0d62"
            ]
        ]
    },
    {
        "id": "ef81bdf4c52e2c55",
        "type": "debug",
        "z": "34725c4ec27d40dd",
        "name": "debug 9",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 580,
        "wires": []
    },
    {
        "id": "ec99d917d0de1c21",
        "type": "mqtt out",
        "z": "34725c4ec27d40dd",
        "name": "To Domoticz",
        "topic": "domoticz/in",
        "qos": "0",
        "retain": "false",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "175c3dc01f359e9d",
        "x": 830,
        "y": 640,
        "wires": []
    },
    {
        "id": "4259c8d387b3011b",
        "type": "debug",
        "z": "34725c4ec27d40dd",
        "name": "debug 10",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 820,
        "y": 580,
        "wires": []
    },
    {
        "id": "175c3dc01f359e9d",
        "type": "mqtt-broker",
        "name": "Raspberry Pi 1B",
        "broker": "192.168.10.51",
        "port": 1883,
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": 4,
        "keepalive": 60,
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "false",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closeRetain": "false",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]
Let me know the result.

Regards

Re: Node red flow

Posted: Tuesday 14 October 2025 17:40
by edwin1234
Hi firewizard,
I get this : Object
{ command: "udevice", idx: 1463, nvalue: 0, svalue: "NaN;0" }

The idx is 1463 now by the way

Re: Node red flow

Posted: Tuesday 14 October 2025 19:39
by FireWizard
@edwin1234.

And if you try with my original Inject node?

Regards

Re: Node red flow

Posted: Wednesday 15 October 2025 17:56
by edwin1234
Hi firewizard,
Now i got some value perhaps i have to wait till it runs for a day or so to see the kwh

Image