Is there is more elegent solution?
````
stream
    |from()
        .measurement('data')
    |stateDuration(lambda: "state" == TRUE)
        .unit(1s)
        .quiet()
        .as('state_duration')
    |delete()
        .field('state')
    |influxDBOut()
        .database('telegraf')
        .measurement('durations')
       
stream
|from()
    .measurement('durations')
    |difference('state_duration')
    .as('diff')
    |where(lambda: "diff" < 0)
    |influxDBOut()
        .database('telegraf')
        .measurement('diff')
```

---