How do I fully integrate a new custom data field? I've got it working somewhat, but...

119 views
Skip to first unread message

Kevin Key

unread,
Aug 4, 2020, 12:15:45 AM8/4/20
to weewx-user
Hi all,

So today I added the following code to a new file in usr/share/weewx/user/evapcooler.py :


import weewx
from weewx.engine import StdService

class MyEvapCooler(StdService):
    def __init__(self, engine, config_dict):
        super(MyEvapCooler, self).__init__(engine, config_dict)
        self.bind(weewx.NEW_ARCHIVE_RECORD, self.new_archive_record)

    def new_archive_record(self, event):
        try:
                event.record['evapcoolerdelta'] = event.record['outTemp'] - event.record['extraTemp2']
        except KeyError:
            pass


import schemas.wview_extended

schema_with_evapcoolerdelta = {
    'table': schemas.wview_extended.table + [('evapcoolerdelta', 'REAL')],
    'day_summaries' : schemas.wview_extended.day_summaries + [('evapcoolerdelta', 'SCALAR')]


---

I'm able to bring up the new field "evapcoolerdelta" in current.inc under /skins/Seasons/ , but I'm having trouble getting the min/max archive data for day, week, month, and year to appear. Are there other places in the code where I need to make it know that I've added a new data field?

Thanks,

Kevin

Andrew Milner

unread,
Aug 4, 2020, 3:22:09 AM8/4/20
to weewx-user
did you change the binding to use the new database with the extra field??

Kevin Key

unread,
Aug 4, 2020, 4:32:13 AM8/4/20
to weewx-user
Thanks Andrew. I followed those directions and got much further. Now I see the new field "evapcoolerdelta" in the Sqlite database, but the values ren't being populated.

Tom Keffer

unread,
Aug 4, 2020, 10:04:56 AM8/4/20
to weewx-user
If you run weewxd directly, it will print out all the LOOP packets and archive records. Do you see 'evapcoolerdelta' in there?

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/fdef2286-e1d3-40cf-8e50-786616b47687n%40googlegroups.com.

Kevin Key

unread,
Aug 4, 2020, 1:46:32 PM8/4/20
to weewx-user
I couldn't get weewxd to display anything, but I ran this command instead:

sudo tail -f /var/log/user.log


I still don't see my new field evapcoolerdelta anywhere in the output.

Tom Keffer

unread,
Aug 4, 2020, 2:39:31 PM8/4/20
to weewx-user
It would not show up in the log.

Did you try running weewxd directly?

Kevin Key

unread,
Aug 4, 2020, 6:49:43 PM8/4/20
to weewx-user
It turns out I had to stop the regular weewx service first - then I was able to get weewxd to display the output. Still no evapcoolerdelta though. :(

LOOP:   2020-08-04 15:47:28 PDT (1596581248) altimeter: 29.91256, barometer: 29.91256, dateTime: 1596581248, inDewpoint: 64.675919618, inHumidity: 55.0, inTemp: 82.5, inTempBatteryStatus: 1, pressure: 29.91256, rainRate: 0, usUnits: 1
LOOP:   2020-08-04 15:47:29 PDT (1596581249) altimeter: 29.91256, barometer: 29.91256, dateTime: 1596581249, extraHumid2: 74.0, extraTemp2: 74.4, extraTemp2BatteryStatus: 74.4, pressure: 29.91256, rainRate: 0, usUnits: 1
LOOP:   2020-08-04 15:47:32 PDT (1596581252) altimeter: 29.91256, barometer: 29.91256, dateTime: 1596581252, extraHumidity1: 76.0, extraTemp1: 37.4, extraTemp1BatteryStatus: 37.4, pressure: 29.91256, rainRate: 0, usUnits: 1
LOOP:   2020-08-04 15:47:35 PDT (1596581255) altimeter: 29.91256, barometer: 29.91256, dateTime: 1596581255, pressure: 29.91256, rain: 0.0, rainRate: 0, txBatteryStatus: 0, usUnits: 1, windDir: 293.0, windSpeed: 5.0
LOOP:   2020-08-04 15:47:44 PDT (1596581264) altimeter: 29.91256, barometer: 29.91256, dateTime: 1596581264, inDewpoint: 64.675919618, inHumidity: 55.0, inTemp: 82.5, inTempBatteryStatus: 1, pressure: 29.91256, rainRate: 0, usUnits: 1
LOOP:   2020-08-04 15:47:46 PDT (1596581266) altimeter: 29.91256, barometer: 29.91256, dateTime: 1596581266, extraHumid2: 74.0, extraTemp2: 74.4, extraTemp2BatteryStatus: 74.4, pressure: 29.91256, rainRate: 0, usUnits: 1
LOOP:   2020-08-04 15:47:49 PDT (1596581269) altimeter: 29.91256, barometer: 29.91256, dateTime: 1596581269, extraHumidity1: 76.0, extraTemp1: 37.4, extraTemp1BatteryStatus: 37.4, pressure: 29.91256, rainRate: 0, usUnits: 1

Tom Keffer

unread,
Aug 4, 2020, 7:01:36 PM8/4/20
to weewx-user
Your service is binding to archive records, so you're only going to see evapcoolerdelta in the records (marked with "REC"), not the LOOP packets. Let it run longer and see what is in the records.

However, on the basis of the little snipped you posted, I can predict what the problem is: there are no LOOP packets with outTemp. You need both outTemp and extraTemp2 to calculate evapcoolerdelta. So, it never gets calculated.

-tk

Kevin Key

unread,
Aug 4, 2020, 7:15:20 PM8/4/20
to weewx-user
Should I be specifying something other than archive record? Oh, outTemp is there. Here's a larger snippet of the output:


 sudo weewxd
LOOP:   2020-08-04 16:10:20 PDT (1596582620) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582620, pressure: 29.922026, rain: None, rainRate: 0, txBatteryStatus: 0, usUnits: 1, windDir: 338.0, windSpeed: 4.0
LOOP:   2020-08-04 16:10:23 PDT (1596582623) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582623, extraHumid2: 74.0, extraTemp2: 74.6, extraTemp2BatteryStatus: 74.6, pressure: 29.922026, rainRate: 0, usUnits: 1
LOOP:   2020-08-04 16:10:23 PDT (1596582623) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582623, inDewpoint: 64.675919618, inHumidity: 55.0, inTemp: 82.5, inTempBatteryStatus: 1, pressure: 29.922026, rainRate: 0, usUnits: 1
LOOP:   2020-08-04 16:10:24 PDT (1596582624) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582624, dewpoint: 63.1346846273, heatindex: 88.7569178536, outHumidity: 44.0, outTemp: 87.8, pressure: 29.922026, rainRate: 0, txBatteryStatus: 0, usUnits: 1, windchill: 87.8, windSpeed: 5.0
LOOP:   2020-08-04 16:10:33 PDT (1596582633) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582633, extraHumidity1: 76.0, extraTemp1: 37.7, extraTemp1BatteryStatus: 37.7, pressure: 29.922026, rainRate: 0, usUnits: 1
LOOP:   2020-08-04 16:10:39 PDT (1596582639) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582639, extraHumid2: 74.0, extraTemp2: 74.6, extraTemp2BatteryStatus: 74.6, pressure: 29.922026, rainRate: 0, usUnits: 1
LOOP:   2020-08-04 16:10:40 PDT (1596582640) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582640, inDewpoint: 64.675919618, inHumidity: 55.0, inTemp: 82.5, inTempBatteryStatus: 1, pressure: 29.922026, rainRate: 0, usUnits: 1
LOOP:   2020-08-04 16:10:42 PDT (1596582642) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582642, pressure: 29.922026, rain: 0.0, rainRate: 0, txBatteryStatus: 0, usUnits: 1, windDir: 270.0, windSpeed: 5.0
LOOP:   2020-08-04 16:10:50 PDT (1596582650) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582650, extraHumidity1: 76.0, extraTemp1: 37.7, extraTemp1BatteryStatus: 37.7, pressure: 29.922026, rainRate: 0, usUnits: 1
LOOP:   2020-08-04 16:10:56 PDT (1596582656) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582656, inDewpoint: 64.675919618, inHumidity: 55.0, inTemp: 82.5, inTempBatteryStatus: 1, pressure: 29.922026, rainRate: 0, usUnits: 1
LOOP:   2020-08-04 16:10:56 PDT (1596582656) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582656, extraHumid2: 74.0, extraTemp2: 74.6, extraTemp2BatteryStatus: 74.6, pressure: 29.922026, rainRate: 0, usUnits: 1
LOOP:   2020-08-04 16:11:00 PDT (1596582660) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582660, dewpoint: 63.4048579642, heatindex: 89.1890195959, outHumidity: 44.0, outTemp: 88.1, pressure: 29.922026, rainRate: 0, txBatteryStatus: 0, usUnits: 1, windchill: 88.1, windSpeed: 5.0
LOOP:   2020-08-04 16:11:06 PDT (1596582666) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582666, extraHumidity1: 76.0, extraTemp1: 37.7, extraTemp1BatteryStatus: 37.7, pressure: 29.922026, rainRate: 0, usUnits: 1
LOOP:   2020-08-04 16:11:12 PDT (1596582672) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582672, inDewpoint: 64.675919618, inHumidity: 55.0, inTemp: 82.5, inTempBatteryStatus: 1, pressure: 29.922026, rainRate: 0, usUnits: 1
LOOP:   2020-08-04 16:11:13 PDT (1596582673) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582673, extraHumid2: 74.0, extraTemp2: 74.6, extraTemp2BatteryStatus: 74.6, pressure: 29.922026, rainRate: 0, usUnits: 1
LOOP:   2020-08-04 16:11:18 PDT (1596582678) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582678, pressure: 29.922026, rain: 0.0, rainRate: 0, txBatteryStatus: 0, usUnits: 1, windDir: 203.0, windSpeed: 3.0
REC:    2020-08-04 16:11:00 PDT (1596582660) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582660, dewpoint: 63.2697734322, extraHumid2: 74.0, extraHumidity1: 76.0, extraTemp1: 37.7, extraTemp1BatteryStatus: 37.7, extraTemp2: 74.6, extraTemp2BatteryStatus: 74.6, heatindex: 88.9719928077, inDewpoint: 64.675919618, inHumidity: 55.0, inTemp: 82.5, inTempBatteryStatus: 1.0, interval: 1, outHumidity: 44.0, outTemp: 87.95, pressure: 29.922026, rain: 0.0, rainRate: 0, txBatteryStatus: 0.0, usUnits: 1, windchill: 87.95, windDir: 299.713958061, windGust: 5.0, windGustDir: None, windSpeed: 4.75
LOOP:   2020-08-04 16:11:22 PDT (1596582682) altimeter: 29.922026, barometer: 29.922026, dateTime: 1596582682, extraHumidity1: 76.0, extraTemp1: 37.7, extraTemp1BatteryStatus: 37.7, pressure: 29.922026, rainRate: 0, usUnits: 1

Meanwhile, I hardcoded the value 12.34 in and still can't get it to appear in the output.

import weewx
from weewx.engine import StdService

class MyEvapCooler(StdService):
    def __init__(self, engine, config_dict):
        # Initialize superclass
        super(MyEvapCooler, self).__init__(engine, config_dict)

        # Bind to any new archive record events
        self.bind(weewx.NEW_ARCHIVE_RECORD, self.new_archive_record)

    def new_archive_record(self, event):
        try:
                event.record['evapcoolerdelta'] = 12.34
#               evapcoolertempdelta = event.record['outTemp'] - event.record['extraTemp2']

#               if evapcoolertempdelta:
#                       event.record['evapcoolerdelta'] = evapcoolertempdelta

        except KeyError:
            pass


import schemas.wview_extended

schema_with_evapcoolerdelta = {
    'table': schemas.wview_extended.table + [('evapcoolerdelta', 'REAL')],
    'day_summaries' : schemas.wview_extended.day_summaries + [('evapcoolerdelta', 'SCALAR')]

Tom Keffer

unread,
Aug 4, 2020, 7:28:57 PM8/4/20
to weewx-user
Where does your service MyEvapCooler sit in the list of services to be run by the engine? You probably want it at the end of process_services. I don't know what file it's in, but say it's in myevapcooler.py, then you'd want:

        process_services = weewx.engine.StdConvert, weewx.engine.StdCalibrate, weewx.engine.StdQC, weewx.wxservices.StdWXCalculate, user.myevapcooler.MyEvapCooler




Kevin Key

unread,
Aug 4, 2020, 7:35:26 PM8/4/20
to weewx-user
Ohh, I only have user.evapcooler.MyEvapCooler listed in report_services in weewx.config. So it should also be added to process_services? What about archive_services and restful_services?

Tom Keffer

unread,
Aug 4, 2020, 8:01:48 PM8/4/20
to weewx-user
A service should be listed only once.

All services run in order. If it's in report_services, it will be run after the archiving service, StdArchive. Put it at the end of process_services.



Kevin Key

unread,
Aug 4, 2020, 8:02:09 PM8/4/20
to weewx-user
SOLVED: I had to edit weewx.config so that user.evapcooler.MyEvapCooler is referenced in process_services instead of report_services.

Thanks for the help.

Reply all
Reply to author
Forward
0 new messages