How to sum current duration in next duration

for a single detector, consider

#define MyHW
#ifdef MyHW
# include "LiquidCrystal.h"     // local copy
int doorPin = A1;

#else
# include <Debouncer.h>
#include <LiquidCrystal.h>
int doorPin = 2;
#endif

enum { Off = HIGH, On = LOW };

// -----------------------------------------------------------------------------
LiquidCrystal lcd(12, 11, 5, 4, 10, 7);
int Contrast=108;

int ledPin = 13;
int rise_count = 0;
int fall_count = 0;
int buttonState = 0;
int doorLst = 0;

unsigned long startTime;
unsigned long endTime;

unsigned long duration;
unsigned long total;

char s [80];

// -----------------------------------------------------------------------------
void setup() {
    Serial.begin(115200);

    analogWrite(6,Contrast);
    lcd.begin(16, 2);

    pinMode(ledPin, OUTPUT);
    pinMode(doorPin, INPUT_PULLUP);
    doorLst = digitalRead (doorPin);

    Serial.println("start");
}

// -----------------------------------------------------------------------------
void loop() {
    byte door = digitalRead (doorPin);

    if (doorLst != door)  {
        doorLst = door;

        if (On == door)  {
            digitalWrite(ledPin, On);
            fall_count++;

            startTime = millis ();
        }
        else {
            digitalWrite(ledPin, Off);
            rise_count++;

            endTime  = millis();
            duration = endTime - startTime;
            total   += duration;
        }

        delay (10);
    }

    sprintf (s, " IN : %4d, OUT: %4d, duration %4ld, total %4ld",
        fall_count, rise_count, (duration+500)/1000, total/1000);
    lcd.print (s);
}