As far as rainfall is concerned, you need to decide what you want before you start coding.
Is it rainfall over the last rolling 24 hours, or rainfall since midnight?
I use a rolling 1 hour and 24 hour values for my weather station, as described here: