Hi @henrybcn,
No problem, I loaded your code (flow) in my test system.
The only issue I have is if I turn it on/off from domoticz directly, I do not see it reflected in node-red. I guess this is possible right?
Yes, normally it should be indicated under the Smartnora node.

- smartnora_nodes.png (25.5 KiB) Viewed 4026 times
I took a look at your flow and simplified it.

- Test_flow_with_smartnora.png (27.22 KiB) Viewed 4026 times
Let me explain.
1. The "domoticz/out" node is capable to send a JSON payload.
So change the "Output" from "auto-detect (string or buffer)" to "a parsed JSON object"
The "auto-detect (string or buffer)" is deprecated and has been replaced by "auto-detect (parsed JSON object, string or buffer)"
In this case you can remove the JSON node. This saves a node.
2. With the "Switch" node you filter the message. In this case every message that contains msg.payload.switchType = "On/Off" will go through and all others are blocked. So if you have more than one "Switch" in Domoticz, all the switches are going to the Smartnora node.
If you have more than one "Switch" that has to go to more Smartnora nodes, it is better to filter on msg.payload.idx
3. Before the Smartnora node, you will almost always need a "Function" node.
In this "Function" node you can store the incoming idx number in the topic. This is saved and used later in the outgoing message.
However you have chosen to use fixed idx numbers (6 and 9) and therefore that line is not necessary.
The contents off the Function node is as follows:
Code: Select all
if (msg.payload.nvalue === 1)
{
msg.payload = true
}
else if (msg.payload.nvalue === 0)
{
msg.payload = false
}
return msg
So if any Switch in Domoticz is "On". you send a boolean true, otherwise a boolean false.
4. Lets look to the Smartnora node.
If you want to filter e.g. a specific idx number, you can use the previous (now removed) line msg.topic = msg.payload.idx and filter on that topic.
In this case you can tick the box after "Ignore input messages that don't match the topic value:" and set then that topic.
Set ALWAYS a Room hint, as that is used by Google.
5. Let us look to the "Function" node that has been connected to the output of the Smartnora node.
Code: Select all
let msg1 = {};
let msg2 = {};
if ( msg.payload === true )
{
msg1.payload = { "command": "switchlight", "idx": 6, "switchcmd": "On" };
msg2.payload = { "command": "switchlight", "idx": 9, "switchcmd": "On" };
}
else if ( msg.payload === false )
{
msg1.payload = { "command": "switchlight", "idx": 6, "switchcmd": "Off" };
msg2.payload = { "command": "switchlight", "idx": 9, "switchcmd": "Off" };
}
return [[msg1,msg2]]
If you want to switch two switches with one command, you can combine these in one function node.
First you have to declare two new variables msg1 and msg2.
Then you combine it and send it to one output.
See:
https://nodered.org/docs/user-guide/writing-functions
An alternative, and perhaps even better, is to create a group in Domoticz (Scenes > Add a Scene, and create a group with your two idx numbers)
In that case you can use the 'Function" node with the following contents:
Code: Select all
if (msg.payload === true)
{
msg.payload = { "command": "switchscene", "idx": 1, "switchcmd": "On" };
}
else if (msg.payload === false)
{
msg.payload = { "command": "switchscene", "idx": 1, "switchcmd": "Off" };
}
return msg
I will send you the complete flow below.
I have "Debug" nodes inserted. If you are satisfied, you can remove these. Or at least, disable the output.
Code: Select all
[{"id":"6e251134eafd988e","type":"tab","label":"Test","disabled":false,"info":"","env":[]},{"id":"4528e53.782fb1c","type":"mqtt in","z":"6e251134eafd988e","name":"","topic":"domoticz/out","qos":"0","datatype":"json","broker":"38b35487299a036d","nl":false,"rap":false,"inputs":0,"x":150,"y":380,"wires":[["681631c8.dbc208"]]},{"id":"681631c8.dbc208","type":"switch","z":"6e251134eafd988e","name":"","property":"payload.switchType","propertyType":"msg","rules":[{"t":"eq","v":"On/Off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":330,"y":380,"wires":[["f9798848.30054","dc07d78e60be9700"]]},{"id":"f9798848.30054","type":"function","z":"6e251134eafd988e","name":"Function In on/off","func":"if (msg.payload.nvalue === 1)\n {\n msg.payload = true\n }\nelse if (msg.payload.nvalue === 0)\n {\n msg.payload = false\n }\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":380,"wires":[["19084c543048e582","e818b645722e4615"]]},{"id":"caefbcc2.78bf18","type":"mqtt out","z":"6e251134eafd988e","name":"","topic":"domoticz/in","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"38b35487299a036d","x":1170,"y":380,"wires":[]},{"id":"e818b645722e4615","type":"noraf-switch","z":"6e251134eafd988e","devicename":"Stairs","roomhint":"Stair","name":"","passthru":false,"errorifstateunchaged":true,"nora":"d83ece29a87dbcd3","topic":"","onvalue":"true","onvalueType":"bool","offvalue":"false","offvalueType":"bool","twofactor":"off","twofactorpin":"","filter":false,"asyncCmd":false,"outputs":1,"x":730,"y":380,"wires":[["974ebb4877c23e82"]]},{"id":"974ebb4877c23e82","type":"function","z":"6e251134eafd988e","name":"Function out On/Off","func":"let msg1 = {};\nlet msg2 = {};\n\nif ( msg.payload === true )\n{\n msg1.payload = { \"command\": \"switchlight\", \"idx\": 6, \"switchcmd\": \"On\" };\n msg2.payload = { \"command\": \"switchlight\", \"idx\": 9, \"switchcmd\": \"On\" };\n}\nelse if ( msg.payload === false )\n{\n msg1.payload = { \"command\": \"switchlight\", \"idx\": 6, \"switchcmd\": \"Off\" };\n msg2.payload = { \"command\": \"switchlight\", \"idx\": 9, \"switchcmd\": \"Off\" };\n}\nreturn [[msg1,msg2]]","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":940,"y":380,"wires":[["d9e60f915db67447","caefbcc2.78bf18"]]},{"id":"dc07d78e60be9700","type":"debug","z":"6e251134eafd988e","name":"debug 31","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":500,"y":320,"wires":[]},{"id":"19084c543048e582","type":"debug","z":"6e251134eafd988e","name":"debug 32","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":320,"wires":[]},{"id":"a678fedbdd0fefb5","type":"function","z":"6e251134eafd988e","name":"function 1","func":"if (msg.payload === true)\n{\n msg.payload = { \"command\": \"switchscene\", \"idx\": 1, \"switchcmd\": \"On\" };\n}\nelse if (msg.payload === false)\n{\n msg.payload = { \"command\": \"switchscene\", \"idx\": 1, \"switchcmd\": \"Off\" };\n}\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":900,"y":440,"wires":[["a6ea09b3960410ba"]]},{"id":"59eace82f56d0bec","type":"inject","z":"6e251134eafd988e","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":730,"y":440,"wires":[["a678fedbdd0fefb5"]]},{"id":"88ef72b948534082","type":"inject","z":"6e251134eafd988e","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":730,"y":480,"wires":[["a678fedbdd0fefb5"]]},{"id":"d9e60f915db67447","type":"debug","z":"6e251134eafd988e","name":"debug 33","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1160,"y":320,"wires":[]},{"id":"a6ea09b3960410ba","type":"debug","z":"6e251134eafd988e","name":"debug 34","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1080,"y":440,"wires":[]},{"id":"38b35487299a036d","type":"mqtt-broker","name":"Raspberry Pi 1","broker":"192.168.10.51","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"d83ece29a87dbcd3","type":"noraf-config","name":"nora config","group":"","twofactor":"off","twofactorpin":"","localexecution":true,"structure":"","storeStateInContext":false,"disableValidationErrors":false,"sendDeviceNameAndLocation":false}]
Let know, if it is working for you.
I do not use Smartnora (anymore), so I did not test it with voice commands.
Regards