Skip to content

Extending WeeWX

Scope: the three doors into the system — installing an extension package, adding a service to the engine's pipeline, and teaching it a new kind of observation with the XTypes system — each one walked through for real in the lab, including the two mistakes the walk made.

WeeWX is built to be extended, and the evidence is in your station directory: a bin/user/ folder waiting for your code, an examples/ folder of sample services and a sample extension shipped with every station, and an [Engine] roster (chapter 4) that names services as a list — because a list can be added to.

Door one: an extension package

An extension is a bundle — a skin, a service, a driver, or several at once — with an installer, managed by weectl extension. The lab installed the sample that ships in the station's own examples/ folder, a minimal skin called Basic:

$ weectl extension install examples/basic --config=weewx.conf --yes
Pick a code [en]: 
Saving installer file to .../station/bin/user/installer/basic
Saved copy of configuration as .../station/weewx.conf.20261105085831
Finished installing extension basic from examples/basic

Check: what that one command did, in order:

  • asked one question --yes could not answer for it — the skin's display language (an installer-specific prompt; the default, English, was taken). Expect installers to have their own small questions; --yes covers the tool's confirmations, not theirs.
  • saved the installer under bin/user/installer/, so weectl extension remove basic can undo the whole thing later;
  • backed up weewx.conf to a timestamped copy before editing it;
  • copied the skin into skins/Basic and added a [[BasicReport]] stanza to the configuration, enabled.

Check: the result, from weectl extension list and the next report cycle:

Extension Name    Version   Description
basic             0.5       Very basic skin for WeeWX.

weewxd: INFO weewx.cheetahgenerator: Generated 1 files for report BasicReport in 0.07 seconds
weewxd: INFO weewx.imagegenerator: Generated 10 images for report BasicReport in 0.10 seconds

The station now publishes a second, plainer website into public_html/basic/ alongside Seasons — installed, listed, generated, and removable, which is the whole lifecycle the extension system promises. Community extensions (the Ecowitt gateway driver of chapter 5 is one) install by exactly this route, from a URL or a downloaded file.

Door two: a service in the pipeline

A service is a Python class the engine loads at startup and feeds events — LOOP packets, archive records, report runs, shutdown. Your own services live in bin/user/ and join the roster by name: chapter 4's process_services and its siblings are the enlistment papers. The samples in examples/ are the project's own tutoring in the shape of one — an alarm that reacts to a reading, a low-battery watcher, a process monitor — each a small file whose docstring tells you where to copy it and which roster line to extend.

Door three: a new observation, through XTypes

The deepest door is the one the lab proved end to end. WeeWX's XTypes system lets code answer questions the database does not store: a value calculated on demand, from the record at hand, usable anywhere a stored observation is — in reports, in aggregates. The pipeline already uses it (the pressure and rain-rate services in the xtype_services roster are XTypes), and the station's examples include one that computes the vapour pressure of water from the outside temperature, a quantity no station in the lab measures.

Installing it was two steps, both straight from the file's own instructions:

$ cp examples/vaporpressure.py bin/user/vaporpressure.py

and adding user.vaporpressure.VaporPressureService to the xtype_services line in [Engine]. The service's whole job at startup is to register a calculator for a new observation name, vapor_p; from then on, any template may ask for $current.vapor_p and receive a value computed from the current record's outTemp with proper units.

The proof page, and the mistake it made first

To see the number, the lab built a minimal skin — one template, one report stanza — named VaporTest. Its first version taught a lesson worth more than the number: the template was called index.html.tmpl, and CheetahGenerator names each output file after its template, so the test page wrote itself to public_html/index.html — over the Seasons front page, which the next cycle's VaporTest run kept cheerfully replacing. Nothing was broken and nothing complained; two reports were writing one file, and the later one won. The fix was a rename, after which the pages coexist:

Check: public_html/vapor.html from the repaired skin, next to a Seasons index.html restored to itself:

<p>Outside temperature now: 32.7°F</p>
<p>Vapor pressure now (from the custom vapor_p type): 0.200 inHg</p>

And the number checks out by hand: the sample's "simple" algorithm is exp(20.386 − 5132/T) mmHg with T in kelvin; at 32.7 °F (273.9 K) that is exp(20.386 − 18.74) ≈ 5.2 mmHg ≈ 0.20 inHg. A calculation you can verify with a pocket calculator is the right size for a first extension.

The general rules the lab's scars reduce to: name templates for the file you want; give every report its own output name or directory; restart the engine after touching the roster or bin/user/ (both are read at startup); and read the log after any extension change, because a service that fails to load fails there, in words, before it fails anywhere else.