Hi,
I could use some help and, if possible, a little explanation.
After quite a struggle, I managed to configure a Tuya smart plug and, with node-red-contrib-tuya-smart-device, the following flow works fine manually:
Flow
[
{
"id": "d79d91df60007d08",
"type": "tuya-smart-device",
"z": "2b2676f81a6deb7d",
"deviceName": "Tuya Smart PLug",
"disableAutoStart": false,
"deviceId": "",
"deviceKey": "",
"storeAsCreds": true,
"deviceIp": "192.168.42.189",
"retryTimeout": "1001",
"findTimeout": "2000",
"tuyaVersion": "3.1",
"eventMode": "event-both",
"x": 930,
"y": 800,
"wires": [
[],
[]
]
},
{
"id": "2a21969c0c2b6363",
"type": "function",
"z": "2b2676f81a6deb7d",
"name": "On/Off",
"func": "msg.payload = {\n \"dps\": 1,\n \"set\": msg.payload\n}\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 710,
"y": 800,
"wires": [
[
"d79d91df60007d08"
]
]
},
{
"id": "2435c40669d586b8",
"type": "inject",
"z": "2b2676f81a6deb7d",
"name": "Turn On",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "true",
"payloadType": "bool",
"x": 520,
"y": 780,
"wires": [
[
"2a21969c0c2b6363"
]
]
},
{
"id": "43b7394eecac0612",
"type": "inject",
"z": "2b2676f81a6deb7d",
"name": "Turn Off",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "false",
"payloadType": "bool",
"x": 510,
"y": 820,
"wires": [
[
"2a21969c0c2b6363"
]
]
}
]
So I set out to make it work with a voice command.
It seemed simple enough, so I simply did this:
Try...
[
{
"id": "e2f84d07b8024614",
"type": "switch",
"z": "2b2676f81a6deb7d",
"name": "tuya - ON",
"property": "payload.intent.name",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "tuyaON",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 500,
"y": 940,
"wires": [
[
"318239d590da3a83"
]
]
},
{
"id": "14d0beacaa37b179",
"type": "switch",
"z": "2b2676f81a6deb7d",
"name": "tuya - OFF",
"property": "payload.intent.name",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "tuyaOFF",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 510,
"y": 980,
"wires": [
[
"77744660066f4cd9"
]
]
},
{
"id": "f697fd60bbd64d66",
"type": "function",
"z": "2b2676f81a6deb7d",
"name": "On/Off",
"func": "msg.payload = {\n \"dps\": 1,\n \"set\": msg.payload\n}\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1030,
"y": 960,
"wires": [
[
"e920facd44b706fa"
]
]
},
{
"id": "e920facd44b706fa",
"type": "tuya-smart-device",
"z": "2b2676f81a6deb7d",
"deviceName": "Tuya Smart PLug",
"disableAutoStart": false,
"deviceId": "",
"deviceKey": "",
"storeAsCreds": true,
"deviceIp": "192.168.42.189",
"retryTimeout": "1001",
"findTimeout": "2000",
"tuyaVersion": "3.1",
"eventMode": "event-both",
"x": 1230,
"y": 960,
"wires": [
[],
[]
]
},
{
"id": "318239d590da3a83",
"type": "change",
"z": "2b2676f81a6deb7d",
"name": "",
"rules": [
{
"t": "set",
"p": "payload.intent.name",
"pt": "msg",
"to": "true",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 780,
"y": 940,
"wires": [
[
"f697fd60bbd64d66"
]
]
},
{
"id": "77744660066f4cd9",
"type": "change",
"z": "2b2676f81a6deb7d",
"name": "",
"rules": [
{
"t": "set",
"p": "payload.intent.name",
"pt": "msg",
"to": "false",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 780,
"y": 980,
"wires": [
[
"f697fd60bbd64d66"
]
]
}
]
But I think the payload is not converted to the right format, because I get the error :
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Socket'
| property 'parser' -> object with constructor 'HTTPParser'
--- property 'socket' closes the circle
What is this subtlety that escapes the clumsy beginner in me?
Thanks