# Filter by change or x min

**URL:** <https://discourse.nodered.org/t/filter-by-change-or-x-min/87076>\
**Category:** General\
**Created:** [8 April 2024 11:38 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076 "2024-04-08T11:38:56Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![volvog](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@volvog](https://discourse.nodered.org/u/volvog)\
**Post date:** [8 April 2024 11:38 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076/1 "2024-04-08T11:38:56Z")

</div>

I want to reduce data flow. From a sensor I get a value every 10s. In case there's no change I don't want to save this value (RBE-Node) except every 5 min (something like "still alive")... Otherwise it'll look in the dashboard as there have been no values which might be interpreted as error...

Any ideas? Currently I'm using the RBE-filter...

---

<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:** [8 April 2024 11:50 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076/2 "2024-04-08T11:50:41Z")

</div>

follow the filter/RBE node with a trigger node set to resend existing msg - then resend every 5 minutes...

---

<div class="post-metadata">

**Author:** ![volvog](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@volvog](https://discourse.nodered.org/u/volvog)\
**Post date:** [8 April 2024 22:48 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076/3 "2024-04-08T22:48:35Z")

</div>

So after the RBE a trigger...  
But won't the trigger resend EVERY msg? Meaning also the messages, that have different values compared to the message before?  
Maybe I haven't described in detail... As long as the values vary, I want to have the values every 10 seconds. Only if the value is the same than before (i.e. PV power during night), then I want to have a value (although it's the same value) every 5 min...

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [8 April 2024 23:17 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076/4 "2024-04-08T23:17:13Z")

</div>

You can use a trigger node to reset the filter if no message has emerged from it for 5 minutes.  
The next input message will then pass through the filter even if it's the same value.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/e/0e548c3936d63bca60bd7e2c0d6646dbe5dd5369.png)

```auto
[{"id":"9bf344f8c13cc042","type":"rbe","z":"d2183b1d5cb6d0b1","name":"RBE","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":530,"y":120,"wires":[["e20b1c5b5a7bf5eb","b01cda49dd383cf5"]]},{"id":"e20b1c5b5a7bf5eb","type":"trigger","z":"d2183b1d5cb6d0b1","name":"Wait 5 min","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"5","extend":true,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":430,"y":180,"wires":[["2f243365e5746f7d"]]},{"id":"2f243365e5746f7d","type":"change","z":"d2183b1d5cb6d0b1","name":"set msg.reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":180,"wires":[["9bf344f8c13cc042"]]}]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 April 2024 23:26 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076/5 "2024-04-08T23:26:13Z")

</div>

(Just passing by and noticed this)

Ok, so you are wanting

> [@volvog](#):
>
> In case there's no change I don't want to save this value (RBE-Node) except every 5 min (something like "still alive").

But that means - say - you get a value (say `20`) and for the next 5 minutes it has been `20`.  
The dashboard will be showing the `20`.

You allow the latest value of `20` to go through to _keep it alive_.  
But nothing will change and you won't see a change.

So - forgive me - but I don't understand what you are wanting to do.

I'm asking because I am kind of like you with a lot of my dashboards and this is still an ongoing _problem_ with my stuff too.

An _option_ is to show a _heart beat_ signal every _so often_.

Also check if the connection is lost (sorry, I can't elaborate on that any more than that as I am not sure where all the things are) that the existing `20` will be replaced with either a `0` or `CONNECTION LOST` kind of message.  
(That was a big stumbling block for me for a wile in the early days)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [8 April 2024 23:47 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076/6 "2024-04-08T23:47:56Z")

</div>

You could have a second trigger node which sends "No input received" or whatever after a bit longer delay than the first trigger eg 6 minutes.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/4/b4cf146c0e4f380089ef96eb69ab782d579a27b2.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [9 April 2024 00:36 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076/7 "2024-04-09T00:36:03Z")

</div>

There are good and bad reasons to use the `RBE` node.

Stopping _duplicate_ data is one case.

# If I may:

Case in point - and this is going to be a bit of a long read.  
But I think it is relevant to what is happening here.

Way back when I used to do a `PING` to detect machines on my network.  
Fixed IP addresses.

The `PING` would be sent out every so often and I would get either `false` or a value of the `ping time`.  
If it was `false` the machine was either OFF or not connected.  
And so if it was a _value_ the device would be online.

So the _node_ to detect that device would look for `false` and if that was the case the machine was off-line/had a problem or (with a value) was online and would adjust the indication on the `dashboard`.

This worked for years and I kind of became comfortable with it as it worked.  
But then....... as with all good ideas: it was no longer practical.

As I added more devices I had to edit the `ping list` for any new devices. Not the end of the world, but was slow and painful.

`nmap -sP <ip range>/mask` was SO MUCH easier, as it did a whole network scan and gave me ALL connected devices.  
WAY easier than the `PING` method.  
But there was a trade off.  
If a device wasn't online (or what ever) I wouldn't get a `false` for that IP address.

That meant I had to use something like what @jbudd suggested.  
It wasn't that_cut and dry_ but it was something I hadn't considered and so I had to make some code to account for that.

# The important thing I found I needed to consider:

Do I get BOTH a _I'm alive_ signal as well as a _I am dead_ signal?

If you only get an _alive_ signal, you need to add some code to detect if the messages stop arriving.  
Otherwise that isn't a problem.

The code to do this MUST go BEFORE the `RBE` part or you will never see the messages are not being received.

I would strongly suggest you make the timeout AT LEAST TWICE the time the messages arrive.  
Unless it is CRITICAL! But then the time between messages would be much lower. But there are traps with being too tight on the timing as a missed message may set off alarms for no reason other than a missed message.

I usually set it to THREE times the message frequency before saying it has failed.

Hope that helps in some way.

---

<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:** [9 April 2024 08:09 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076/8 "2024-04-09T08:09:54Z")

</div>

> [@volvog](#):
>
> won't the trigger resend EVERY msg?

No, it resends only the last message it received. dceejay's suggestion will do exactly what you have asked for.

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

```auto
[{"id":"bc41b91b8c855ddb","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":230,"y":5380,"wires":[["4b52a6bc5817b27e"]]},{"id":"e2e69a86f310dd4f","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":230,"y":5440,"wires":[["4b52a6bc5817b27e"]]},{"id":"4b52a6bc5817b27e","type":"rbe","z":"bdd7be38.d3b55","name":"Block duplicates","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":410,"y":5400,"wires":[["51fc458dd49e1f38"]]},{"id":"51fc458dd49e1f38","type":"trigger","z":"bdd7be38.d3b55","name":"","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"-5","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":600,"y":5400,"wires":[["668298de4e1a94be"]]},{"id":"668298de4e1a94be","type":"debug","z":"bdd7be38.d3b55","name":"debug 2514","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":5400,"wires":[]}]

```

---

<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:** [9 April 2024 08:25 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076/9 "2024-04-09T08:25:02Z")

</div>

Thank you @Colin... I was just about to post my own example (that is exactly that... even down to the 5s for test purposes 😉 )

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [9 April 2024 08:59 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076/10 "2024-04-09T08:59:14Z")

</div>

> [@Colin](#):
>
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/2/92f6b768d0e75b3cac15047bd545981aa1f4338d.png)
> 
> image738×133 10.4 KB

Debug 2514 🤯

---

<div class="post-metadata">

**Author:** ![volvog](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@volvog](https://discourse.nodered.org/u/volvog)\
**Post date:** [9 April 2024 09:13 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076/11 "2024-04-09T09:13:54Z")

</div>

If you're not sending the 20 any more and the value will go to 100... then you'll see a line from 20 to 100 over 6 hours. But in reality 5:59 hours the value was 20 and then went to 100...

---

<div class="post-metadata">

**Author:** ![volvog](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@volvog](https://discourse.nodered.org/u/volvog)\
**Post date:** [9 April 2024 09:16 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076/12 "2024-04-09T09:16:17Z")

</div>

Hey, that's a lot of reaction to my question... Thank you very much. I will test in the evening.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [9 April 2024 09:31 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076/13 "2024-04-09T09:31:31Z")

</div>

> [@volvog](#):
>
> it'll look in the dashboard as there have been no values which might be interpreted as error...

I personally don't like the idea of resending an old message because it falsifies the info on the dashboard.

If the sensor data stops arriving, @dceejay's solution will continue to send the last message for ever, or at least until you redeploy the flow.

My approach will only ever pass fresh messages as they arrive from the sensor.  
If dots are getting added to the graph you can be confident that the sensor data is still arriving.

Of course my post responding to @Trying_to_learn, a warning when sensor data fails, is applicable to either solution.

---

<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:** [9 April 2024 09:40 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076/14 "2024-04-09T09:40:52Z")

</div>

Depends on the chart you are using and the interpolation... on Dashboard v1 - ui-chart node you can select step interpolation which will step up to your 100 value only when it arrives... so yeah... depends on your chart as well 🙂  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/c/4c6eea149314937fb1d466d100fadb7ffad391e9.png)

---

<div class="post-metadata">

**Author:** ![volvog](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@volvog](https://discourse.nodered.org/u/volvog)\
**Post date:** [9 April 2024 10:18 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076/15 "2024-04-09T10:18:08Z")

</div>

That's a good idea. Just checked it and yes, Grafana also has this options...  
Thank you very much for the idea!

---

<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:** [9 April 2024 12:31 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076/16 "2024-04-09T12:31:02Z")

</div>

> [@Steve-Mcl](#):
>
> Debug 2514

I imported a flow from here which bumped it up to a ridiculous value. I think node-red uses the current highest value as its base for new ones. What we need is a simple flow to renumber all the debug nodes in a flow to get it back down again. Well thats what _I_ need anyway

---

<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:** [23 April 2024 12:31 UTC](https://discourse.nodered.org/t/filter-by-change-or-x-min/87076/17 "2024-04-23T12:31:56Z")

</div>

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