Hello @tontze
You said:
Nope. your example didn't work, but i figured it out from your example and from my earlier inject node. This is working:
I was not sure about the example in the Smartthings documentation.
I already said:
I found the msg.topic quite confusing.
So, as I'm not sure either msg.topic should be set to "switch" or msg.payload.topic should be set to "switch" or or both.
I configured them both, just to be sure.
But perfect, that it is working now.
I have one small remark to your code.
The first line of your code shows:
var msg = {
and if you click in the function node you will see a small yellow triangle with the text: 'msg' is already defined.
It is not necessary to declare the variable msg, as this is already done (by default).
So the contents of the function node should become:
Code: Select all
msg = {
topic: "switch",
payload: {
value: msg.payload.nvalue
}
}
return msg;
It is working now

I can switch smartthings switch from domoticz

Now just need to make it other way around
Can you operate the lamp, connected to the Smartthings node, and see if something is shown in the last "Debug"node.
Or if this is not possible can you test the following flow:
Code: Select all
[{"id":"7c7791de.29521","type":"inject","z":"4e92e308.9bb32c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":280,"wires":[["b994970e.927188"]]},{"id":"b6f73d8f.ef4cc8","type":"smartthings-node-onoff","z":"4e92e308.9bb32c","conf":"666c7bf2.c25414","name":"Kitchen Lights","device":"e162c5c6-80d2-46e1-aaef-741a39f934fe","x":640,"y":280,"wires":[["635ae9af.854d9"]]},{"id":"b994970e.927188","type":"function","z":"4e92e308.9bb32c","name":"Function Kitchen Light","func":"msg = {\n topic: \"update\",\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":400,"y":280,"wires":[["b6f73d8f.ef4cc8"]]},{"id":"635ae9af.854d9","type":"debug","z":"4e92e308.9bb32c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":280,"wires":[]},{"id":"666c7bf2.c25414","type":"smartthings-config","name":"ST","token":"xxx"}]
I expect you will see, something like:

- Screenshot_Smartthings2.png (12.71 KiB) Viewed 4327 times
If this is the case, can you test the following flow:
Connect the output of the Smartthings node to the input of the "Function" node.
And configure the MQTT output node, according to your configuration.
Code: Select all
[{"id":"191ec999.485656","type":"function","z":"4e92e308.9bb32c","name":"","func":"if (msg.payload.value === 1 )\n{\nmsg.payload = { \"command\": \"switchlight\", \"idx\": 11, \"switchcmd\": \"On\" };\n}\nelse if ( msg.payload.value === 0 )\n{\nmsg.payload = { \"command\": \"switchlight\", \"idx\": 11, \"switchcmd\": \"Off\" };\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1040,"y":100,"wires":[["d805ccf1.c0753"]]},{"id":"d805ccf1.c0753","type":"mqtt out","z":"4e92e308.9bb32c","name":"","topic":"domoticz/in","qos":"1","retain":"false","broker":"f9f13036.e28b58","x":1230,"y":100,"wires":[]},{"id":"f9f13036.e28b58","type":"mqtt-broker","name":"localhost","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
Awaiting your response,
Regards