Validating Driveway Sensors

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.

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

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.

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

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

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.

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

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