Git Product home page Git Product logo

weewx-brultech's Introduction

weewx-brultech

Extension to the WeeWX weather system for collecting data and generating reports for the Brultech GEM energy monitors.

Overview

This is a extension for the WeeWX weather system for the Brultech GEM energy monitor. While an energy monitor is very different from a weather station, WeeWX is a very flexible system and has no trouble running the driver. The extension includes three parts:

  • A driver for the GEM energy monitor. The driver is designed to poll your energy monitor at regular intervals, typically every 10-15 seconds, then pass the data on to the rest of the WeeWX system.

  • A database schema designed for the monitor. Because the types used by an energy monitor are so radically different from a weather station, this extension includes a specialty schema (called gem_schema), specifically designed for the Brultech monitors. It will be used to initialize a separate database from the conventional WeeWX weather database, allowing both to be run simultaneously. By default, it will include space for 32 channels.

  • A WeeWX skin, called SeasonsPower, designed to display current, week, month, and year energy use. It also includes monthly energy summaries. It can easily be customized by following the directions in the WeeWX Customization Guide.

What follows are directions for installing the extension. It consists of five parts:

  1. Configuring your Brultech monitor
  2. Installing WeeWX
  3. Installing the extension, either by using the WeeWX installer, or manually.
  4. Select database options
  5. Start up WeeWX

Configuring your Brultech device

The Brultech energy monitors come with a bewildering array of modes and options. To keep things simple, this driver makes two assumptions:

  • The device will always be in server mode.
  • The device driver will always poll the device.

This makes it pretty easy to configure the device:

  1. Set the GEM to "server mode". Using a browser, connect to your GEM (http://192.168.1.104, in my case) and go to the "Application Settings" page. Set it to server mode, using port 8000:

    Application settings

    Click Apply.

  2. Then click on the "Device Management" tab, and click the "Restart" button under Restart Module.

    Restart Module

The monitor will reboot and be ready to receive commands from the driver. That's it for the monitor.

Next step is to install WeeWX.

Install WeeWX

It is strongly recommended that you use the "setup.py" method for installing WeeWX. All of the instructions that follow assume this.

Follow the instructions in the setup.py install guide and install WeeWX. When asked, specify that the Simulator driver be used. When you're done, WeeWX will be installed in /home/weewx.

Deactivate weather skins

By default, when WeeWX is installed, it installs the Seasons skin and activates it. You will need to deactivate it. In the WeeWX configuration file weewx.conf, generally located in /home/weewx/weewx.conf, set option enable to false for the Seasons report. When you're done, it will look like this:

    ...
    [[SeasonsReport]]
        # The SeasonsReport uses the 'Seasons' skin, which contains the
        # images, templates and plots for the report.
        skin = Seasons
        enable = false
        lang = en
        unit_system = us

Next step is to install the weewx-brultech extension itself, either by using the WeeWX installer, or manually.

Install the extension by using the WeeWX installer

This section describes how to install weewx-brultech using the WeeWX installer.

Download and install

Download the weewx-brultech package and install it using the WeeWX installer:

cd /home/weewx
wget https://github.com/tkeffer/weewx-brultech/archive/master.zip
./bin/wee_extension --install=master.zip

Configure

When you're done with the installation, your WeeWX configuration will be set up to use the Brultech driver. However, you still have to configure the driver. Do this by using the wee_config utility with the --reconfigure option:

./bin/wee_config --reconfigure

It will give you the opportunity to change various settings. Eventually, it will ask about options for the Brultech driver:

Specify the IP address (e.g., 192.168.0.10) or hostname of the Brultech monitor.
host [192.168.1.104]: 192.168.0.7
Specify the port
port [8000]: 
Saved backup to /home/weewx/weewx.conf.20211025164234

In this example, we have changed the host from 192.168.1.104 to 192.168.0.7, but accepted the default port (8000).

Installing the extension manually

This section describes how to manually configure WeeWX to use this extension.

Download and unpack

Download the weewx-brultech package and unpack it

cd /home/weewx
wget https://github.com/tkeffer/weewx-brultech/archive/master.zip
tar xvf master.zip

Copy files

Put the files brultech.py and gem_schema.py in the user subdirectory. Typically,

cd /home/weewx/weewx-brultech-master
cp bin/user/brultech.py /home/weewx/bin/user
cp bin/user/gem_schema.py /home/weewx/bin/user

Copy the StandardPower skin over:

cp -r skins/StandardPower /home/weewx/skins

Configure weewx.conf

This section is about manually configuring the configuration file, weewx.conf, usually found in /home/weewx/weewx.conf.

  1. Add section [Brultech]

    Insert a new stanza [Brultech] into your weewx.conf file that looks like this:

    [Brultech]
    
        # See README.md for instructions on how to configure the Brultech devices!!
    
        # Power is computed as the difference between energy records. How old a 
        # record can be and still be used for this calculation:
        stale = 1800
    
        # How often to poll the device for data
        poll_interval = 5
    
        # Max number of channels to emit. Limit is set by hardware (48 for GEM).
        max_channels = 32
    
        # The type of packet to use. Possible choices are GEMBin48NetTime, GEMBin48Net,
        # or GEMAscii:
        packet_type = GEMBin48NetTime
    
        # Max number of times to try an I/O operation before declaring an error
        max_tries = 3
    
        driver = user.brultech
    
        # The type of connection to use. It should match a section below. 
        # Right now, only 'socket' is supported.
        connection = socket
    
        # The following is for socket connections: 
        [[socket]]
            host = 192.168.1.104
            port = 8000
            timeout = 20
            # After sending a command, how long to wait before looking for a response    
            send_delay = 0.2
    
        [[sensor_map]]

    Be sure to set options host and port to their proper values for your network configuration.

  2. Set station type

    Tell WeeWX to use the Brultech device driver by setting station_type, under section [Station], to Brultech:

    [Station]
    
       ...
    
       # Set to type of station hardware. There must be a corresponding stanza
       # in this file with a 'driver' parameter indicating the driver to be used.
       station_type = Brultech
  3. Configure new binding

    Under stanza [DataBindings], add a new database binding bt_binding for the Brultech device. It should look like this:

    [DataBindings]
    
     ...
    
        [[bt_binding]]
            # The database must match one of the sections in [Databases].
            database = bt_sqlite
            # The name of the table within the database
            table_name = archive
            # The manager handles aggregation of data for historical summaries
            manager = weewx.manager.DaySummaryManager
            # The schema defines the structure of the database.
            # It is *only* used when the database is created.
            schema = user.gem_schema.schema
  4. Configure new database

    Under stanza [Databases], add a new database bt_sqlite:

    [Databases]
    
    ...
    
        [[bt_sqlite]]
            database_name = weepwr.sdb
            database_type = SQLite  
  5. Use the new binding

    Under stanza [StdArchive], set the option data_binding to bt_binding. This will cause new data to be archived in the database dedicated to Brultech data.

    [StdArchive]
    
        ...
    
        data_binding = bt_binding         
  6. Configure and activate the SeasonsPower skin

    Add a subsection to [StdReport] for the SeasonsPower skin, and activate it by setting enable to True:

    [StdReport]
     
        ...
     
        [[PowerReport]]
            skin = SeasonsPower
            enable = True
            data_binding = bt_binding
            [[[Units]]]
                [[[[Groups]]]]
                    group_energy2 = kilowatt_hour

    Incidentally, while you're in there, make sure that any "weather" skins have been deactivated --- they won't work with the data from the energy monitor!

  7. Make sure the configuration service runs

    Because of its many specialized types, the Brultech driver requires setting up some custom configurations. This is done by the service brultech.BrultechService. You must add it to the list of services to run by adding it to data_services. So, now your [Engine] section looks something like this:

    [Engine]
    
       [[Services]]
           # This section specifies the services that should be run. They are
           # grouped by type, and the order of services within each group
           # determines the order in which the services will be run.
           prep_services = weewx.engine.StdTimeSynch,
           data_services = user.brultech.BrultechService
           process_services = weewx.engine.StdConvert, weewx.engine.StdCalibrate, weewx.engine.StdQC, weewx.wxservices.StdWXCalculate
           ...

Select database options

The default schema works well for most applications. However, you may want to tune it for special cases. Take a look in the schema's file, usually located in /home/weewx/bin/user/gem_schema.py, and you will see a number of options. Here are their meanings

Option Default Meaning
MAX_CURRENT_CHANNELS 32 How many current channels to include in the schema. Max for GEM is 32.
MAX_TEMPERATURE_CHANNELS 8 How many temperature channels to include in the schema. Max for GEM is 8.
MAX_PULSE_CHANNELS 4 How many pulse (counter) channels to include. Max for GEM is 4.
INCLUDE_ACCUMULATED_ABSOLUTE True Store accumulated (since device reset) absolute energy.
INCLUDE_ACCUMULATED_POLARIZED False Store accumulated (since device reset) polarized energy.
INCLUDE_DELTA_ABSOLUTE True Store delta absolute energy.
INCLUDE_DELTA_POLARIZED False Store delta polarized energy.
INCLUDE_POWER_ABSOLUTE False Store the average absolute power consumed during archive period.
INCLUDE_POWER_POLARIZED False Store the average polarized power consumed during archive period.

Starting WeeWX

You're done installing and configuring the extension. You can start WeeWX either directly from the command line, or start it as a daemon. Instructions are in the WeeWX User's Guide, in the section Running WeeWX.

Observation types

The driver can emit the following types:

Type Python type Meaning
dateTime int Timestamp in unix epoch time
serial str The unit serial number
unit_id int Unit identification number
secs int Continuous device uptime
chNN_count int Pulse count in channel NN
chNN_volt float Voltage in channel NN
chNN_temperature float Temperature in channel NN
chNN_amp float Current (amperage) in channel NN
chNN_a_power float Average absolute power over an archive period (see below)
chNN_p_power float Average polarized power over an archive period (see below)
chNN_a_energy2 float Total accumulated absolute energy (see below)
chNN_p_energy2 float Total accumulated polarized energy (see below)
chNN_ad_energy2 float Absolute energy over an archive period (see below)
chNN_pd_energy2 float Polarized energy over an archive period (see below)

where NN is the channel number. NB: the channel number uses no leading zero. For example, it is ch2_volt, NOT ch02_volt.

So, for example:

  • ch14_p_energy2 would be the accumulated polarized energy in channel 14.
  • ch2_a_energy2 would be the accumulated absolute energy in channel 2.
  • ch2_ad_energy2 would be the absolute energy used during the archive interval in channel 2.

Accumulated vs delta energy.

Accumulated

The Brultech energy monitors emit accumulated energy in units of watt-seconds. Accumulated energy is the amount of energy that has flowed through the channel since the monitor was reset. Because a watt-second is a small amount of energy, and it may be years since your monitor was reset, this can often be a very large number. Fortunately, the Brultech monitors reserve five bytes for this value, so it can count up to over 300,000 kWh. A typical home might use 10,000 kWh per year, so the value is unlikely to rollover for years.

Delta

WeeWX uses accumulated energy to calculate delta energy, which is the amount of energy that flowed through the channel in an archive interval (typically 5 minutes). It is the difference in accumulated energy between the beginning and the end of the interval.

Calculations

To calculate the amount of power used over, say, a month, you can either take the difference in accumulated energy, or you can sum the smaller delta energies for the month. Here's an example using channel 8:

Strategy Tag
Calculate using accumulated energy $month.ch8_a_energy2.diff
Calculate using delta energy $month.ch8_ad_energy2.sum

Which to use?

By default, both values are stored in the database. The skins that come with weewx-brultech use accumulated energy.

They each have their advantages.

Advantage accumulated energy

The calculation is very efficient: only two numbers need be looked up in the database. By contrast, using delta energies requires summing all the records.

If the computer running WeeWX goes down during the time period, but the energy monitor stays up, it won't affect the final result. This is because you only need the first and last value for the time period to calculate the total energy used.

Of course, if the monitor goes down, you will miss energy used during that time period no matter which method you use.

Advantage delta energy

If you have technical problems with your monitor and must do a system reset, the counters will go to zero. This means that if you try to calculate total energy used over a period that includes the reset, and you do the calculation by calculating differences in accumulated energy, you will get a large negative number. By contrast, if you sum the delta energies, you will get the correct answer.

The same thing can happen if the battery in your GEM fails. It is responsible for maintaining the count should the power fail.

weewx-brultech's People

Contributors

tkeffer avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

matthewwall

weewx-brultech's Issues

Handling old previous records

This is more a question than a real "issue": how should one handle large gaps in the incoming data? Say, the system was "down" for a day and then starts sending again.

It looks as if the code e.g. for power just uses the last "old" record and averages over the (long) time period. On the other hand there is a parameter "stale" that I do not see used in the code. Was there once a plan to handle "old" data differently and was this given up later?

weewx dies when running the brultech driver

looks like some assumptions in brultech.py might not consider all of the cases.

Dec 24 12:05:22 pitest weewx-gem[6912] CRITICAL __main__: Caught unrecoverable exception:
Dec 24 12:05:22 pitest weewx-gem[6912] CRITICAL __main__:     ****  integer division or modulo by zero
Dec 24 12:05:22 pitest weewx-gem[6912] CRITICAL __main__:     ****  Traceback (most recent call last):
Dec 24 12:05:22 pitest weewx-gem[6912] CRITICAL __main__:     ****    File "/opt/weewx/bin/weewxd", line 153, in main
Dec 24 12:05:22 pitest weewx-gem[6912] CRITICAL __main__:     ****      engine.run()
Dec 24 12:05:22 pitest weewx-gem[6912] CRITICAL __main__:     ****    File "/opt/weewx/bin/weewx/engine.py", line 210, in run
Dec 24 12:05:22 pitest weewx-gem[6912] CRITICAL __main__:     ****      self.dispatchEvent(weewx.Event(weewx.NEW_LOOP_PACKET, packet=packet))
Dec 24 12:05:22 pitest weewx-gem[6912] CRITICAL __main__:     ****    File "/opt/weewx/bin/weewx/engine.py", line 245, in dispatchEvent
Dec 24 12:05:22 pitest weewx-gem[6912] CRITICAL __main__:     ****      callback(event)
Dec 24 12:05:22 pitest weewx-gem[6912] CRITICAL __main__:     ****    File "/opt/weewx/bin/user/brultech.py", line 911, in new_loop_packet
Dec 24 12:05:22 pitest weewx-gem[6912] CRITICAL __main__:     ****      self.bt_extends.add_power_to_packet(event.packet)
Dec 24 12:05:22 pitest weewx-gem[6912] CRITICAL __main__:     ****    File "/opt/weewx/bin/user/brultech.py", line 781, in add_power_to_packet
Dec 24 12:05:22 pitest weewx-gem[6912] CRITICAL __main__:     ****      deriv = self.derivatives[obs_type].add_record(packet)
Dec 24 12:05:22 pitest weewx-gem[6912] CRITICAL __main__:     ****    File "/opt/weewx/bin/weeutil/timediff.py", line 44, in add_record
Dec 24 12:05:22 pitest weewx-gem[6912] CRITICAL __main__:     ****      derivative = (record[self.obs_type] - self.old_value) / (record['dateTime'] - self.old_timestamp)
Dec 24 12:05:22 pitest weewx-gem[6912] CRITICAL __main__:     ****  ZeroDivisionError: integer division or modulo by zero
Dec 24 12:05:22 pitest weewx-gem[6912] CRITICAL __main__:     ****  Exiting.

this is weewx development branch as of 23dec2021 and brultech driver as of a few days ago.

here is the log from startup:

Dec 24 22:20:59 pitest weewx-gem[10386] INFO __main__: Initializing weewx version 4.6.0b7
Dec 24 22:20:59 pitest weewx-gem[10386] INFO __main__: Using Python 2.7.16 (default, Oct 10 2019, 22:02:15) #012[GCC 8.3.0]
Dec 24 22:20:59 pitest weewx-gem[10386] INFO __main__: Platform Linux-5.10.63-v7+-armv7l-with-debian-10.11
Dec 24 22:20:59 pitest weewx-gem[10386] INFO __main__: Locale is 'en_GB.UTF-8'
Dec 24 22:20:59 pitest weewx-gem[10386] INFO __main__: Using configuration file /etc/weewx/gem.conf
Dec 24 22:20:59 pitest weewx-gem[10386] INFO __main__: Debug is 0
Dec 24 22:20:59 pitest weewx-gem[10386] INFO __main__: PID file is /var/run/weewx-gem.pid
Dec 24 22:20:59 pitest weewx-gem[10390] INFO weewx.engine: Loading station type Brultech (user.brultech)
Dec 24 22:21:00 pitest weewx-gem[10390] INFO weewx.engine: StdConvert target unit is 0x1
Dec 24 22:21:00 pitest weewx-gem[10390] INFO weewx.wxservices: StdWXCalculate will use data binding bt_binding
Dec 24 22:21:00 pitest weewx-gem[10390] INFO weewx.engine: Archive will use data binding bt_binding
Dec 24 22:21:00 pitest weewx-gem[10390] INFO weewx.engine: Record generation will be attempted in 'hardware'
Dec 24 22:21:00 pitest weewx-gem[10390] INFO weewx.engine: Using archive interval of 300 seconds (specified in weewx configuration)
Dec 24 22:21:00 pitest weewx-gem[10390] INFO weewx.restx: StationRegistry: Registration not requested.
Dec 24 22:21:00 pitest weewx-gem[10390] INFO user.influx: service version is 0.16
Dec 24 22:21:00 pitest weewx-gem[10390] INFO user.influx: database: data
Dec 24 22:21:00 pitest weewx-gem[10390] INFO user.influx: destination: http://192.168.76.60/influx
Dec 24 22:21:00 pitest weewx-gem[10390] INFO user.influx: line_format: multi-line-dotted
Dec 24 22:21:00 pitest weewx-gem[10390] INFO user.influx: measurement: pitest.gem
Dec 24 22:21:00 pitest weewx-gem[10390] INFO user.influx: tags: host=pitest,driver=gem
Dec 24 22:21:00 pitest weewx-gem[10390] INFO user.influx: binding: loop,archive
Dec 24 22:21:00 pitest weewx-gem[10390] INFO user.influx: Data will be uploaded to http://192.168.76.60/influx
Dec 24 22:21:00 pitest weewx-gem[10390] INFO weewx.engine: 'pyephem' not detected, extended almanac data is not available
Dec 24 22:21:00 pitest weewx-gem[10390] INFO __main__: Starting up weewx version 4.6.0b7
Dec 24 22:21:00 pitest weewx-gem[10390] INFO weewx.engine: Clock error is 1.06 seconds (positive is fast)
Dec 24 22:21:00 pitest weewx-gem[10390] INFO weewx.engine: Using binding 'bt_binding' to database 'gem.sdb'
Dec 24 22:21:00 pitest weewx-gem[10390] INFO weewx.manager: Starting backfill of daily summaries
Dec 24 22:21:00 pitest weewx-gem[10390] INFO weewx.manager: Daily summaries up to date
Dec 24 22:21:00 pitest weewx-gem[10390] INFO weewx.engine: Starting main packet loop.

let me know if you need debug

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.