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

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?

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

1 Like

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?

1 Like

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

So I am guessing you want the following

 - 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

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.