Trigger light after two sensors are triggered in a specific sequence

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:

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.

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.

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, to only pass messages from the GATE for two minutes after the ROAD triggers

[{"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":[]}]
1 Like

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

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!

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

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

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.

[{"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"]]}]

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