# Door logic problem I can't quite wrap my head around

**URL:** <https://discourse.nodered.org/t/door-logic-problem-i-cant-quite-wrap-my-head-around/100230>\
**Category:** General\
**Created:** [23 January 2026 21:10 UTC](https://discourse.nodered.org/t/door-logic-problem-i-cant-quite-wrap-my-head-around/100230 "2026-01-23T21:10:30Z")\
**Posts on this page:** 7\
**Page:** 1

<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:** [23 January 2026 21:10 UTC](https://discourse.nodered.org/t/door-logic-problem-i-cant-quite-wrap-my-head-around/100230/1 "2026-01-23T21:10:30Z")

</div>

I have a door. When the door is closed let's call that the start position. When the door is full open I want to send a signal, let's call it true, once and only once until the door fully closes again. Then when the door fully opens I want to send another true once and only once until the door fully closes again. Rinse, repeat. ad nauseum. My door hardware logic works I get good signals door open and close my fleshware logic is failing me. A gentle nudge in the right direction please?

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [23 January 2026 21:51 UTC](https://discourse.nodered.org/t/door-logic-problem-i-cant-quite-wrap-my-head-around/100230/2 "2026-01-23T21:51:25Z")

</div>

Hi @gerry, hope you are well.

Is this a contact sensor (Binary) or some kind of variable position value?  
if a variable value, I feel a threshold type approach might work maybe?

if \<5% for 10s = Closed  
if \>85% for 10s = Open

just an example - but you see where I am going

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [23 January 2026 21:57 UTC](https://discourse.nodered.org/t/door-logic-problem-i-cant-quite-wrap-my-head-around/100230/3 "2026-01-23T21:57:33Z")

</div>

It also may be handy to understand _how_ the signals are sent.

Is it you are getting an continuous _stream_ of messages with the door's condition or just when things change?

---

<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:** [23 January 2026 22:12 UTC](https://discourse.nodered.org/t/door-logic-problem-i-cant-quite-wrap-my-head-around/100230/4 "2026-01-23T22:12:59Z")

</div>

There are two nodemcu's one for door closed and one for door open. I know, it's just how it turned out. One sends mqtt door closed and the other sends door open. The messages are sent every 5 seconds  
They are micro switches, open or closed

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [23 January 2026 22:23 UTC](https://discourse.nodered.org/t/door-logic-problem-i-cant-quite-wrap-my-head-around/100230/5 "2026-01-23T22:23:15Z")

</div>

> [@gerry](#):
>
> They are micro switches, open or closed

So I am guessing you want the following

```auto
 - Close MCU Latches -> : Door closed
 - Open MCU (The other end) Latches -> : Door Open

```

But you want to ignore the de-lacthes?

I hope I am understanding?

It might help with what @Trying_to_learn asked - in that what you actually get, during each transition

**Extar, Extra - read all About**

* * *

If you get the state of both switches (every 5s as mentioned)- build a truth table

| Closed Switch | Open Switch | Agreed State |
| --- | --- | --- |
| Closed | Open | Door Closed |
| Open | Open | Transitioning |
| Open | Closed | Door Opened |

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [24 January 2026 04:47 UTC](https://discourse.nodered.org/t/door-logic-problem-i-cant-quite-wrap-my-head-around/100230/6 "2026-01-24T04:47:02Z")

</div>

Excuse the slight digression:  
The `node mcu`.  
Rather than sending the state every 5 seconds set the `retain: true` on the MQTT channel.  
Then you won't/shouldn't need to keep sending the message.

Why?  
Ok, let's think about it.  
Every 5 seconds you are sending the state of the door. GIVEN the WiFi is working.  
If it isn't, it won't really matter what happens as the message won't get through.

Marking the `retain` as `true` it means that if the WiFi goes down, the last state is remembered.  
Which also doesn't mean much as the WiFi is down. But it reduces the amount of traffic over your WiFi.

So in/on the `node-mcu`, you only send a message if the state changes.  
Again reducing the amount of traffic.  
You can also send a message of `in transit` (as your logic table allows it) and you could even project if it is _TRANSITIONING_ `open -> closed` or `closed -> open`. Which may be helpful, but not important in the bigger scheme of things.

Hope this helps.

---

<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:** [24 April 2026 04:47 UTC](https://discourse.nodered.org/t/door-logic-problem-i-cant-quite-wrap-my-head-around/100230/7 "2026-04-24T04:47:45Z")

</div>

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