Exclude values on the basis of duration

I am trying to measure a machine. This works to some extend pretty good.
But I want to exclude values, if they have not been at a specifc treshold for a certain timespan.

In this example you see it at 13:07 and 13:08. These values should be excluded in case the duration of the “status” is not at least 60 seconds on a “1” value.
For now the number of “Wickel” is “10”, but should be only “8” in this case.

Current query:
SELECT count(diff) FROM (SELECT difference(status) AS diff FROM “sensor_data” WHERE (“machine_name” =‘Rollenschneider03_Licht’) AND $timeFilter) WHERE diff=1

I am pretty new to Grafana, and couldn’t find an answer for my issue.

Thx for helping out :slight_smile: