How to detect a 0-1-0 and then a 1-0-1 sequence

Hello everyone, I have a garage door sensor that when the door opens is emits a 1-0-1 sequence of events in about 2 seconds, then when it closes the inverse 0-1-0. A steady 0 means the door is closed, a steady 1 means the door is open. The image below shows first an opening sequence, then a couple minutes later a closing sequence.

image

Does anyone have any suggestions how I can generate 'door opening' and a 'door closing' events from this state? Thanks in advance.

This example may help you The inject and split simulate your payloads.

[{"id":"bbdadc0c.47864","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[0,1,0]","payloadType":"json","x":110,"y":3160,"wires":[["ff364a64.b29f7"]]},{"id":"ff364a64.b29f7","type":"split","z":"c74669a0.6a34f8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":250,"y":3180,"wires":[["db51b787.e5576","7bee5c17.c6ee14"]]},{"id":"7d9d5e3.5637e2","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1,0,1]","payloadType":"json","x":120,"y":3220,"wires":[["ff364a64.b29f7"]]},{"id":"db51b787.e5576","type":"trigger","z":"c74669a0.6a34f8","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"150","extend":true,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":430,"y":3160,"wires":[["6ab22d61.4ff8b4"]]},{"id":"7bee5c17.c6ee14","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":400,"y":3100,"wires":[]},{"id":"6ab22d61.4ff8b4","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload = 1 ? \"open\" : \"closed\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":3140,"wires":[["ca83da9f.87c02"]]},{"id":"ca83da9f.87c02","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":830,"y":3120,"wires":[]}]

I think the trigger needs to be 2.5 seconds, or thereabouts doesn't it?

yes you are correct i did not see the times on the image . maybe a second would do as the payloads seem a second apart.
[edit] 2 seconds should be fine

[{"id":"bbdadc0c.47864","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"pi/18","payload":"[0,1,0]","payloadType":"json","x":140,"y":3160,"wires":[["ff364a64.b29f7"]]},{"id":"ff364a64.b29f7","type":"split","z":"c74669a0.6a34f8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":250,"y":3180,"wires":[["dace1442.41481"]]},{"id":"7d9d5e3.5637e2","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"pi/18","payload":"[1,0,1]","payloadType":"json","x":150,"y":3220,"wires":[["ff364a64.b29f7"]]},{"id":"dace1442.41481","type":"delay","z":"c74669a0.6a34f8","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":380,"y":3260,"wires":[["db51b787.e5576","7bee5c17.c6ee14"]]},{"id":"db51b787.e5576","type":"trigger","z":"c74669a0.6a34f8","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"2","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"topic","topic":"topic","outputs":1,"x":450,"y":3180,"wires":[["6ab22d61.4ff8b4"]]},{"id":"7bee5c17.c6ee14","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":400,"y":3100,"wires":[]},{"id":"6ab22d61.4ff8b4","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload = 1 ? \"open\" : \"closed\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":3140,"wires":[["ca83da9f.87c02"]]},{"id":"ca83da9f.87c02","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":830,"y":3120,"wires":[]}]

[edit] added per topic in trigger

That's really cool - many thanks. It works perfectly after I fiddled with the times a bit and landed at about a second in the trigger. I see you cut the logic to just looking at the last digit, rather than the whole sequence, which in this case should be safe. Good solution, many thanks :+1:

1 Like

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