Downtime in realtime

What I’ve done in the past is to use an integer in the PLC to indicate state according to S88 phase state model and this is logged in the database on change with a timestamp. Using query’s you can extract the information with any timespan (variable start/end timestamp) you want.