# Trigger a flow if state changes to false and stays at false for over a minute

**URL:** https://discourse.nodered.org/t/trigger-a-flow-if-state-changes-to-false-and-stays-at-false-for-over-a-minute/63793
**Category:** General
**Created:** [11 June 2022 14:58 UTC](https://discourse.nodered.org/t/trigger-a-flow-if-state-changes-to-false-and-stays-at-false-for-over-a-minute/63793 "2022-06-11T14:58:08Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![maxweissboeck](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maxweissboeck/32/59803_2.png) [@maxweissboeck](https://discourse.nodered.org/u/maxweissboeck)
#### Post date: [11 June 2022 14:58 UTC](https://discourse.nodered.org/t/trigger-a-flow-if-state-changes-to-false-and-stays-at-false-for-over-a-minute/63793/1 "2022-06-11T14:58:08Z")

</div>

Sorry folks if this is already answered, but I'm searching and experimenting now for hours without any progress.

Problem:

I have a node that fires **true** or **false** , depending if a server connection is alive or dead.  
As long as **true** messages are coming, all is ok, nothing to do.  
But if **false** messages are coming for more than 1 minute (without any **true** message in this time), I need to start a flow to take some action.

I experimented with Delay and Trigger Node, but so far I have no glue how to handle this.

In theory it is easy:

- if a **false** message is coming, start a timer with one minute and ignore all following **false** messages
- if a **true** message is coming, reset the timer (and ignore all following **true** messages or again reset the timer, does not matter)
- if timer fires (1 minute is over and no **true** message arrived in this time), fire the action flow and reset timer

Thanks, Max

---

<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: [11 June 2022 15:04 UTC](https://discourse.nodered.org/t/trigger-a-flow-if-state-changes-to-false-and-stays-at-false-for-over-a-minute/63793/2 "2022-06-11T15:04:56Z")

</div>

Do you mean this

```auto
[{"id":"da2756de.d5664","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":3160,"wires":[]},{"id":"63503f14.9acb28","type":"trigger","z":"bf9e1e33.030598","name":"","op1":"","op2":"false for 1 min","op1type":"nul","op2type":"str","duration":"1","extend":false,"overrideDelay":false,"units":"min","reset":"true","bytopic":"all","topic":"topic","outputs":1,"x":320,"y":3200,"wires":[["da2756de.d5664"]]},{"id":"591b2162.21b8f8","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":131,"y":3195,"wires":[["63503f14.9acb28"]]},{"id":"67c6f334.9f7c84","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":121,"y":3235,"wires":[["63503f14.9acb28"]]}]

```

---

<div class="post-metadata">

### Author: ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)
#### Post date: [11 June 2022 15:19 UTC](https://discourse.nodered.org/t/trigger-a-flow-if-state-changes-to-false-and-stays-at-false-for-over-a-minute/63793/3 "2022-06-11T15:19:43Z")

</div>

one note about @E1cid's flow. after a deploy you have to inject at least once to set the trigger node or the node won't fire. After a deploy, if no server messages come in it will never fire the trigger node. You have to have at least one message. I solve this by using an inject node set to fire once at power on which then sets the trigger. This may be an edge situation but be aware it could happen.

---

<div class="post-metadata">

### Author: ![maxweissboeck](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maxweissboeck/32/59803_2.png) [@maxweissboeck](https://discourse.nodered.org/u/maxweissboeck)
#### Post date: [12 June 2022 15:41 UTC](https://discourse.nodered.org/t/trigger-a-flow-if-state-changes-to-false-and-stays-at-false-for-over-a-minute/63793/4 "2022-06-12T15:41:04Z")

</div>

Wow, it is really easy if you know how 🙃  
Thank you very much!

---

<div class="post-metadata">

### Author: ![maxweissboeck](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maxweissboeck/32/59803_2.png) [@maxweissboeck](https://discourse.nodered.org/u/maxweissboeck)
#### Post date: [12 June 2022 15:42 UTC](https://discourse.nodered.org/t/trigger-a-flow-if-state-changes-to-false-and-stays-at-false-for-over-a-minute/63793/5 "2022-06-12T15:42:46Z")

</div>

Thank you for the hint on initialisation, works perfect now

---

<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: [26 June 2022 15:42 UTC](https://discourse.nodered.org/t/trigger-a-flow-if-state-changes-to-false-and-stays-at-false-for-over-a-minute/63793/6 "2022-06-26T15:42:51Z")

</div>

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