# Join/Wait Node: Timeout Feature request

**URL:** <https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633>\
**Category:** Feature Requests\
**Created:** [1 June 2020 16:12 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633 "2020-06-01T16:12:20Z")\
**Posts on this page:** 17\
**Page:** 2

<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:** [3 June 2020 07:54 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633/21 "2020-06-03T07:54:53Z")

</div>

I still think that a DSM would be the best way, I haven't used those nodes enough to knock off the solution in 5 minutes. I imagine that @cflurin would come up with a solution in no time at all if he were to have a few minutes to look at it.

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [3 June 2020 08:23 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633/22 "2020-06-03T08:23:02Z")

</div>

I haven't read the thread yet but this might help, otherwise I'll have a deaper look.

> [@Directional door sensor](https://discourse.nodered.org/t/directional-door-sensor/24551/17):
>
> A first dsm-implementation with a door contact inside and a motion sensor outside. Note: install the dsm.node first. [{"id":"6190347.b7639cc","type":"dsm","z":"ac4aa9f6.c24288","name":"in/out detection","sm\_config":"{\n \"stateOutput\": \"payload\",\n \"currentState\": \"idle\",\n \"states\": {\n \"idle\": {\n \"open\": \"opened\",\n \"detect\": \"detected\"\n },\n \"opened\": {\n \"detect\": \"out\",\n \"close\": \"id…

---

<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:** [3 June 2020 08:26 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633/23 "2020-06-03T08:26:21Z")

</div>

> [@dxdc](#):
>
> This is needed to avoid multiple `door close` events from firing the light on again.

How can you get another door close event without an open in between?

---

<div class="post-metadata">

**Author:** ![dxdc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dxdc/32/23114_2.png) [@dxdc](https://discourse.nodered.org/u/dxdc)\
**Post date:** [3 June 2020 14:03 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633/24 "2020-06-03T14:03:32Z")

</div>

@cflurin this flow is cool for state tracking, but it doesn't seem to track timing. E.g., both events need to happen within a specific timeframe.

---

<div class="post-metadata">

**Author:** ![dxdc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dxdc/32/23114_2.png) [@dxdc](https://discourse.nodered.org/u/dxdc)\
**Post date:** [3 June 2020 14:05 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633/25 "2020-06-03T14:05:29Z")

</div>

@Colin I realize this is non-ideal, but it has to do with the sensor. Sometimes - esp. depending on speed of movement and sensitivity - the open event may not fire. These sensors are all battery powered, so the latency is non-zero.

---

<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:** [3 June 2020 14:15 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633/26 "2020-06-03T14:15:08Z")

</div>

Understood. An RBE on the way in might be the easiest way to sanitise that rather than complicating the later logic.

---

<div class="post-metadata">

**Author:** ![dxdc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dxdc/32/23114_2.png) [@dxdc](https://discourse.nodered.org/u/dxdc)\
**Post date:** [3 June 2020 14:19 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633/27 "2020-06-03T14:19:31Z")

</div>

@Colin Yeah, good thought but it's still problematic though -- for instance -- if a door is rapidly open/closed, it will send the "close" event again, but RBE would block it.

---

<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:** [3 June 2020 14:50 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633/28 "2020-06-03T14:50:14Z")

</div>

Do you mean that if you get a motion event, then miss the door open, then door close that the RBE would hide that? In which case yes I think you are right, the RBE node is not what you want.

On the DSM I think the example posted was not supposed to be a complete solution but a starting point. The timer would need to be added in.

---

<div class="post-metadata">

**Author:** ![dxdc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dxdc/32/23114_2.png) [@dxdc](https://discourse.nodered.org/u/dxdc)\
**Post date:** [3 June 2020 15:39 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633/29 "2020-06-03T15:39:12Z")

</div>

> Do you mean that if you get a motion event, then miss the door open, then door close that the RBE would hide that? In which case yes I think you are right, the RBE node is not what you want.

Exactly.

> [@Colin](#):
>
> On the DSM I think the example posted was not supposed to be a complete solution but a starting point. The timer would need to be added in.

I get that, but after reading over the documentation for it (multiple times), I'm still somewhat confused by how this works or how it would even be possible to modify it to work with a timer. While I understand the code in the example (I think), there are a number of undocumented options. For example:

- The difference in labeling between states and transition names should be more clear. I don't find this intuitive that `idle` and `opened` are state names where as `open` is a transition name. It gets confusing especially when nearly identical names are chosen for state/transition.

```auto
    "states": {
        "idle": {
            "open": "opened",
            "detect": "detected"
        },
    },

```

- What is a `preState`?
- The description of what these do was not provided: `triggerInput` , `stateOutput` , `preStateOutput` , `globalOutput` and `flowOutput`
- setData and getData examples were not extremely clear, and neither were the timer/watchdog.
- The use of before/on/after transition isn't entirely obvious. I guess, before/after make sense, but not sure about on.
- `output` = true/false seems like an undocumented feature?

Maybe using a trigger and outputting the intermediate states there is some hope but I'm not really sure how it would work.

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [3 June 2020 15:53 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633/30 "2020-06-03T15:53:06Z")

</div>

> [@dxdc](#):
>
> Turn light on if 1) motion detected, and 2) door closed within 10 seconds.

Here is a first approach corresponding to your specs but I think it needs some more improvements.

```auto
[{"id":"2243fd98.bc6bf2","type":"inject","z":"aff5350e.4a1208","name":"Motion true","topic":"motion","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":140,"wires":[["de2779d0.7beb48"]]},{"id":"db2b3f24.f8ab2","type":"inject","z":"aff5350e.4a1208","name":"Door true","topic":"door","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":240,"wires":[["de2779d0.7beb48"]]},{"id":"6d2bb831.b0f508","type":"inject","z":"aff5350e.4a1208","name":"Door false","topic":"door","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":280,"wires":[["de2779d0.7beb48"]]},{"id":"7b3b3552.650bdc","type":"inject","z":"aff5350e.4a1208","name":"Motion false","topic":"motion","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":180,"wires":[["de2779d0.7beb48"]]},{"id":"de2779d0.7beb48","type":"dsm","z":"aff5350e.4a1208","name":"light control","sm_config":"{\n \"stateOutput\": \"payload\",\n \"currentState\": \"idle\",\n \"data\": {\n \"motion\": \"init\",\n \"door\": \"init\",\n \"timeover\": false,\n \"timeout\": 10\n },\n \"methods\": {\n \"motion\": [\n \"sm.data.motion = msg.payload;\",\n \"sm.data.timeover = false;\",\n \"clearTimeout(timeout.id);\",\n \"timeout.id = setTimeout(function() {\",\n \"sm.data.timeover = true;\",\n \"}, sm.data.timeout * 1000);\"\n],\n \"door\": [\n \"sm.data.door = msg.payload;\"\n],\n \"onTransition\": [\n \"if (typeof sm.data.motion !== 'init' && typeof sm.data.door !== 'init') {\",\n \"if (sm.data.motion && !sm.data.door && !sm.data.timeover) {\",\n \"msg.topic = 'light';\",\n \"msg.payload = true;\",\n \"node.send(msg);\",\n \"};\",\n \"};\"\n],\n \"status\": {\n \"fill\": {\n \"get\": \"'green';\"\n },\n \"shape\": \"dot\",\n \"text\": {\n \"get\": \"'motion: ' + sm.data.motion + ' door: ' + sm.data.door;\"\n }\n }\n }\n}\n","x":510,"y":200,"wires":[["2606da5f.12e926"]]},{"id":"2606da5f.12e926","type":"debug","z":"aff5350e.4a1208","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":200,"wires":[]}]

```

---

<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:** [3 June 2020 15:56 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633/31 "2020-06-03T15:56:36Z")

</div>

In case you missed it the detailed spec is in post 17

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [3 June 2020 16:31 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633/32 "2020-06-03T16:31:32Z")

</div>

> [@dxdc](#):
>
> While I understand the code in the example (I think), there are a number of undocumented options.

I know, the doc should be updated.  
I'm working on a new project so a Pull Request for the dsm-documentation is welcome.

Note: there are several examples in the Wiki that might help.

---

<div class="post-metadata">

**Author:** ![dxdc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dxdc/32/23114_2.png) [@dxdc](https://discourse.nodered.org/u/dxdc)\
**Post date:** [3 June 2020 16:46 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633/33 "2020-06-03T16:46:47Z")

</div>

> [@cflurin](#):
>
> I'm working on a new project so a Pull Request for the dsm-documentation is welcome.

Would consider it if I understood how it works a bit better 🙂  
It seems quite powerful once you master all the options.

> [@cflurin](#):
>
> Here is a first approach corresponding to your specs but I think it needs some more improvements.

Interesting. I'm not sure I understand the `init` state here, but it does seem to work somewhat. I get repeated outputs if motion:true is continually sent though. And, if `door:false` then `motion:true` will continue to send events without regard for the elapsed time.

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [3 June 2020 18:30 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633/34 "2020-06-03T18:30:47Z")

</div>

> [@dxdc](#):
>
> I'm not sure I understand the `init` state here

I changed `init` to `null` and typeof to `boolean`. The purpose is to allow evaluation after both inputs are set.

```auto
{
    "stateOutput": "payload",
    "currentState": "idle",
    "data": {
        "motion": null,
        "door": null,
        "timeover": false,
        "timeout": 10
    },
    "methods": {
        "motion": [
            "sm.data.motion = msg.payload;",
            "sm.data.timeover = false;",
            "clearTimeout(timeout.id);",
            "timeout.id = setTimeout(function() {",
                "sm.data.timeover = true;",
            "}, sm.data.timeout * 1000);"
        ],
        "door": [
            "sm.data.door = msg.payload;"
        ],
        "onTransition": [
            "if (typeof sm.data.motion === 'boolean' && typeof sm.data.door === 'boolean') {",
                "if (sm.data.motion && !sm.data.door && !sm.data.timeover) {",
                    "msg.topic = 'light';",
                    "msg.payload = true;",
                    "node.send(msg);",
                "};",
            "};"
        ],
        "status": {
            "fill": {
                "get": "'green';"
            },
            "shape": "dot",
            "text": {
                "get": "'motion: ' + sm.data.motion + ' door: ' + sm.data.door;"
            }
        }
    }
}

```

Regarding the function I'll have a look tomorrow.

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [4 June 2020 09:25 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633/35 "2020-06-04T09:25:08Z")

</div>

@dxdc: my point of view:

1. You have built a contrib-node because you think you can't do it with the core-nodes, that's ok just use your node.

2. Howerver I'm quite sure this can be achieved with the core nodes. If you want an `one-node` solution have a look at the `function` node or use the `dsm` node, just start with a simple example. You don't need to understand all the features and options.

3. I only use a few contrib-nodes (less installtion and most important less maintenance). With the core-nodes (they should remain simple to use) and some contrib-nodes (2 of 8 are my nodes) I can almost do all what I need.

---

<div class="post-metadata">

**Author:** ![dxdc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dxdc/32/23114_2.png) [@dxdc](https://discourse.nodered.org/u/dxdc)\
**Post date:** [4 June 2020 17:19 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633/36 "2020-06-04T17:19:45Z")

</div>

I generally agree that simpler is better. There is some functionality that I feel would be really valuable in the context of core nodes though that isn't there. It's "possible" to add it using elaborate function nodes, but at that point, it's cleaner to just make it a separate contrib node for maintenance reasons in my opinion... esp. since you can add unit tests for those.

I think the core nodes would benefit tremendously from enhanced boolean logic gates/state tracking, as well as having that happen within a fix time window, rather than trying to reinvent the wheel. I think these problems are ubiquitous enough that making core nodes with them would be very beneficial.

---

<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:** [3 August 2020 17:19 UTC](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633/37 "2020-08-03T17:19:50Z")

</div>

Closed on 3 August 2020 17:19 UTC

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

[Previous page](https://discourse.nodered.org/t/join-wait-node-timeout-feature-request/27633.md?page=1)
