# Garage door and motion sensor working together

**URL:** https://discourse.nodered.org/t/garage-door-and-motion-sensor-working-together/25616
**Category:** General
**Created:** [27 April 2020 11:32 UTC](https://discourse.nodered.org/t/garage-door-and-motion-sensor-working-together/25616 "2020-04-27T11:32:27Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![spider7611](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spider7611/32/20762_2.png) [@spider7611](https://discourse.nodered.org/u/spider7611)
#### Post date: [27 April 2020 11:32 UTC](https://discourse.nodered.org/t/garage-door-and-motion-sensor-working-together/25616/1 "2020-04-27T11:32:27Z")

</div>

Hi,

Have a problem what I don't know how to resolve.  
So I have a garage door with contact sensor Open/Close state.  
Near this door have a motion sensor.  
My problem is that the motion sensor see that the garage door is opening and send a message: "motion is detected" what I don't need it between opening situation.  
I want that if the door is opening the motion sensor not do anything for about 1 minute.  
After that time when the door is opened start working the motion sensor.  
When the garage door closed stop the motion sensor message if detect any motion.

Thank You.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [27 April 2020 17:33 UTC](https://discourse.nodered.org/t/garage-door-and-motion-sensor-working-together/25616/2 "2020-04-27T17:33:56Z")

</div>

So you need a "gate" style interaction. Where 1 variable is used to check whether or not an event is passed through.

I think that one of the Finite State Machine nodes such as the DSM node may be easiest to deal with. Otherwise you can do it "manually".

When the door starts to open, send a signal which NR translates to updating a variable - say to TRUE - which is kept in a context store. In your motion sensor flow, check that variable before allowing the motion to be passed on to any other nodes.

Use a trigger node after the receipt of the door opening event so that the variable gets set to false after 1 minute:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/d/8da53ba9bf177f81f8ed9aa8ccc8c1cc1bf02340.png)

---

<div class="post-metadata">

### Author: ![spider7611](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spider7611/32/20762_2.png) [@spider7611](https://discourse.nodered.org/u/spider7611)
#### Post date: [27 April 2020 18:21 UTC](https://discourse.nodered.org/t/garage-door-and-motion-sensor-working-together/25616/3 "2020-04-27T18:21:37Z")

</div>

Here is what I have now:

 ![nodered](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/e/ee4ca79ff1c4ebc393e211932a971bf1feffd16d.png)  
Motion detected then if the door open ring the doorbell and turn on gateway light.  
But I don't need doorbell ring and light when the door opening in that minute. So how can I change it?  
I'm a beginner so please if you can give step by step instruction. Thank You. 🙂

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [27 April 2020 19:17 UTC](https://discourse.nodered.org/t/garage-door-and-motion-sensor-working-together/25616/4 "2020-04-27T19:17:25Z")

</div>

As @TotallyInformation suggests, the key is to use a `trigger` node to send a pair of messages one minute apart when the door opens. There are many ways to use those messages to block signals from the motion sensor. I think that for a beginner the simplest way is to use the gate node ([node-red-contrib-simple-gate](https://flows.nodered.org/node/node-red-contrib-simple-gate)). This flow should give you the general idea:

 ![2020.04.27 garage door](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/6/361e62fe7603aea6f61e49e1c6f1a21ddeea5199.jpeg)

```auto
[{"id":"5e6daaca.bb46bc","type":"inject","z":"6d60db6b.03942c","name":"door opens","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":640,"wires":[["636503b1.bd70a4"]]},{"id":"636503b1.bd70a4","type":"change","z":"6d60db6b.03942c","name":"topic='control'","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":640,"wires":[["b5c599d0.be505"]]},{"id":"b5c599d0.be505","type":"trigger","z":"6d60db6b.03942c","op1":"close","op2":"open","op1type":"str","op2type":"str","duration":"10","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":470,"y":640,"wires":[["3a37877e.e1f3f"]]},{"id":"3a37877e.e1f3f","type":"gate","z":"6d60db6b.03942c","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":630,"y":700,"wires":[["f2ea7904.9bac7"]]},{"id":"6d1db02e.e470c","type":"inject","z":"6d60db6b.03942c","name":"motion sensed","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":460,"y":700,"wires":[["3a37877e.e1f3f"]]},{"id":"f2ea7904.9bac7","type":"debug","z":"6d60db6b.03942c","name":"motion detected","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":780,"y":700,"wires":[]}]

```

The contact and motion sensors are simulated by `inject` nodes, and the time between messages is set to 10 seconds instead of one minute for the demonstration.

---

<div class="post-metadata">

### Author: ![spider7611](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spider7611/32/20762_2.png) [@spider7611](https://discourse.nodered.org/u/spider7611)
#### Post date: [28 April 2020 07:38 UTC](https://discourse.nodered.org/t/garage-door-and-motion-sensor-working-together/25616/5 "2020-04-28T07:38:35Z")

</div>

Perfect, I think now it's working. Will test it.

 ![nodered](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/5/2543a8535978c867bf3301d860075a7720a61188.png)

Thank You Both!

---

<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: [12 May 2020 07:38 UTC](https://discourse.nodered.org/t/garage-door-and-motion-sensor-working-together/25616/6 "2020-05-12T07:38:36Z")

</div>

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