Filter by preceding row value

I think the reply to this question will help you:
Query for gap start and end time - General - InfluxData Community
What you should do is sort it in reverse time order, then apply elapsed, filter, and sort in time order. Applying elapsed will give you the time from off to the on that preceded it, so that each on has the time from itself to the next off.