You might want to build a queue with two values. One for longterm and one for last boot. In the last boot queue you always overwrite with the currently measured value. If the last measured value is zero or lower than whats stored in the last boot queue, add last boot to the longterm qeue and reset the last boot queue to zero.
Your grand total will then be the sum of the last boot and longterm value.