# Same event use with Node-Red

**URL:** https://discourse.nodered.org/t/same-event-use-with-node-red/8952
**Category:** General
**Created:** [14 March 2019 02:21 UTC](https://discourse.nodered.org/t/same-event-use-with-node-red/8952 "2019-03-14T02:21:22Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![florent](https://avatars.discourse-cdn.com/v4/letter/f/e19b73/32.png) [@florent](https://discourse.nodered.org/u/florent)
#### Post date: [14 March 2019 02:21 UTC](https://discourse.nodered.org/t/same-event-use-with-node-red/8952/1 "2019-03-14T02:21:22Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6017426b134eb6381ab3b9cd6f777a2dcb4ca5da.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/784c3fcbd67126c7d3338bcad6b8cf8ec3d5d893.png)

And detector of water  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/df5ecc9f47fc2943597c3d21b6279cf82e1d5f79.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/ffaab69a568558df1ce58acfebbc1c2c3a69cf62.png)

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/32599075b06e4277a194a5b5c90c3224412e6c66.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6d779adf67c85c5ac7d814af53448c1347a944ce.png)

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

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [14 March 2019 05:32 UTC](https://discourse.nodered.org/t/same-event-use-with-node-red/8952/2 "2019-03-14T05:32:18Z")

</div>

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

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [14 March 2019 06:07 UTC](https://discourse.nodered.org/t/same-event-use-with-node-red/8952/3 "2019-03-14T06:07:05Z")

</div>

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

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [14 March 2019 09:23 UTC](https://discourse.nodered.org/t/same-event-use-with-node-red/8952/4 "2019-03-14T09:23:27Z")

</div>

> [@bakman2](#):
>
> Here I add a msg.topic

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

---

<div class="post-metadata">

### Author: ![florent](https://avatars.discourse-cdn.com/v4/letter/f/e19b73/32.png) [@florent](https://discourse.nodered.org/u/florent)
#### Post date: [15 March 2019 03:21 UTC](https://discourse.nodered.org/t/same-event-use-with-node-red/8952/5 "2019-03-15T03:21:14Z")

</div>

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"}

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/62699ed2663a21fa1c3f6b424a03f38661eaebf1.png)

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"}

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/8cd8635cf6fa35145adcf7b6efe826f8282f9803.png)

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

Thanks

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [15 March 2019 04:45 UTC](https://discourse.nodered.org/t/same-event-use-with-node-red/8952/6 "2019-03-15T04:45:58Z")

</div>

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

---

<div class="post-metadata">

### Author: ![florent](https://avatars.discourse-cdn.com/v4/letter/f/e19b73/32.png) [@florent](https://discourse.nodered.org/u/florent)
#### Post date: [16 March 2019 01:00 UTC](https://discourse.nodered.org/t/same-event-use-with-node-red/8952/7 "2019-03-16T01:00:44Z")

</div>

Ok...

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

Could you show me?

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [16 March 2019 05:14 UTC](https://discourse.nodered.org/t/same-event-use-with-node-red/8952/8 "2019-03-16T05:14:25Z")

</div>

Reduced example:

```auto
[{"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.

---

<div class="post-metadata">

### Author: ![florent](https://avatars.discourse-cdn.com/v4/letter/f/e19b73/32.png) [@florent](https://discourse.nodered.org/u/florent)
#### Post date: [19 March 2019 02:51 UTC](https://discourse.nodered.org/t/same-event-use-with-node-red/8952/9 "2019-03-19T02:51:30Z")

</div>

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.

```auto
[{"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 ?
