# How to do complex event processing using node-red

**URL:** <https://discourse.nodered.org/t/how-to-do-complex-event-processing-using-node-red/17085>\
**Category:** General\
**Created:** [24 October 2019 12:47 UTC](https://discourse.nodered.org/t/how-to-do-complex-event-processing-using-node-red/17085 "2019-10-24T12:47:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)\
**Post date:** [24 October 2019 12:47 UTC](https://discourse.nodered.org/t/how-to-do-complex-event-processing-using-node-red/17085/1 "2019-10-24T12:47:32Z")

</div>

In node-red how can we do complex event processing. I am using node-red-contrib-cep node for complex event processing , is there any alternative or any simple example on this node-red-contrib-cep node only having examples of pattern,window,filter based rule.

The example which they have mentioned in node-red-contrib-cep node is not sufficient and hard to understand.

---

<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:** [24 October 2019 13:07 UTC](https://discourse.nodered.org/t/how-to-do-complex-event-processing-using-node-red/17085/2 "2019-10-24T13:07:03Z")

</div>

Can you give an example of what you would like to do?

---

<div class="post-metadata">

**Author:** ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)\
**Post date:** [24 October 2019 14:22 UTC](https://discourse.nodered.org/t/how-to-do-complex-event-processing-using-node-red/17085/3 "2019-10-24T14:22:58Z")

</div>

Like `filter, window, pattern` based situations.Like for example filter means it will check whether data is `==, >= , <= , !=,> ,<` . For window based examples it should store based on time or message length and it should store and support aggregate functions such as MAX,AVG. Then for pattern based rule it should support increment, decrement. Sequential rule also.

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [24 October 2019 14:32 UTC](https://discourse.nodered.org/t/how-to-do-complex-event-processing-using-node-red/17085/4 "2019-10-24T14:32:31Z")

</div>

So... half of those like the builtin `switch` node?

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [24 October 2019 15:35 UTC](https://discourse.nodered.org/t/how-to-do-complex-event-processing-using-node-red/17085/5 "2019-10-24T15:35:14Z")

</div>

If you think the docs are hard to understand, you could open an issue on the nodes github page and work with the nodes author to improve the docs. That way hopefully you and the community both benefit.

---

<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:** [24 October 2019 16:46 UTC](https://discourse.nodered.org/t/how-to-do-complex-event-processing-using-node-red/17085/6 "2019-10-24T16:46:24Z")

</div>

Also if there are missing features then I think adding them to that node would be the best solution. So again working with the author to improve the node would be good.

---

<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:** [24 October 2019 17:16 UTC](https://discourse.nodered.org/t/how-to-do-complex-event-processing-using-node-red/17085/7 "2019-10-24T17:16:29Z")

</div>

Some of this is easily handled with the existing switch node. For things like aggregations, you'll want to be saving data points somewhere to be able to perform the comparative analysis. Increment/decrements can be handled pretty easily in the function node. Some advanced things like statistical analysis over long periods of time may be easier if you utilize something like a time-series database (influx or similar.)

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [24 October 2019 18:03 UTC](https://discourse.nodered.org/t/how-to-do-complex-event-processing-using-node-red/17085/8 "2019-10-24T18:03:58Z")

</div>

> [@VIKRAMAS](#):
>
> support aggregate functions such as MAX,AVG

Hi @VIKRAMAS,  
while my [node-red-contrib-calc](https://github.com/bartbutenaers/node-red-contrib-calc) only covers simple mathematics, Dean's [node-red-contrib-statistics](https://github.com/DeanCording/node-red-contrib-statistics) node might contain some calculations you could use ...  
Bart
