# Hold status for x seconds

**URL:** https://discourse.nodered.org/t/hold-status-for-x-seconds/84556
**Category:** General
**Created:** [15 January 2024 10:23 UTC](https://discourse.nodered.org/t/hold-status-for-x-seconds/84556 "2024-01-15T10:23:32Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![ic81](https://avatars.discourse-cdn.com/v4/letter/i/e274bd/32.png) [@ic81](https://discourse.nodered.org/u/ic81)
#### Post date: [15 January 2024 10:23 UTC](https://discourse.nodered.org/t/hold-status-for-x-seconds/84556/1 "2024-01-15T10:23:32Z")

</div>

Hi everyone,

I'm begineer....🙂

I need an info....

I've two node (iot sensors) with boolean output (updated every seconds) that pilot raspberry GPIO.  
I need that when one of this sensor goes true, the true state stay true for x seconds.

The problem is that if one sensor goes true, the other one send false and reset the output.  
Any ideas?

Thanks for your help.

---

<div class="post-metadata">

### Author: ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)
#### Post date: [15 January 2024 10:42 UTC](https://discourse.nodered.org/t/hold-status-for-x-seconds/84556/2 "2024-01-15T10:42:40Z")

</div>

Hi,  
Maybe the following, add a function node between your two nodes and the GPIO node

```js
const output = context.get('output') || false;

if (msg.payload === true && !output) {
  context.set('output', true);
  node.send({ payload: true });
  // Inject false after 10s
  setTimeout(() => {
    context.set('output', false);
    node.send({ payload: false });
  }, 10000); // <- adjust time here in ms
}

```

When one of the two nodes sends true it sends a true message and triggers a timeout of 10s which will send false.

---

<div class="post-metadata">

### Author: ![ic81](https://avatars.discourse-cdn.com/v4/letter/i/e274bd/32.png) [@ic81](https://discourse.nodered.org/u/ic81)
#### Post date: [15 January 2024 10:54 UTC](https://discourse.nodered.org/t/hold-status-for-x-seconds/84556/3 "2024-01-15T10:54:04Z")

</div>

Thanks a lot!!!!!!!

---

<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: [15 January 2024 11:00 UTC](https://discourse.nodered.org/t/hold-status-for-x-seconds/84556/4 "2024-01-15T11:00:01Z")

</div>

As a beginner, i would recommend you get to know the nodes a bit better before reaching for a function node.

Here is another approach:

![chrome_UXEFui7byf](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/5/c542b7f70f1202ed1d11051bfca863989ded2ae5.gif)

Demo flow  
_Use `CTRL+I` to import_

```auto
[{"id":"c1d40a844369be8f","type":"inject","z":"e0236af69e824001","name":"Fake Sensor 1 true","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":330,"y":160,"wires":[["a45425b2a93f587f"]]},{"id":"3af7aefde8bc24b7","type":"inject","z":"e0236af69e824001","name":"Fake Sensor 1 false","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":330,"y":200,"wires":[["a45425b2a93f587f"]]},{"id":"94cd9a8bf54d4059","type":"inject","z":"e0236af69e824001","name":"Fake Sensor 2 true","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":330,"y":300,"wires":[["a45425b2a93f587f"]]},{"id":"026ebcf939ce4106","type":"inject","z":"e0236af69e824001","name":"Fake Sensor 2 false","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":330,"y":340,"wires":[["a45425b2a93f587f"]]},{"id":"a45425b2a93f587f","type":"switch","z":"e0236af69e824001","name":"is true?","property":"payload","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":560,"y":240,"wires":[["1373dc1ab9abfef5"]]},{"id":"3efc628fc449d21c","type":"debug","z":"e0236af69e824001","name":"to next node ->","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":740,"y":360,"wires":[]},{"id":"1373dc1ab9abfef5","type":"trigger","z":"e0236af69e824001","name":"send false after 10s (extend if more arrive)","op1":"","op2":"false","op1type":"pay","op2type":"bool","duration":"10","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":660,"y":300,"wires":[["3efc628fc449d21c"]]}]

```

---

<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: [15 January 2024 11:02 UTC](https://discourse.nodered.org/t/hold-status-for-x-seconds/84556/5 "2024-01-15T11:02:08Z")

</div>

> [@ic81](#):
>
> I'm begineer...

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

### Author: ![ic81](https://avatars.discourse-cdn.com/v4/letter/i/e274bd/32.png) [@ic81](https://discourse.nodered.org/u/ic81)
#### Post date: [15 January 2024 11:05 UTC](https://discourse.nodered.org/t/hold-status-for-x-seconds/84556/6 "2024-01-15T11:05:22Z")

</div>

thanks!!!

---

<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: [15 March 2024 11:05 UTC](https://discourse.nodered.org/t/hold-status-for-x-seconds/84556/7 "2024-03-15T11:05:41Z")

</div>

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