# Only forward a message after two consequative messages with same payload

**URL:** <https://discourse.nodered.org/t/only-forward-a-message-after-two-consequative-messages-with-same-payload/69834>\
**Category:** General\
**Created:** [31 October 2022 12:16 UTC](https://discourse.nodered.org/t/only-forward-a-message-after-two-consequative-messages-with-same-payload/69834 "2022-10-31T12:16:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavyLandman](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/davylandman/32/69964_2.png) [@DavyLandman](https://discourse.nodered.org/u/DavyLandman)\
**Post date:** [31 October 2022 12:16 UTC](https://discourse.nodered.org/t/only-forward-a-message-after-two-consequative-messages-with-same-payload/69834/1 "2022-10-31T12:16:09Z")

</div>

I'm parsing something from a noisy source (literal, ascii noise over the line), and I want to filter out "wrong" messages by only sending stuff along after I've seen the same value twice in a row. Since it's a slow moving sensor, this is quite an okay noise reduction.

So how could I build this accumulating behavior?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [31 October 2022 12:31 UTC](https://discourse.nodered.org/t/only-forward-a-message-after-two-consequative-messages-with-same-payload/69834/2 "2022-10-31T12:31:32Z")

</div>

You could pass the message through a switch node set to equals previous payload.  
e.g.

```auto
[{"id":"00e5cf23448a2121","type":"switch","z":"452103ea51141731","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"","vt":"prev"}],"checkall":"true","repair":false,"outputs":1,"x":250,"y":860,"wires":[["8b685ae0571bd80d"]]},{"id":"e79d2b295950adc1","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"a","payloadType":"str","x":110,"y":840,"wires":[["00e5cf23448a2121"]]},{"id":"ec76edf4ddfc8ce7","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"b","payloadType":"str","x":90,"y":900,"wires":[["00e5cf23448a2121"]]},{"id":"8b685ae0571bd80d","type":"debug","z":"452103ea51141731","name":"debug 98","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":440,"y":880,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![JayDickson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jaydickson/32/90592_2.png) [@JayDickson](https://discourse.nodered.org/u/JayDickson)\
**Post date:** [31 October 2022 12:37 UTC](https://discourse.nodered.org/t/only-forward-a-message-after-two-consequative-messages-with-same-payload/69834/3 "2022-10-31T12:37:58Z")

</div>

@E1cid beat me to the suggestion I was leaning toward, though for similar situations you may also find value in [node-red-contrib-debounce (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-debounce)

---

<div class="post-metadata">

**Author:** ![DavyLandman](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/davylandman/32/69964_2.png) [@DavyLandman](https://discourse.nodered.org/u/DavyLandman)\
**Post date:** [31 October 2022 12:58 UTC](https://discourse.nodered.org/t/only-forward-a-message-after-two-consequative-messages-with-same-payload/69834/4 "2022-10-31T12:58:29Z")

</div>

aah, interesting.

I solved it using 2 smooth filters with a window of 2, a min & max, and then joining on the output and checking if they are the same.

But I like this switch much better, didn't know they had access to the previous value 👍

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [14 November 2022 12:59 UTC](https://discourse.nodered.org/t/only-forward-a-message-after-two-consequative-messages-with-same-payload/69834/5 "2022-11-14T12:59:19Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
