# Additive / compound delay

**URL:** https://discourse.nodered.org/t/additive-compound-delay/39940
**Category:** General
**Created:** [28 January 2021 16:40 UTC](https://discourse.nodered.org/t/additive-compound-delay/39940 "2021-01-28T16:40:21Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![gazzat5](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gazzat5/32/36097_2.png) [@gazzat5](https://discourse.nodered.org/u/gazzat5)
#### Post date: [28 January 2021 16:40 UTC](https://discourse.nodered.org/t/additive-compound-delay/39940/1 "2021-01-28T16:40:22Z")

</div>

Hi there,  
I'm picking up data from mqtt as the input node, triggering a delay and then setting the msg.payload to '0'.  
However i want to know what happens if the delay gets triggered twice, do the timers run concurrently?

If the timers would run concurrently, is there a way to compound the by adding the delays together instead?

Basically i have a pir sensor that outputs a 1 to a topic when it's triggered, but never sets the topic back to 0 so i'm using a delay to do it.

Thoughts, comments and suggestions appreciated!

---

<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: [28 January 2021 17:14 UTC](https://discourse.nodered.org/t/additive-compound-delay/39940/2 "2021-01-28T17:14:00Z")

</div>

Welcome to the forum @gazzat5.

> [@gazzat5](#):
>
> do the timers run concurrently

That depends on what timer you are using. Please post here a bit of your flow so we can see what you are doing. Just the few relevant nodes.

See this post for how to share your flow here - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

### Author: ![gazzat5](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gazzat5/32/36097_2.png) [@gazzat5](https://discourse.nodered.org/u/gazzat5)
#### Post date: [28 January 2021 17:32 UTC](https://discourse.nodered.org/t/additive-compound-delay/39940/3 "2021-01-28T17:32:54Z")

</div>

Here's my flow:

```auto
[
    {
        "id": "8ea50271.939ae",
        "type": "delay",
        "z": "a84d5beb.895958",
        "name": "",
        "pauseType": "delay",
        "timeout": "5",
        "timeoutUnits": "minutes",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 440,
        "y": 1600,
        "wires": [
            [
                "5032178a.d3b698"
            ]
        ]
    },
    {
        "id": "5032178a.d3b698",
        "type": "function",
        "z": "a84d5beb.895958",
        "name": "reset_topic",
        "func": "msg.payload = 0;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 620,
        "y": 1600,
        "wires": [
            [
                "e5de41ff.8975c"
            ]
        ]
    },
    {
        "id": "e5de41ff.8975c",
        "type": "mqtt out",
        "z": "a84d5beb.895958",
        "name": "",
        "topic": "sensors/rtl_433/Smoke-GS558/unit",
        "qos": "",
        "retain": "true",
        "broker": "c10f09f0.421e98",
        "x": 890,
        "y": 1600,
        "wires": []
    },
    {
        "id": "8e8d66ea.b85608",
        "type": "mqtt in",
        "z": "a84d5beb.895958",
        "name": "",
        "topic": "sensors/rtl_433/Smoke-GS558/unit",
        "qos": "2",
        "datatype": "auto",
        "broker": "c10f09f0.421e98",
        "x": 200,
        "y": 1600,
        "wires": [
            [
                "8ea50271.939ae"
            ]
        ]
    },
    {
        "id": "c10f09f0.421e98",
        "type": "mqtt-broker",
        "z": "",
        "name": "dietpi",
        "broker": "localhost",
        "port": "1883",
        "clientid": "node-red",
        "usetls": false,
        "compatmode": false,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    }
]

```

---

<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: [28 January 2021 19:15 UTC](https://discourse.nodered.org/t/additive-compound-delay/39940/4 "2021-01-28T19:15:45Z")

</div>

I suspect a trigger node may help as it can second a second (0) output after a delay from the first. Or maybe the delay put into rate limit mode ( which will then queue them up)

---

<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: [28 January 2021 21:01 UTC](https://discourse.nodered.org/t/additive-compound-delay/39940/5 "2021-01-28T21:01:10Z")

</div>

I think maybe what you want is to use a Trigger node configured like this

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

That will start a timer when it gets a message. If nothing else happens then after five minutes it will send a message with payload 0. However if another message comes within five minutes then it will start the timer again. If yet another message arrives then it will reset again. So the result is that it will send when nothing has happened for five minutes.

---

<div class="post-metadata">

### Author: ![gazzat5](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gazzat5/32/36097_2.png) [@gazzat5](https://discourse.nodered.org/u/gazzat5)
#### Post date: [2 February 2021 15:36 UTC](https://discourse.nodered.org/t/additive-compound-delay/39940/6 "2021-02-02T15:36:03Z")

</div>

Hi, thanks for that, it does the trick 😃. I've changed the flows so that the delay writes to a different mqtt topic as not to cause a feedback loop. The flows also takes the new topic and writes to influxdb.

See below:

 ![nodered-compound-delay](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/27440bf1b6718f56718a0838e1f9dabe44cb8e0c.png)

---

<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: [16 February 2021 15:36 UTC](https://discourse.nodered.org/t/additive-compound-delay/39940/7 "2021-02-16T15:36:42Z")

</div>

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