can someone tel me ho i can write this inject in a function ?
msg.payload = {
mutiple: true,
data: {
"20": true,
"24": "00da03e803e8"
}
}
return msg
msg.payload = {
multiple: true,
data: {
"20": true,
"24": "00da03e803e8"
}
}
return msg;
Wow, we even got the detailed layout identical.
I laughed my head off! literally on the second of each post
But mine has a mistake - can you spot?
Semicolon is not required
But yes your spelling is atrocious
Did you build the inject node and send it to a debug node to check what it would produce?
I wasn't sure whether the .20
notation would build an array or an object.
my flow
[
{
"id": "157466c68314f327",
"type": "tab",
"label": "Flow 2",
"disabled": false,
"info": "",
"env": []
},
{
"id": "115ada30.1743c6",
"type": "tuya-local",
"z": "157466c68314f327",
"devName": "Test2023",
"devIp": "192.168.16.214",
"devId": "bf97ca67f3fbd97b02suxw",
"devKey": "*TgS)JB5[MQYHi=}",
"protocolVer": "3.3",
"renameSchema": "",
"filterCB": "",
"x": 760,
"y": 360,
"wires": [
[
"88349073.f9906"
]
]
},
{
"id": "88349073.f9906",
"type": "debug",
"z": "157466c68314f327",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 990,
"y": 360,
"wires": []
},
{
"id": "797d431a.95651c",
"type": "inject",
"z": "157466c68314f327",
"name": "{\"set\": true, \"dps\" : 20}",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"set\": true, \"dps\" : 20}",
"payloadType": "json",
"x": 240,
"y": 380,
"wires": [
[
"115ada30.1743c6"
]
]
},
{
"id": "e23704b.8e613f8",
"type": "inject",
"z": "157466c68314f327",
"name": "{\"set\": false, \"dps\" : 20}",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"set\": false, \"dps\" : 20}",
"payloadType": "json",
"x": 240,
"y": 340,
"wires": [
[
"115ada30.1743c6"
]
]
},
{
"id": "5953c975c9b8758c",
"type": "inject",
"z": "157466c68314f327",
"name": "button2",
"props": [
{
"p": "payload.multiple",
"v": "true",
"vt": "bool"
},
{
"p": "payload.data.20",
"v": "true",
"vt": "bool"
},
{
"p": "payload.data.24",
"v": "00da03e803e8",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 250,
"y": 540,
"wires": [
[
"115ada30.1743c6",
"0dd461832a677556"
]
]
},
{
"id": "0dd461832a677556",
"type": "debug",
"z": "157466c68314f327",
"name": "debug 5",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 980,
"y": 540,
"wires": []
},
{
"id": "2f79a39ce040a1c0",
"type": "function",
"z": "157466c68314f327",
"name": "function 2",
"func": "msg.payload = {\n mutiple: true,\n data: {\n \"20\": true,\n \"24\": \"00da03e803e8\"\n }\n}\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 540,
"y": 120,
"wires": [
[
"115ada30.1743c6",
"14e94e8765c4a5c6"
]
]
},
{
"id": "14e94e8765c4a5c6",
"type": "debug",
"z": "157466c68314f327",
"name": "debug 6",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 980,
"y": 120,
"wires": []
},
{
"id": "97bfeea14724561d",
"type": "inject",
"z": "157466c68314f327",
"name": "button1",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "true",
"payloadType": "bool",
"x": 250,
"y": 120,
"wires": [
[
"2f79a39ce040a1c0"
]
]
}
]
Mine and @Colin s are identical - only mine has a typo on the spelling of multiple
thats clear, but my problem is, i want press button1 (bolean) to start the funktion (which does not work)
when is press button2 ist the same as my first picture ist does work.
Means as inject it works, as function it dosent work
In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```
)
```
code goes here
```
You can edit and correct your post by clicking the pencil icon.
See this post for more details - How to share code or flow json
sorry for my misstake
[
{
"id": "157466c68314f327",
"type": "tab",
"label": "Flow 2",
"disabled": false,
"info": "",
"env": []
},
{
"id": "115ada30.1743c6",
"type": "tuya-local",
"z": "157466c68314f327",
"devName": "Test2023",
"devIp": "192.168.16.214",
"devId": "bf97ca67f3fbd97b02suxw",
"devKey": "*TgS)JB5[MQYHi=}",
"protocolVer": "3.3",
"renameSchema": "",
"filterCB": "",
"x": 760,
"y": 360,
"wires": [
[
"88349073.f9906"
]
]
},
{
"id": "88349073.f9906",
"type": "debug",
"z": "157466c68314f327",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 990,
"y": 360,
"wires": []
},
{
"id": "797d431a.95651c",
"type": "inject",
"z": "157466c68314f327",
"name": "{\"set\": true, \"dps\" : 20}",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"set\": true, \"dps\" : 20}",
"payloadType": "json",
"x": 240,
"y": 380,
"wires": [
[
"115ada30.1743c6"
]
]
},
{
"id": "e23704b.8e613f8",
"type": "inject",
"z": "157466c68314f327",
"name": "{\"set\": false, \"dps\" : 20}",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"set\": false, \"dps\" : 20}",
"payloadType": "json",
"x": 240,
"y": 340,
"wires": [
[
"115ada30.1743c6"
]
]
},
{
"id": "5953c975c9b8758c",
"type": "inject",
"z": "157466c68314f327",
"name": "button2",
"props": [
{
"p": "payload.multiple",
"v": "true",
"vt": "bool"
},
{
"p": "payload.data.20",
"v": "true",
"vt": "bool"
},
{
"p": "payload.data.24",
"v": "00da03e803e8",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 250,
"y": 540,
"wires": [
[
"115ada30.1743c6",
"0dd461832a677556"
]
]
},
{
"id": "0dd461832a677556",
"type": "debug",
"z": "157466c68314f327",
"name": "debug 5",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 980,
"y": 540,
"wires": []
},
{
"id": "2f79a39ce040a1c0",
"type": "function",
"z": "157466c68314f327",
"name": "function 2",
"func": "msg.payload = {\n mutiple: true,\n data: {\n \"20\": true,\n \"24\": \"00da03e803e8\"\n }\n}\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 540,
"y": 120,
"wires": [
[
"115ada30.1743c6",
"9c6f8f60bd73240b"
]
]
},
{
"id": "97bfeea14724561d",
"type": "inject",
"z": "157466c68314f327",
"name": "button1",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 250,
"y": 120,
"wires": [
[
"2f79a39ce040a1c0"
]
]
},
{
"id": "9c6f8f60bd73240b",
"type": "debug",
"z": "157466c68314f327",
"name": "debug 6",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 860,
"y": 120,
"wires": []
}
]
Sorry was my mistake i wrote the word multiple wrong (copied wrong )
You have copied the typo error to the function.
mutiple: true,
I used to like the word multiple - I suddenly don't!
yes thank you. and now my second question:
how can i create a variable for "00da03e803e8" to input another value
If you mean within the function it's self..
let someId = "00da03e803e8"
msg.payload = {
multiple: true,
data: {
"20": true,
"24": someId
}
}
return msg;
Of if you want to set it elsewhere
- Use a change node, to set a
flow
variable
[{"id":"51948002f737e19e","type":"change","z":"157466c68314f327","name":"","rules":[{"t":"set","p":"someId","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":425,"y":640,"wires":[[]]},{"id":"2b45bb0cd5f50fec","type":"inject","z":"157466c68314f327","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"00da03e803e8","payloadType":"str","x":225,"y":640,"wires":[["51948002f737e19e"]]}]
Then to grab it.
msg.payload = {
multiple: true,
data: {
"20": true,
"24": flow.get("someId")
}
}
return msg;
You are my Hero this is exactly what i need.
thx a lot
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.