So after trying several things and failing, I did some more reading. A couple of things that I tried and was disappointed in that I could not get them to work were the accumulators without deltas and the weewx accumulator time page (both that I posted in the previous notice.
In particular, the accumulator page where they define mintime, maxtime, lastime as extractors within the accumulator looked so promising but everything I tried created errors within the accum.py program.
I also kept running into issues where it seemed that the accumulators were reseting at the end of each archive (REC) loop!
So here is my present solution (not yet tested cause I am waiting for thunderstorms to come through!!!) .
There are three sections to this.
The first section is the [STDCalibrate] in weewx.conf
the lightning_distance and lightning_strike_count come from the Deltas defined in the SDR.py
[StdCalibrate]
[[Corrections]]
# For each type, an arbitrary calibration expression can be given.
# It should be in the units defined in the StdConvert section.
# Example:
foo = foo + 0.2
# lightning_strike_count is a internal variable that is used by weewx in reports. It shows the numer of lightning strikes that occured within a loop/archive interval
# obtain information about lightning strikes for reporting to hubitat
# lightning_count_sum is the sum of lightning_strike_count for the day
# lightning_strike_last_distance = distance of the last lightning strike
# lightning_strike_min_distance = distance of the closest lightning strike
#
# still have work to do to obtain the time of the two lightning strikes
# still have testing to do on what is presently done
lightning_count_sum = lightning_strike_count
lightning_strike_min_distance = lightning_distance
lightning_strike_last_distance = lightning_distance
lightning_strike_last_time = lightning_distance
lightning_strike_min_time = lightning_distance
The second is the [Accumulator} section
[Accumulator]
#
# Set up accumulators for monitoring the lightning strikes
#
# Set them all for daily accumulation (period = daily)
#
[[lightning_count_sum]]
period = daily
extractor = sum
[[lightning_strike_last_distance]]
period = daily
extractor = last
[[lightning_strike_min_distance]]
period = daily
extractor = min
[[lightning_strike_last_time]]
period = daily
lastime = user.accumulators.LastTimeAccumulator
[[lightning_strike_min_time]]
period = daily
mintime = user.accumulatos.MinTimeAccumulator
##############################################################################
you will see to custom accumulators in the Accumulators... they are stored in a file /etc/weewx/bin/user/accumulators.py
# user/accumulators.py
import weewx.accum
class MinTimeAccumulator(weewx.accum.Accumulator):
"""Custom accumulator to track the timestamp of the minimum value."""
def __init__(self, obs_type):
super(MinTimeAccumulator, self).__init__(obs_type)
self.min_val = None
self.min_time = None
def accumulate(self, record):
"""Process each record from the archive."""
value = record.get(self.obs_type)
if value is None:
return
ts = record.get('dateTime')
if self.min_val is None or value < self.min_val:
self.min_val = value
self.min_time = ts
def get_result(self):
"""Return the timestamp of the minimum value."""
return self.min_time
class LastTimeAccumulator(weewx.accum.Accumulator):
"""Custom accumulator to track the timestamp of the last value."""
def __init__(self, obs_type):
super(LastTimeAccumulator, self).__init__(obs_type)
self.last_val = None
self.last_time = None
def accumulate(self, record):
"""Process each record from the archive."""
value = record.get(self.obs_type)
if value is None:
return
ts = record.get('dateTime')
if self.last_val is None or value < self.min_val:
self.last_val = value
self.last_time = ts
def get_result(self):
"""Return the timestamp of the minimum value."""
return self.last_time
Again... these have not been tested yet (waiting on a thunderstorm) and I am expecting some level of disappointment when it gets here!!!! However, watching the records in the database they are being written and all the values are 0/Null at this point (which is what they should be). I am thinking that I might need to put a qualifier on the STDCalibration section about only doing anything unless lightning_strike_count is none 0 (a lightning strike occured within the loop interval. I am also expecting that the mintime and lasttime accumulators that i wrote may not be 100% correct or may be able to be done more eloquently.
If you have any thoughts let me know.
THanks
Patrick