Same event use with Node-Red


#1

Hi,
I have two node, one for detector of open door and another for detector of water.
The probleme is that I use the same changment event.

Detector of open/close door
image
image

And detector of water
image
image

And when i use detector of door or water, it send me an email from both..

image

I know that is two differents nodeid and i should be abble to send an email of one of them depending what action i do. but how can I do that ?
Somebody could help me and just give me an example ?

Thank you for your help


#2

Can you post your flow ? Replace the zwave key nodes with some inject nodes containing the strings that come from the zwave nodes.


#3

Simple example. The key is to be able to distinguish to source. Here I add a msg.topic.

[{"id":"dfa876bb.414a5","type":"inject","z":"652f7308.d51334","name":"","topic":"","payload":"255","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":160,"wires":[["84c40e6.8bbb37"]]},{"id":"e2851d93.abb09","type":"inject","z":"652f7308.d51334","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":120,"wires":[["84c40e6.8bbb37"]]},{"id":"84c40e6.8bbb37","type":"change","z":"652f7308.d51334","name":"water","rules":[{"t":"set","p":"topic","pt":"msg","to":"water","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":140,"wires":[["f1dcc175.37c8c"]]},{"id":"291023f2.ca1be4","type":"inject","z":"652f7308.d51334","name":"","topic":"","payload":"255","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":260,"wires":[["d28ffb86.83835"]]},{"id":"4bb12e01.0d2e18","type":"inject","z":"652f7308.d51334","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":220,"wires":[["d28ffb86.83835"]]},{"id":"d28ffb86.83835","type":"change","z":"652f7308.d51334","name":"door","rules":[{"t":"set","p":"topic","pt":"msg","to":"door","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":220,"wires":[["f1dcc175.37c8c"]]},{"id":"167b6872.0d5d2","type":"debug","z":"652f7308.d51334","name":"0","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":710,"y":160,"wires":[]},{"id":"8716058f.cf401","type":"debug","z":"652f7308.d51334","name":"255","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":710,"y":220,"wires":[]},{"id":"f1dcc175.37c8c","type":"switch","z":"652f7308.d51334","name":"0 or 255","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"255","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":500,"y":180,"wires":[["167b6872.0d5d2"],["8716058f.cf401"]]}]

#4

Isn't that the answer to your question? Most people use the topic to ensure differentiation. I do that myself.


#5

Hi, and thanks for your help.
I followed your exemple and me node is:
Door is open
{"_msgid":"43e2a05a.bc1d6","topic":"","payload":"La porte d'entrée a été ouverte le 14/3/2019 à 22:53:11=>0"}

Door is closed
{"_msgid":"29706a69.d68f96","topic":"","payload":"La porte d'entrée a été fermée le 14/3/2019 à 22:54:20 => 255"}

and for the water
Water is detected
{"_msgid":"6b87dc2e.947824","topic":"","payload":"Une fuite d'eau est détectée !14/3/2019 à 23:17:36=>0"}

{"nodeid":9,"event":255,"uuid":"b827ebcca0ee-0xfb755da4-9"}

There is no water
{"_msgid":"23e376cf.dc1c8a","topic":"","payload":"Il n'y a plus de fuite d'eau détectée !14/3/2019 à 23:18:14=>255"}

{"nodeid":9,"event":0,"uuid":"b827ebcca0ee-0xfb755da4-9"}

So, I see my Topics are empty... is it the problem ? could I modify that ?

Thanks


#6

It is caused by the function node where you don't return the topic.


#7

Ok...

So, what I have to do...
Make a function that not return anything as Topic ?

Could you show me?


#8

Reduced example:

[{"id":"95f0573a.ab5d18","type":"function","z":"14ea57f3.6898c8","name":"","func":"d = new Date()\np = msg.payload.event\nt = msg.topic\n\nif(p===0 && t == \"door\"){\n    o = \"door closed\"\n}\nif(p===255 && t == \"door\"){\n    o = \"door open\"\n}\nif(p===0 && t == \"water\"){\n    o = \"no water detected\"\n}\nif(p===255 && t == \"water\"){\n    o = \"water detected\"\n}\n\nmsg.payload = o + \" \" + d\nreturn msg\n","outputs":1,"noerr":0,"x":550,"y":220,"wires":[["752c91c5.839a2"]]},{"id":"752c91c5.839a2","type":"debug","z":"14ea57f3.6898c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":690,"y":220,"wires":[]},{"id":"9e42ad3c.2ed6d","type":"change","z":"14ea57f3.6898c8","name":"topic: water","rules":[{"t":"set","p":"topic","pt":"msg","to":"water","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":200,"wires":[["95f0573a.ab5d18"]]},{"id":"b53e82a1.618848","type":"change","z":"14ea57f3.6898c8","name":"topic: door","rules":[{"t":"set","p":"topic","pt":"msg","to":"door","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":240,"wires":[["95f0573a.ab5d18"]]},{"id":"5022dbc1.c9a1fc","type":"inject","z":"14ea57f3.6898c8","name":"0","topic":"","payload":"{\"event\":0}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":200,"wires":[["9e42ad3c.2ed6d","b53e82a1.618848"]]},{"id":"f2c3c4d3.ef2378","type":"inject","z":"14ea57f3.6898c8","name":"255","topic":"","payload":"{\"event\":255}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":240,"wires":[["9e42ad3c.2ed6d","b53e82a1.618848"]]}]

Look at the inject node and the function node.
Connect your zwave key nodes to the "topic" nodes and it should work.


#9

Hi bakman, I'm sorry for my late to you answer.

But I was doing some tests.
Thanks you very much for your help !!
I did that and it works well.

[{"id":"cfcef1e0.c01ca","type":"zwave-in","z":"9b6d8e05.12229","name":"Zwave key","controller":"bf9b88b2.96f5c8","x":80,"y":1440,"wires":[["872e4127.da32b"]]},{"id":"872e4127.da32b","type":"switch","z":"9b6d8e05.12229","name":"","property":"payload.nodeid","propertyType":"msg","rules":[{"t":"eq","v":"9","vt":"str"},{"t":"eq","v":"4","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":300,"y":1440,"wires":[["b26017c4.34ae18"],["b26017c4.34ae18"]]},{"id":"6000f6bf.a61d68","type":"debug","z":"9b6d8e05.12229","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":1440,"wires":[]},{"id":"b26017c4.34ae18","type":"function","z":"9b6d8e05.12229","name":"","func":"d = new Date() \np = msg.payload.event\ni = msg.payload.nodeid\n/* t = msg.topic */\n\nif(p===0 && i == \"4\"){\n    o = \"door closed\"\n}\nif(p===255 && i == \"4\"){\n    o = \"door open\"\n}\nif(p===0 && i == \"9\"){\n    o = \"no water detected\"\n}\nif(p===255 && i == \"9\"){\n    o = \"water detected\"\n}\n\nmsg.payload = o + \" \" + d\n\nreturn msg\n","outputs":1,"noerr":0,"x":490,"y":1440,"wires":[["6000f6bf.a61d68"]]},{"id":"bf9b88b2.96f5c8","type":"zwave-controller","z":0,"port":"/dev/ttyACM0","driverattempts":"3","pollinterval":"10000","allowunreadyupdates":false,"networkkey":"","logging":true}]

What do you think about that ?