# Watch node firing multiple times (\> 2)

**URL:** <https://discourse.nodered.org/t/watch-node-firing-multiple-times-2/16769>\
**Category:** General\
**Created:** [16 October 2019 12:58 UTC](https://discourse.nodered.org/t/watch-node-firing-multiple-times-2/16769 "2019-10-16T12:58:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![beemoe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/beemoe/32/13230_2.png) [@beemoe](https://discourse.nodered.org/u/beemoe)\
**Post date:** [16 October 2019 12:58 UTC](https://discourse.nodered.org/t/watch-node-firing-multiple-times-2/16769/1 "2019-10-16T12:58:00Z")

</div>

I'm using the standard `node-red: watch` node and I'm having trouble getting it to fire consistently, or allow me to filter the fires to continue the workflow one time.

It is the entry point for an AI inference model where a camera will send the image to the file system, node red then executes the .py and returns the inference result to be sent back to an HMI.

It's all working, except that it runs the workflow up to 4 times. (this kills the processor)

This is on Windows 10IOT, latest version of everything (started fresh yesterday). It seemed to work ok on Linux over WinSCP, but when I drag a file in to simulate the camera transfer it will fire multiple times. I filtered the 0 out, that was the easy one.

Some initial testing - the `.png` fires twice (same payload), a `.jpg` will fire four times also identical payloads.

From a single transfer/execution.

```auto
D:\\ai\\images : msg : Object
{ payload: "D:\ai\images\37gd2h.jpg", topic: "D:\\ai\\images", file: "37gd2h.jpg", filename: "D:\ai\images\37gd2h.jpg", size: 95320 … }
10/16/2019, 8:29:32 AMnode: 6a69fd99.a24024
D:\\ai\\images : msg : Object
{ payload: "D:\ai\images\37gd2h.jpg", topic: "D:\\ai\\images", file: "37gd2h.jpg", filename: "D:\ai\images\37gd2h.jpg", size: 95320 … }
10/16/2019, 8:29:32 AMnode: 6a69fd99.a24024
D:\\ai\\images : msg : Object
{ payload: "D:\ai\images\37gd2h.jpg", topic: "D:\\ai\\images", file: "37gd2h.jpg", filename: "D:\ai\images\37gd2h.jpg", size: 95320 … }
10/16/2019, 8:29:32 AMnode: 6a69fd99.a24024
D:\\ai\\images : msg : Object
{ payload: "D:\ai\images\37gd2h.jpg", topic: "D:\\ai\\images", file: "37gd2h.jpg", filename: "D:\ai\images\37gd2h.jpg", size: 95320 … }

```

Should I be using a different node here? Is there an updated one? Not sure what to do here.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 October 2019 13:15 UTC](https://discourse.nodered.org/t/watch-node-firing-multiple-times-2/16769/2 "2019-10-16T13:15:34Z")

</div>

Maybe use an RBE node to filter out duplicates?  
Or if it's because the writes are slow and you need to ensure it's finished then maybe a trigger node set to send nothing at first, some small timeout - but extend the timeout if another message arrives during that timeout, and then send original payload.

---

<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:** [16 October 2019 13:20 UTC](https://discourse.nodered.org/t/watch-node-firing-multiple-times-2/16769/3 "2019-10-16T13:20:15Z")

</div>

You are falling foul of the problem with watches. They trigger whenever the file is updated and that isn't when you think it is.

You will need to filter out the multiple changes. you should also add a delay before you trigger your flow to give the final update time to finish.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 October 2019 13:23 UTC](https://discourse.nodered.org/t/watch-node-firing-multiple-times-2/16769/4 "2019-10-16T13:23:36Z")

</div>

That is a common problem with the watch node. The watch events are generated by the operating system and if the write itself takes some time then the OS sees the file changing multiple times and the watch node is triggered multiple times. Whenever I use a watch node I follow it with a Trigger node as suggested by @dceejay set to do nothing initally but send the message on after a few seconds to make sure the write is complete.  
I think the suggestion to use an RBE may not be reliable as it will pass the initial message on immediately and you may find yourself reading the file before it has finished writing it.

---

<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:** [16 October 2019 13:31 UTC](https://discourse.nodered.org/t/watch-node-firing-multiple-times-2/16769/5 "2019-10-16T13:31:59Z")

</div>

> [@Colin](#):
>
> I think the suggestion to use an RBE

😃 I didn't suggest that. Just to filter out multiples - how is left as an exercise for the reader. You _could_ use the first change as the trigger as long as you can predict the time it takes to finish the changes but I agree that it isn't generally sensible.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 October 2019 13:36 UTC](https://discourse.nodered.org/t/watch-node-firing-multiple-times-2/16769/6 "2019-10-16T13:36:06Z")

</div>

> [@TotallyInformation](#):
>
> I didn't suggest that [RBE]

Correct, somebody else did. Your post had not arrived here when I sent mine, even though the timeline now shows yours several minutest before mine. I have noticed that situation before.

---

<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:** [16 October 2019 13:36 UTC](https://discourse.nodered.org/t/watch-node-firing-multiple-times-2/16769/7 "2019-10-16T13:36:49Z")

</div>

Sorry, that'll be the time machine, I keep forgetting to turn it off.

---

<div class="post-metadata">

**Author:** ![beemoe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/beemoe/32/13230_2.png) [@beemoe](https://discourse.nodered.org/u/beemoe)\
**Post date:** [16 October 2019 14:27 UTC](https://discourse.nodered.org/t/watch-node-firing-multiple-times-2/16769/8 "2019-10-16T14:27:49Z")

</div>

Welp.

I was hoping I did something silly, didn't RTFM or something in that orbit. I started to look at ways to stack the messages and then fire after a settling timer, but wanted to make sure I didn't miss something obvious before journeying out in the weeds.

Looks like I'll set my solution GPS for the weeds and see what happens.

Thanks all.

Edit: Simple enough, added a 1sec trigger that resets if it gets a new message. All testing points to that being acceptable but I have some space to open the timer for longer if I must. I've accepted @dceejay's answer.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 October 2019 14:30 UTC](https://discourse.nodered.org/t/watch-node-firing-multiple-times-2/16769/9 "2019-10-16T14:30:47Z")

</div>

As has been suggested, all you need is a Trigger node.  
Building this into the Watch node, as an option, would be a useful enhancement if someone felt strongly enough about it.
