# Trigger light after two sensors are triggered in a specific sequence

**URL:** <https://discourse.nodered.org/t/trigger-light-after-two-sensors-are-triggered-in-a-specific-sequence/86305>\
**Category:** General\
**Created:** [10 March 2024 03:13 UTC](https://discourse.nodered.org/t/trigger-light-after-two-sensors-are-triggered-in-a-specific-sequence/86305 "2024-03-10T03:13:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![erkme73](https://avatars.discourse-cdn.com/v4/letter/e/e495f1/32.png) [@erkme73](https://discourse.nodered.org/u/erkme73)\
**Post date:** [10 March 2024 03:13 UTC](https://discourse.nodered.org/t/trigger-light-after-two-sensors-are-triggered-in-a-specific-sequence/86305/1 "2024-03-10T03:13:38Z")

</div>

I have two sensors on the approach to my gate. One is at the road (ROAD), the other is at the gate (GATE). I currently have NR watching for GATE after sunset. If it is triggered, it causes all exterior lights to turn on around the house.

However, this means if I leave my house at night, the lights come on unnecessarily upon my departure. So I would like to use some kind of logic that will define the trigger as:

At night, ROAD sensor trips, \<2 min, GATE sensor trips = lights on.

IOW, ROAD must trip BEFORE (but within 2min) of GATE. This should result in the lights coming on only as someone is approaching my property, rather than departing it.

I'm really stumped as to how to incorporate that into my flow.

This is my current flow for a simple GATE trigger:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/9/69c65bd94e298fe24e37ea6a55111c33addbe712.png)

The "de-bounce" is in there because the GATE sensor has a tendency to send more than one pulse in rapid succession which was causing a race condition with the "light was OFF" switch. The "light was OFF" switch is intended to prevent the auto off nodes from activating if the lights were already on.

---

<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:** [10 March 2024 03:38 UTC](https://discourse.nodered.org/t/trigger-light-after-two-sensors-are-triggered-in-a-specific-sequence/86305/2 "2024-03-10T03:38:40Z")

</div>

I fear you are not getting replies because not many people use your system.

## Suggestion:

Make a _basic_ flow with `inject` nodes for sensors, and `debug` nodes for outputs.

You press `inject1` then `inject2` - in a certain time - and see what you get.

Start with that kind of flow and work up to what you have.

As much as I can appreciate what you are doing, as said: everyone doesn't have those nodes and aren't going to spend time helping you if they don't have them.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [10 March 2024 05:48 UTC](https://discourse.nodered.org/t/trigger-light-after-two-sensors-are-triggered-in-a-specific-sequence/86305/3 "2024-03-10T05:48:03Z")

</div>

Hello @erkme73, welcome to the forum.

I think all your blue nodes are Home Assistant?  
Not sure how well my approach would play with HA.

I would use a "gate" node, [node-red-contrib-simple-gate](https://flows.nodered.org/node/node-red-contrib-simple-gate), to only pass messages from the GATE for two minutes after the ROAD triggers

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

```auto
[{"id":"d017ce9e8e14372d","type":"gate","z":"698e71d46d8d7345","name":"","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memory","x":390,"y":160,"wires":[["c2997a7ff6c1a15e"]]},{"id":"27c8669e6ddba171","type":"inject","z":"698e71d46d8d7345","name":"Your road sensor","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":80,"wires":[["b46622842d88ee6a"]]},{"id":"b46622842d88ee6a","type":"change","z":"698e71d46d8d7345","name":"msg.topic = control","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":80,"wires":[["92a217295d80c0c1"]]},{"id":"92a217295d80c0c1","type":"trigger","z":"698e71d46d8d7345","name":"Open gate for 2 min","op1":"open","op2":"close","op1type":"str","op2type":"str","duration":"2","extend":true,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":580,"y":80,"wires":[["d017ce9e8e14372d"]]},{"id":"33b5fbd482e208f5","type":"inject","z":"698e71d46d8d7345","name":"Your gate sensor","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":160,"wires":[["d017ce9e8e14372d"]]},{"id":"c2997a7ff6c1a15e","type":"trigger","z":"698e71d46d8d7345","name":"Lights on for 10 min","op1":"ON","op2":"OFF","op1type":"str","op2type":"str","duration":"10","extend":true,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":570,"y":160,"wires":[["b6943fe264b5168c"]]},{"id":"b6943fe264b5168c","type":"debug","z":"698e71d46d8d7345","name":"debug 470","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":160,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![erkme73](https://avatars.discourse-cdn.com/v4/letter/e/e495f1/32.png) [@erkme73](https://discourse.nodered.org/u/erkme73)\
**Post date:** [10 March 2024 13:08 UTC](https://discourse.nodered.org/t/trigger-light-after-two-sensors-are-triggered-in-a-specific-sequence/86305/4 "2024-03-10T13:08:11Z")

</div>

Thank you! I will give this a try later today. Much appreciated!

---

<div class="post-metadata">

**Author:** ![erkme73](https://avatars.discourse-cdn.com/v4/letter/e/e495f1/32.png) [@erkme73](https://discourse.nodered.org/u/erkme73)\
**Post date:** [11 March 2024 01:19 UTC](https://discourse.nodered.org/t/trigger-light-after-two-sensors-are-triggered-in-a-specific-sequence/86305/5 "2024-03-11T01:19:11Z")

</div>

Wow! That worked awesome and was exactly what I needed. I'm such a noob when it comes to programming (and logic in general), so that was great help. Thank you!

---

<div class="post-metadata">

**Author:** ![Randy](https://avatars.discourse-cdn.com/v4/letter/r/2acd7d/32.png) [@Randy](https://discourse.nodered.org/u/Randy)\
**Post date:** [12 March 2024 00:43 UTC](https://discourse.nodered.org/t/trigger-light-after-two-sensors-are-triggered-in-a-specific-sequence/86305/6 "2024-03-12T00:43:18Z")

</div>

I have a similar driveway sensor setup and needed to have both sensors tripped in sequence to indicate a valid vehicle. I was having issues with deer breaking only one IR beam causing an alarm. Instead, zenofmud helped me with the code he provided.

It will also send either an inbound or outbound message depending on the vehicle direction.

[https://discourse.nodered.org/t/driveway-sensors/51516](https://discourse.nodered.org/t/driveway-sensors/51516)

---

<div class="post-metadata">

**Author:** ![erkme73](https://avatars.discourse-cdn.com/v4/letter/e/e495f1/32.png) [@erkme73](https://discourse.nodered.org/u/erkme73)\
**Post date:** [12 March 2024 01:12 UTC](https://discourse.nodered.org/t/trigger-light-after-two-sensors-are-triggered-in-a-specific-sequence/86305/7 "2024-03-12T01:12:45Z")

</div>

I'm open to learning alternatives, but unfortunately, your link isn't working: Oops! That page doesn’t exist or is private.

---

<div class="post-metadata">

**Author:** ![Randy](https://avatars.discourse-cdn.com/v4/letter/r/2acd7d/32.png) [@Randy](https://discourse.nodered.org/u/Randy)\
**Post date:** [13 March 2024 23:06 UTC](https://discourse.nodered.org/t/trigger-light-after-two-sensors-are-triggered-in-a-specific-sequence/86305/8 "2024-03-13T23:06:31Z")

</div>

Not sure why the link isn't working for you? I just clicked on it and went straight to the post.  
Let me see if I can include the code here. Might have to delete this posting and try again if I mess it up.

```auto
[{"id":"733884a.6f1157c","type":"inject","z":"8011676faa725d2d","name":"IR 1 outbound","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":150,"y":340,"wires":[["db737fd8.cc035"]]},{"id":"db737fd8.cc035","type":"change","z":"8011676faa725d2d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"},{"t":"set","p":"topic","pt":"msg","to":"ir1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":240,"wires":[["13a2d331.895a3d","1210fd37.ae1a53"]]},{"id":"ad64588c.5aa708","type":"change","z":"8011676faa725d2d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"},{"t":"set","p":"topic","pt":"msg","to":"ir2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":140,"wires":[["a9fb5562.84d4d8","1210fd37.ae1a53"]]},{"id":"2414f4a4.e3bcac","type":"join","z":"8011676faa725d2d","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":890,"y":180,"wires":[["a62d706d.a2995","39720e26.e21ff2"]]},{"id":"1210fd37.ae1a53","type":"delay","z":"8011676faa725d2d","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":542.857120513916,"y":187.1428918838501,"wires":[["99fc1560.561378"]]},{"id":"99fc1560.561378","type":"change","z":"8011676faa725d2d","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":704.2856712341309,"y":187.14290142059326,"wires":[["2414f4a4.e3bcac"]]},{"id":"13a2d331.895a3d","type":"change","z":"8011676faa725d2d","name":"","rules":[{"t":"set","p":"parts.id","pt":"msg","to":"sensors","tot":"str"},{"t":"set","p":"parts.index","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"parts.count","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"parts.type","pt":"msg","to":"object","tot":"str"},{"t":"set","p":"parts.key","pt":"msg","to":"ir1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":622.8571395874023,"y":240.00001049041748,"wires":[["2414f4a4.e3bcac"]]},{"id":"2296f152.6e4d2e","type":"debug","z":"8011676faa725d2d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1385.7143516540527,"y":178.57138538360596,"wires":[]},{"id":"a9fb5562.84d4d8","type":"change","z":"8011676faa725d2d","name":"","rules":[{"t":"set","p":"parts.id","pt":"msg","to":"sensors","tot":"str"},{"t":"set","p":"parts.index","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"parts.count","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"parts.type","pt":"msg","to":"object","tot":"str"},{"t":"set","p":"parts.key","pt":"msg","to":"ir2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":622.8571395874023,"y":140.00001049041748,"wires":[["2414f4a4.e3bcac"]]},{"id":"39720e26.e21ff2","type":"change","z":"8011676faa725d2d","name":"","rules":[{"t":"change","p":"topic","pt":"msg","from":"ir1","fromt":"str","to":"inbound","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1064.2857475280762,"y":202.85713386535645,"wires":[["e62d86f2.ff40e8"]]},{"id":"a62d706d.a2995","type":"change","z":"8011676faa725d2d","name":"","rules":[{"t":"change","p":"topic","pt":"msg","from":"ir2","fromt":"str","to":"outbound","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1065.7143287658691,"y":161.4285430908203,"wires":[["e62d86f2.ff40e8"]]},{"id":"e62d86f2.ff40e8","type":"switch","z":"8011676faa725d2d","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"inbound","vt":"str"},{"t":"eq","v":"outbound","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":1241.4285697937012,"y":178.5713939666748,"wires":[["2296f152.6e4d2e"],["2296f152.6e4d2e"],["6dbdeaba63717a2f"]]},{"id":"418e4870e73366fc","type":"inject","z":"8011676faa725d2d","name":"Start","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":90,"y":140,"wires":[["ad64588c.5aa708","5aa1c39d65eeb7d3"]]},{"id":"5aa1c39d65eeb7d3","type":"delay","z":"8011676faa725d2d","name":"","pauseType":"delay","timeout":"7","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":120,"y":240,"wires":[["db737fd8.cc035","d0300997405063f7"]]},{"id":"d0300997405063f7","type":"delay","z":"8011676faa725d2d","name":"","pauseType":"delay","timeout":"6","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":260,"y":180,"wires":[["ad64588c.5aa708"]]},{"id":"6dbdeaba63717a2f","type":"debug","z":"8011676faa725d2d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1347.1428565979004,"y":254.2856798171997,"wires":[]},{"id":"062a5c817d74cf9b","type":"inject","z":"8011676faa725d2d","name":"IR 2 inbound","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":60,"wires":[["ad64588c.5aa708"]]}]

```

---

<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:** [27 March 2024 23:06 UTC](https://discourse.nodered.org/t/trigger-light-after-two-sensors-are-triggered-in-a-specific-sequence/86305/9 "2024-03-27T23:06:40Z")

</div>

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