Calculating event duration from boolean values?

The best solution for this is probably to use Kapacitor with a script something like this…

stream
	|from()
		.database('door')
		.measurement('door')
	|stateDuration(lambda: "value" == FALSE)
		.unit(1s)
	|influxDBOut()
		.database('door')
		.retentionPolicy('autogen')
		.measurement('door_open')

However, as noted by @michael on this thread, you’ll need to sample and write the sate of the door more often than just on state changes in order for it to calculate state duration.

1 Like