Calculate how long time a switch has been turned on during a specific period

This should give you a starting point:

1 Like