diff --git a/docs/customizing.htm b/docs/customizing.htm index ebd8e9e1..c46212a9 100644 --- a/docs/customizing.htm +++ b/docs/customizing.htm @@ -1241,7 +1241,6 @@ $month.outTemp.max Example Meaning - $hour($hours_ago=h) @@ -1273,6 +1272,7 @@ $month.outTemp.max $year($years_ago=1).outTemp.max The maximum temperature last year. +

Unit conversion options

@@ -6053,13 +6053,26 @@ mysql> RENAME TABLE weewx_new.archive TO weewx.archive;group_energy (which already exists), so it can enjoy the labels and formats already provided for this group. This is done by extending the dictionary weewx.units.obs_group_dict, typically by - adding Python code to the file user/extensions.py: -

-
import weewx.units
-weewx.units.obs_group_dict['electricity'] = 'group_energy'
+ class='code'>weewx.units.obs_group_dict.

-

Once the observation has been associated with a unit group, +

Add the following to our new services file + user/electricity.py, just after the last + import statement:

+
import weewx
+from weewx.engine import StdService
+
+import weewx.units
+weewx.units.obs_group_dict['electricity'] = 'group_energy'
+
+class AddElectricity(StdService):
+
+   # [...]
+ +

When our new service gets loaded by the WeeWX engine, these few lines + will get run. They tell WeeWX that our new observation type, + electricity, is part of the unit group + group_energy. + Once the observation has been associated with a unit group, the unit labels and other tag syntax will work for that observation. So, now a tag like:

$month.electricity.sum
@@ -6069,7 +6082,7 @@ weewx.units.obs_group_dict['electricity'] = 'group_energy'

Creating a new unit group

That was an easy one, because there was already an existing - group, group_amp, that covered our new + group, group_energy, that covered our new observation type. But, what if we are measuring something entirely new, like force with time? There is nothing in the existing system of units that covers things like newtons or pounds. We will have to @@ -6078,13 +6091,14 @@ weewx.units.obs_group_dict['electricity'] = 'group_energy'

We assume we have a new observation type, force, - that we are measuing over time. We will create a new unit group, + that we are measuring over time, for a service named + user/rocket.py. We will create a new unit group, group_force, and new units, newton and pound. Our new observation, force, will belong to group_force, and will be measured in units of newton or pound. + class='code'>pound.

  1. As before, we start by specifying what group our new @@ -6114,6 +6128,14 @@ weewx.units.conversionDict['pound'] = {'newton': lambda x : x * 4.44822}
+

As with the previous example of group_energy, + the last step is to extend the + weewx.units.obs_group_dict dictionary so that these new units can + be used by our service. We do this by adding the Python code from + steps 1 - 4 above into + our new services file user/rocket.py, at the + head of that file and just after the last import statement (as in the + previous example).

Use the new types