# Trigger a flow after n occurences of a condition

**URL:** https://community.homey.app/t/trigger-a-flow-after-n-occurences-of-a-condition/63454
**Category:** Ideas & Suggestions
**Created:** [May 10, 2022, 12:21pm UTC](https://community.homey.app/t/trigger-a-flow-after-n-occurences-of-a-condition/63454 "2022-05-10T12:21:31Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Aybert](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Aybert](https://community.homey.app/u/Aybert)
#### Post date: [May 10, 2022, 12:21pm UTC](https://community.homey.app/t/trigger-a-flow-after-n-occurences-of-a-condition/63454/1 "2022-05-10T12:21:31Z")

</div>

Hi there

sometimes my network becomes not that stable (in particular when I upgrade the box from my provider ☹ ) And I came to an idea : would it be possible for any flow to have a counter, and actually trigger the flow only when the conditions have been met continuously over a preset number of time ?

---

<div class="post-metadata">

### Author: ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)
#### Post date: [May 10, 2022, 1:08pm UTC](https://community.homey.app/t/trigger-a-flow-after-n-occurences-of-a-condition/63454/2 "2022-05-10T13:08:27Z")

</div>

If I get you right, something like this should get it started?

When…  
(Logics) A variable [[YourCounterVar]] changed  
And…  
(Logics) Variable [[YourCounterVar]] is equal to 5  
Then…  
(Chronograph) Start or replace timer ‘Network’ with running time of 5 minutes

When…  
(Chronograph) Timer ‘Network’ has finished  
And…  
(Logics) Variable [[YourCounterVar]] is equal to 5  
Then…  
Do something

---

<div class="post-metadata">

### Author: ![Aybert](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Aybert](https://community.homey.app/u/Aybert)
#### Post date: [May 10, 2022, 6:06pm UTC](https://community.homey.app/t/trigger-a-flow-after-n-occurences-of-a-condition/63454/3 "2022-05-10T18:06:16Z")

</div>

Sorry, nope, it would be rather like this:

- Flow 1 :

- Flow 2 (inversion of flow 1)

- Flow 3

the idea is to eliminate false positives, where sometimes some conditions may be met (such as “device is not reachable”) just because the network is flapping.  
Then I would like that the condition is met 2 or 3 times in a row before triggering the flow action

---

<div class="post-metadata">

### Author: ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)
#### Post date: [May 10, 2022, 8:02pm UTC](https://community.homey.app/t/trigger-a-flow-after-n-occurences-of-a-condition/63454/4 "2022-05-10T20:02:19Z")

</div>

Well, then you could add the delay like this

- Flow 3  
When…  
(variable) has changed  
And…  
(variable) \> (threshold)  
Then…  
(Chronograph) Start or replace timer ‘Network’ with running time of 5 minutes  
Else  
(Chronograph) Pause timer ‘Network’

- Flow 4  
When…  
(Chronograph) Timer ‘Network’ has finished  
And…  
(variable) \> (threshold)  
Then…  
Start action

---

<div class="post-metadata">

### Author: ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)
#### Post date: [May 10, 2022, 8:14pm UTC](https://community.homey.app/t/trigger-a-flow-after-n-occurences-of-a-condition/63454/5 "2022-05-10T20:14:49Z")

</div>

> [@Aybert](#):
>
> Flow 2 (inversion of flow 1)
> 
> - when condition 1 is not met
> - then decrement (variable). If (variable) \<= 0 then (variable) = 0

These are 2 flows

- Flow 2A  
When…  
condition 1 is not met  
Then…  
Calculate (variable) as {{(variable)-1}}

- Flow 2B  
When…  
(variable) has changed  
And…  
(variable) is equal or less than 0  
Then…  
Set (variable) to 0
