# Validating Driveway Sensors

**URL:** https://discourse.nodered.org/t/validating-driveway-sensors/24989
**Category:** General
**Created:** [17 April 2020 01:13 UTC](https://discourse.nodered.org/t/validating-driveway-sensors/24989 "2020-04-17T01:13:13Z")
**Posts on this page:** 6
**Page:** 1

<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: [17 April 2020 01:13 UTC](https://discourse.nodered.org/t/validating-driveway-sensors/24989/1 "2020-04-17T01:13:13Z")

</div>

I have two staggered IR photobeams across my driveway to detect vehicle direction. This allows lights to turn on when coming home and turn off when leaving. It works great but currently only requires one beam to be broken.

There have been very few false alarms where something only broke one beam. I have debug nodes in the flow showing only one broken beam.

I would like to add a way to validate the fact a vehicle entered by requiring both beams to be broken within say 3 seconds of each other. An inbound alarm would only be generated by the inbound beam broken first followed by the outbound within 3 seconds. And naturally the opposite for an outbound alarm. Any ideas or suggestions to break through my brain fog would be appreciated.

Below is not my full flow but just an example of the simplicity of what I am using now.

```auto
[{"id":"e79207e7.720088","type":"inject","z":"1a5978fd.b9c0d7","name":"","topic":"","payload":"inbound","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":290,"y":120,"wires":[["ad17d183.ecc56"]]},{"id":"fccd042a.74c978","type":"inject","z":"1a5978fd.b9c0d7","name":"","topic":"","payload":"outbound","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":240,"wires":[["ad17d183.ecc56"]]},{"id":"ad17d183.ecc56","type":"delay","z":"1a5978fd.b9c0d7","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"5","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":620,"y":160,"wires":[["50d01e88.132ac"]]},{"id":"50d01e88.132ac","type":"debug","z":"1a5978fd.b9c0d7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":940,"y":180,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [17 April 2020 08:24 UTC](https://discourse.nodered.org/t/validating-driveway-sensors/24989/2 "2020-04-17T08:24:02Z")

</div>

Here is a basic flow you can try - each inject represents one of the two sensors. Both end up conneting to a join however if the second sensor reading doesn't occur within 5 seconds, the first is dumped.

After the join you can use the topic to determine the order of the sensors and then use that for the direction the object is moving.

 ![Screen Shot 2020-04-17 at 2.24.09 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/1/51d5b8f0e1b6a60608109d4693a909113694ff3a.png)

```auto
[{"id":"dd6ff42c.2f5f88","type":"inject","z":"d18bea89.51692","name":"IR 1","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":80,"wires":[["a417ff7c.29d6"]]},{"id":"77685b44.d3ff9c","type":"inject","z":"d18bea89.51692","name":"IR 2","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":490,"y":80,"wires":[["ef5a5db.167d7a"]]},{"id":"a417ff7c.29d6","type":"change","z":"d18bea89.51692","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":160,"y":140,"wires":[["b6fe8401.05d838","96e261b7.2cb5b8"]]},{"id":"ef5a5db.167d7a","type":"change","z":"d18bea89.51692","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":500,"y":140,"wires":[["d194d130.679948","b6d394f5.0a11f8"]]},{"id":"20f31cd3.f6b344","type":"join","z":"d18bea89.51692","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":350,"y":380,"wires":[["eaec277e.419168"]]},{"id":"eb5e53bb.a9c7d8","type":"delay","z":"d18bea89.51692","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":120,"y":320,"wires":[["86be1c07.657d8"]]},{"id":"86be1c07.657d8","type":"change","z":"d18bea89.51692","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":140,"y":380,"wires":[["20f31cd3.f6b344"]]},{"id":"b6fe8401.05d838","type":"change","z":"d18bea89.51692","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":160,"y":220,"wires":[["20f31cd3.f6b344"]]},{"id":"eaec277e.419168","type":"debug","z":"d18bea89.51692","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":350,"y":500,"wires":[]},{"id":"d194d130.679948","type":"change","z":"d18bea89.51692","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":500,"y":220,"wires":[["20f31cd3.f6b344"]]},{"id":"6db72338.b11d74","type":"link in","z":"d18bea89.51692","name":"","links":["96e261b7.2cb5b8","b6d394f5.0a11f8"],"x":95,"y":280,"wires":[["eb5e53bb.a9c7d8"]]},{"id":"96e261b7.2cb5b8","type":"link out","z":"d18bea89.51692","name":"","links":["6db72338.b11d74"],"x":95,"y":180,"wires":[]},{"id":"b6d394f5.0a11f8","type":"link out","z":"d18bea89.51692","name":"","links":["6db72338.b11d74"],"x":435,"y":180,"wires":[]}]

```

---

<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: [17 April 2020 17:45 UTC](https://discourse.nodered.org/t/validating-driveway-sensors/24989/3 "2020-04-17T17:45:11Z")

</div>

I'm not getting any message out to the debug. I noticed the switch node appears to be empty?

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [17 April 2020 18:21 UTC](https://discourse.nodered.org/t/validating-driveway-sensors/24989/4 "2020-04-17T18:21:50Z")

</div>

Oops, I added that in because I was going to do more but decided to leave that to you. Stick a `debug` on the output of the `join` so you can see what you get from it.

I've edited the post to remove the switch.

---

<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: [18 April 2020 22:26 UTC](https://discourse.nodered.org/t/validating-driveway-sensors/24989/5 "2020-04-18T22:26:02Z")

</div>

Now you know how green I am!! Yup, that solved the problem. That's for your help and efforts. Should solve my issue.

---

<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: [17 June 2020 22:26 UTC](https://discourse.nodered.org/t/validating-driveway-sensors/24989/6 "2020-06-17T22:26:02Z")

</div>

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