Change a Var when a bit sensor keep activate 5 payloads in a row

With the standard firmware in that Dragino device, you cannot add such logic to the node: one can only transmit the current digital state of pin PA12 at a fixed interval, or use AT+INTMOD=1 along with connecting the switch to interrupt pin PB14 to transmit whenever the switch state changes. (I don’t know if the Dragino firmware does proper debouncing of the input, or might use some throttling, which would be needed to avoid sending too many uplinks.)

Explaining all that’s needed to create an application to analyse those uplinks is way too much for me, or for this forum, I feel. You’ll need to hire a software developer who knows some basics about how to persist and retrieve data, and use those historical values for your business logic. It’s not something that can be achieved with just TTN Console.

It seems one can also upload one’s own Arduino sketches into that Dragino device. That would be great, if only as then you don’t waste air time using the standard Dragino payload format, which sends way more details than you need. I’ve not searched for any examples, and maybe you’d need to choose a different device altogether. But unless you’ve already started investigating this without telling us, you’d need a software developer for that too.

It might be easier to look for an off-the-shelf device that allows for setting some min/max thresholds or supports delayed alerts, to only transmit when needed. And maybe use a distance meter rather than a switch? (It seems that Nemeus NIS-UL – Ultrasonic sensor supports such thresholds, but surely there are others too.)

And of course, even with the ideal device, one would still need some application to process the uplinks too, unless something from Visualize (and push) your IOT data suffices.