Validating Driveway Sensors

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