can not get weewx to process this formula

162 views
Skip to first unread message

Mks Mk

unread,
Oct 17, 2023, 12:48:41 PM10/17/23
to weewx-user
we want to improve the accuracy of our home energy monitor and we added new sensor to read the main line voltage so we got two sensors and the data is logged in weewx database.

    [[sensor_map]]

        ampere = current.***.EfPacket
        linevoltage = payload5.*****.RadioHeadASKPacket


the database have these columns which we created

consumption
ampere
linevoltage
pf


we want to calculate the energy consumption so we added this correction

[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
pf = 0.88
        consumption = ((ampere * linevoltage) /1000) * pf


unfortunately weewx did nothing nor it complained about it. can weewx process such formula?

thanks

Tom Keffer

unread,
Oct 17, 2023, 2:26:38 PM10/17/23
to weewx...@googlegroups.com
The only symbols that can be used in the [[Corrections]] formula are other types in the archive record. So unless 'ampere', 'linevoltage', and 'pf' all appear in the record, the correction will not work.

--
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/26effb7c-ad33-4de8-a9a0-f1390012ec5an%40googlegroups.com.

Mks Mk

unread,
Oct 17, 2023, 6:26:25 PM10/17/23
to weewx-user
Hi Tom

we run weewx directly and found that 'ampere' & 'linevoltage' are in different loop because the data are coming from two different sensors by sdr.py driver.
how we can combine these loops into one so weewx can process this formula, or what can we do to get this calculation done.?

Thank you for your support

gjr80

unread,
Oct 17, 2023, 6:28:55 PM10/17/23
to weewx-user
So what does

consumption = ((ampere * linevoltage) /1000) * 0.88

do?

Gary

Tom Keffer

unread,
Oct 17, 2023, 8:30:56 PM10/17/23
to weewx...@googlegroups.com
Even if all types don't appear in the LOOP packets, they should all be appearing in the archive records. Run weewxd directly from the command line and see exactly what's in the archive record.

I apologize that the error diagnostics for [[Corrections]] are pretty crappy. Still, is there anything in the log?

Your other option is to write a weewx service that caches values.

Mks Mk

unread,
Oct 17, 2023, 8:35:05 PM10/17/23
to weewx-user
Hi Gary

it all started here

we were using fixed value for the incoming grid line to calculate the consumption but it was not accurate enough so we added new sensor to read the grid incoming line voltage.
earlier this formula worked consumption = ampere * 117 / 1000 * 0.88
but  consumption = ampere * linevoltage / 1000 * 0.88 did not work
the linevoltage input comes from different sensor than ampere,  these two reading are generated in different loops, so based on Tom advice the weewx correction will not work
thank you

Mks Mk

unread,
Oct 17, 2023, 9:12:47 PM10/17/23
to weewx-user
from database

dateTime usUnits interval consumption          ampere                linevoltage      pf
1697583060 1            1                        90.84233333          141           0.9
1697583120 1            1                        110.3686667          141           0.9
1697583180 1            1                        77.51766667          140.5           0.9
1697583240 1            1                        101.4843333          141           0.9
1697583300 1            1                        100.0026667          141           0.9
1697583360 1            1                        4.977666667          141           0.9
1697583420 1            1                        4.907666667   142           0.9
1697583480 1            1                        4.927666667   141.5           0.9
1697583540 1            1                        4.886          141.3333333   0.9
1697583600 1            1                        4.867666667          141            0.9
1697583660 1            1                        4.877666667          141            0.9
1697583720 1            1                        78.94533333          141            0.9
1697583780 1            1                        90.26166667          140.6666667     0.9


Tom Keffer

unread,
Oct 17, 2023, 9:42:59 PM10/17/23
to weewx...@googlegroups.com
Just had a thought. 

I assume that weewxd is using software record generation. Check in the log. If so, [[Corrections]] does not apply the corrections to archive records because, in theory, the correction should have already been applied in the LOOP packets. Obviously that's not happening here.

I've created issue #895 to track.

In the meantime, what you can do is create a simple service to do the calculation. It would look something like this (NOT TESTED):

from weewx.engine import StdService

class Power(StdService):

  def __init__(self, engine, config_dict):
    super(Power, self).__init__(engine, config_dict)

    self.bind(weewx.NEW_ARCHIVE_RECORD, self.new_archive_record)

  def new_archive_record(self, event)
    ampere = event.record.get('ampere')
    linevoltage = event.record.get('linevoltage')
    if ampere is not None and linevoltage is not None:
      event.record['consumption'] = ampere * linevoltage
    else:
      event.record['consumption'] = None

This will work provided that linevoltage and ampere do not vary too much over the archive interval. Because you are using short intervals (60 seconds), this is probably not much of a problem.
    






Mks Mk

unread,
Oct 17, 2023, 11:50:58 PM10/17/23
to weewx-user
there is nothing in the log file related to the correction

we tried the service but it failed twice

1st run failed with error:

Oct 18 06:37:20 debian weewx[3413] CRITICAL __main__:     ****    File "/usr/share/weewx/user/myservice.py", line 10
Oct 18 06:37:20 debian weewx[3413] CRITICAL __main__:     ****      def new_archive_record(self, event)
Oct 18 06:37:20 debian weewx[3413] CRITICAL __main__:     ****                                         ^
Oct 18 06:37:20 debian weewx[3413] CRITICAL __main__:     ****  SyntaxError: invalid syntax
Oct 18 06:37:20 debian weewx[3413] CRITICAL __main__:     ****  Exiting.

changed to

def new_archive_record(self, event):

run weewx again but failed with error


Oct 18 06:42:20 debian weewx[3603] CRITICAL __main__:     ****    File "/usr/share/weewx/weewxd", line 148, in main
Oct 18 06:42:20 debian weewx[3603] CRITICAL __main__:     ****      engine = weewx.engine.StdEngine(config_dict)
Oct 18 06:42:20 debian weewx[3603] CRITICAL __main__:     ****    File "/usr/share/weewx/weewx/engine.py", line 93, in __init__
Oct 18 06:42:20 debian weewx[3603] CRITICAL __main__:     ****      self.loadServices(config_dict)
Oct 18 06:42:20 debian weewx[3603] CRITICAL __main__:     ****    File "/usr/share/weewx/weewx/engine.py", line 161, in loadServices
Oct 18 06:42:20 debian weewx[3603] CRITICAL __main__:     ****      obj = weeutil.weeutil.get_object(svc)(self, config_dict)
Oct 18 06:42:20 debian weewx[3603] CRITICAL __main__:     ****    File "/usr/share/weewx/user/myservice.py", line 8, in __init__
Oct 18 06:42:20 debian weewx[3603] CRITICAL __main__:     ****      self.bind(weewx.NEW_ARCHIVE_RECORD, self.new_archive_record)
Oct 18 06:42:20 debian weewx[3603] CRITICAL __main__:     ****  NameError: name 'weewx' is not defined
Oct 18 06:42:20 debian weewx[3603] CRITICAL __main__:     ****  Exiting.

Mks Mk

unread,
Oct 18, 2023, 12:01:27 AM10/18/23
to weewx-user

added import weewx to the top of file
it worked

Mks Mk

unread,
Oct 18, 2023, 12:17:44 AM10/18/23
to weewx-user
Thank you Tom
the service file is doing exactly what we needed.

GOD bless you

Tom Keffer

unread,
Dec 5, 2023, 5:55:53 PM12/5/23
to weewx-user
Final note on this: Commit a978796 allows one to apply corrections to only archive records, even if they came from software. So, you could do

 [[Corrections]]
pf = 0.88
        consumption = ((ampere * linevoltage) /1000) * pf, archive

This is not precisely what you want, because it is applying the expression to the product of the average amperage times the average linevoltage, but it would get you close.

-tk
Reply all
Reply to author
Forward
0 new messages