Directional door sensor

Hey guys
I have been wanting to do this for a while, finally can now.
I saw some posts a long time ago about making directional sensors on the main door.
My two sensors will be a aqura zigbee door sensor on the door and an aqara zigbee motion sensor located on the outside of the door above.
Here is generally what i was thinking.
What i would like is when i am leaving my house to turn the light off. This would trigger when the door sensor sends an mqtt message first then as i step out and it triggers the motion sensor. both send to some sort of logic node then turn off the lights

When i am arriving at the house. the motion sensor would trigger first then the door sensor would trigger next and turn the lights on.

All of this is easy for me except the main logic determining the direction.

Does anybody have suggestions for doing this logic?

My initial thoughts were to do a buffer array of 2 objects, 1 sensor would send 1 message then the next sensor would send 2nd message. The buffer then flushes and sends it to a function node and i do logic on that array/buffer.
Other option would be a series of open and close gates that the messages make their way through and it would end in 2 options in or out and i would turn on the lights that way
However, both of these seem very convoluded and i may be overthinking it.

Ideas? Thx

...nice use-case.

My initial thought goes into the direction of using a dsm-node (https://github.com/cflurin/node-red-contrib-dsm) with some thing like in the traffic-light example from the node's wiki.
Like using two final states "inside" and "outside", together with two state transitions "on-my-way-out" and "on-my-way-in").

However, regardless of how to define it in node-red, I think the challenge is within the real world examples.

Especially with using the motion detector as a trigger (what about stray cats or with the mail or pizza delivery man)?

hmm that could potentially work. I will have to mess around with that and get back with you!

My main problem which I forgot to mention was actually waiting for the events to come in. Since they are not exactly at the same time there is a race condition/wait condition. I can't use delays as what if i am holding the door opening talking to someone. I find it hard to program it with a function node because how long do i wait for the additional variable? 3 seconds? 5 seconds? 10?
i would like a node that has two inputs; waits for both of those to trigger then send it. then i do processing based on which of those are at the top of an array or buffer.

you are certainly right about use delivery trucks etc. I think i will have to add more logic to it. I do have a home awareness state for each person in the house. It tracks your phone and graphs over time when you're home, when you leave, when you come back. I will have to use this also.
There are a ton of variables in there as well.
If someone is doing a delivering and i open the door to the logic it seems that I am arriving, outside triggered then door opened. so i will have to use my home awareness of; if outside is triggered , then door open and i am home don't do anything. gah! getting more complicated :stuck_out_tongue:

edit: i am also open to other suggestions of how to detect direction of door. this is just what i have seen suggested. sadly i can't find the link i read a while ago about it
i thought also maybe a touch sensor on the door handle, it is a brass handle and electrically conductive. i can fit a small zigbee sensor in there and sends a signal when touched or something? idk

Yes, a complicated scenario...
IMHO the best thing on how to determine that you really are leaving/inside and not just answering the door or filling the trashcan outside is some "Thing" that you would only carry with you when leaving home, Like your phone/wallet/set of (car-)keys. Detection could be via WLAN presence of the phone or RFID (tag reader at the door, probably).
As for direction of the door (assuming the door itself can only open to one physical direction, like outwards), using a ultrasonic sensor at low range, that gets triggered when the door is approached from the inside could be an option.
When direction is from inside to outside, the sensor is triggerd first...when from outside to inside, the sensor is triggered second/after the motion outside.

I agree that something like an NFC token on your key ring would be sensible. Even then, you might need 2 sensors, one in and one out.

I saw a much simpler solution a long time ago though. A key board near the door. Each peg on the board senses the weight of a set of keys hanging on it.

or .. https://www.wired.com/2007/04/usb-keyholder-m/ :slight_smile:

I do have a home awareness setup, phone based.
RFID could do as well.
My current door sensor alerts me via push notification if the door is open for more than 5 minutes. As there was one time I though I latched the door closed went on my way and the wind blew the door open keeping it open for many hours

I really like this idea! honestly I may do that. will have to figure out what I need to do logic with maybe a wemos and contact sensors

Yes, I have that setup as well. Also a similar setup on the freezer door. Both use 433MHz mag switches.

Have you considered adding a second motion sensor on the INSIDE of the door? I haven't worked out the full state diagram, but with four events (door:opens/closes, motion:inside/outside), you can distinguish the principal cases mentioned so far. You might also need a timeout to handle pets, delivery men who just drop off packages, etc.

How about photocell beam


or

one inside one outside, attached to something like a shelly 1.

You could then detect direction as time difference, also has advantage of no couriers, pets, wind or insects causing false alarms

One easy solution would be to have two doors, an entrance door and an exit door :grinning: We actually have two garden doors but only one main door. I'll have a look tomorrow how to do it with the dsm node.

This is a great idea. I will look into this

haha I like that idea but unfortunately cant have two doors. While I actually have 3 doors between me and the outside, my door, intermediary door , outside door. ( I live in an apartment). I do own the place but don't think other tenants would like me to put sensors on those doors.

What I was thinking actually....
adding 2 motion sensors outside, 1 door sensor, 2 motion sensors inside.
While this would get crazy to do flows for is there a node that does AI ?
I could easily train that node with door opens. When I come back I mark it as I walked in, when I leave I mark it as i left.
The 2 sensors on each side would be able to provide additional inputs to the ai node , if there is one?

then once trained enough data it would output what it thought happen based on all the sensors?
does an AI node exist?

Other option I just thought of. I am trying to think what is different from the outside and inside. The only thing differently I do when I leave is i HAVE to turn the lock handle to open the door. When I come in I use the key which unlocks the door but does not move the handle. so I could put a sensor on that maybe. I would need a mercury switch or tilt switch of some sort

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\": \"idle\",\n            \"no-motion\": \"idle\"\n        },\n        \"detected\": {\n            \"open\": \"in\",\n            \"close\": \"idle\",\n            \"no-motion\": \"idle\"\n        },\n        \"out\": {\n            \"close\": \"idle\",\n            \"no-motion\": \"idle\"\n        },\n        \"in\": {\n            \"close\": \"idle\",\n            \"no-motion\": \"idle\"\n        }\n    },\n    \"methods\": {\n        \"onBeforeTransition\": [\n            \"switch (true) {\",\n                \"case (msg.topic === 'contact'):\",\n                    \"msg.topic = msg.payload ? 'open' : 'close';\",\n                    \"break;\",\n                \"case (msg.topic === 'motion'):\",\n                    \"msg.topic = msg.payload ? 'detect' : 'no-motion';\",\n                    \"break;\",              \n            \"}\"\n        ],\n        \"onAfterTransition\": [\n            \"switch(msg.payload) {\",\n                \"case 'in':\",\n                \"case 'out':\",\n                    \"output = true;\",\n                    \"break;\",\n                \"default:\",\n                    \"output = false;\",\n            \"}\"\n        ],\n        \"status\": {\n            \"fill\": {\n                \"get\": \"sm.currentState === 'idle' ? 'grey' : sm.currentState === 'in' ? 'red' : 'green';\"\n            },\n            \"shape\": \"dot\",\n            \"text\": {\n                \"get\": \"sm.currentState;\"\n            }\n        }\n    }\n}\n","x":430,"y":220,"wires":[["a288e2cd.f4d75"]]},{"id":"12fef344.228bfd","type":"inject","z":"ac4aa9f6.c24288","name":"","topic":"contact","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":140,"wires":[["6190347.b7639cc"]]},{"id":"d6bdc384.ddb62","type":"inject","z":"ac4aa9f6.c24288","name":"","topic":"motion","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":260,"wires":[["6190347.b7639cc"]]},{"id":"a288e2cd.f4d75","type":"debug","z":"ac4aa9f6.c24288","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":630,"y":220,"wires":[]},{"id":"fa941603.5d6858","type":"inject","z":"ac4aa9f6.c24288","name":"","topic":"contact","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":180,"wires":[["6190347.b7639cc"]]},{"id":"e2c98e2c.b3939","type":"inject","z":"ac4aa9f6.c24288","name":"","topic":"motion","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":300,"wires":[["6190347.b7639cc"]]}]
2 Likes

And Paul, @zenofmud, just published a similar solution, in that case for a driveway but it could eventually be used as a base?

Here is a real World example from my door/motion sensor out of my database (german but understandable, I think). The door sensor is mounted on the inside of the door:

Block 1: Wife is kicking out the cat. With only this sensor I cannot detect if she is in the house. She stayed inside.
'66236', '2020-04-16 06:06:02', 'motion_door1', 'Alarm', '1', '(door1) Bewegung ein'
'66238', '2020-04-16 06:06:08', 'door1', 'Alarm', '1', '(door1) offen'
'66239', '2020-04-16 06:06:22', 'door1', 'Alarm', '0', '(door1) geschlossen'
'66242', '2020-04-16 06:06:32', 'motion_door1', 'Alarm', '0', '(door1) Bewegung aus'

Block 2: Wife is preparing the dog for walking and leaving the house.
'66356', '2020-04-16 06:49:01', 'motion_door1', 'Alarm', '1', '(door1) Bewegung ein'
'66358', '2020-04-16 06:49:20', 'motion_door1', 'Alarm', '0', '(door1) Bewegung aus'
'66360', '2020-04-16 06:49:27', 'motion_door1', 'Alarm', '1', '(door1) Bewegung ein'
'66362', '2020-04-16 06:49:42', 'motion_door1', 'Alarm', '0', '(door1) Bewegung aus'
'66364', '2020-04-16 06:49:54', 'motion_door1', 'Alarm', '1', '(door1) Bewegung ein'
'66365', '2020-04-16 06:50:12', 'motion_door1', 'Alarm', '0', '(door1) Bewegung aus'
'66366', '2020-04-16 06:50:41', 'motion_door1', 'Alarm', '1', '(door1) Bewegung ein'
'66367', '2020-04-16 06:51:03', 'motion_door1', 'Alarm', '0', '(door1) Bewegung aus'
'66368', '2020-04-16 06:51:07', 'door1', 'Alarm', '1', '(door1) offen'
'66369', '2020-04-16 06:51:13', 'door1', 'Alarm', '0', '(door1) geschlossen'

Block 3: Wife and the dog are coming home.
'66396', '2020-04-16 07:39:35', 'motion_door1', 'Alarm', '1', '(door1) Bewegung ein'
'66397', '2020-04-16 07:39:37', 'door1', 'Alarm', '1', '(door1) offen'
'66398', '2020-04-16 07:39:47', 'door1', 'Alarm', '0', '(door1) geschlossen'
'66399', '2020-04-16 07:39:57', 'motion_door1', 'Alarm', '0', '(door1) Bewegung aus'
'66400', '2020-04-16 07:40:05', 'motion_door1', 'Alarm', '1', '(door1) Bewegung ein'
'66401', '2020-04-16 07:40:21', 'motion_door1', 'Alarm', '0', '(door1) Bewegung aus'
'66402', '2020-04-16 07:40:28', 'motion_door1', 'Alarm', '1', '(door1) Bewegung ein'
'66403', '2020-04-16 07:40:43', 'motion_door1', 'Alarm', '0', '(door1) Bewegung aus'
'66404', '2020-04-16 07:40:49', 'motion_door1', 'Alarm', '1', '(door1) Bewegung ein'
'66405', '2020-04-16 07:41:05', 'motion_door1', 'Alarm', '0', '(door1) Bewegung aus'
'66406', '2020-04-16 07:41:18', 'motion_door1', 'Alarm', '1', '(door1) Bewegung ein'
'66408', '2020-04-16 07:41:34', 'motion_door1', 'Alarm', '0', '(door1) Bewegung aus'

The first problem is the long time for the motion message. The time between open an close is short. If somebody moves quick it is not possible to detect inside/outside. Whats about several persons? What is when the person comes in to get something and leaves?

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