From db2038e14a46412d4b0e6788d91b52230cbcd504 Mon Sep 17 00:00:00 2001
From: Glenn 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,12 +6053,30 @@ 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'+
Or that same Python code can be added to our new services file + user/electricity.py, following 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):
+
+ def __init__(self, engine, config_dict):
+
+ # [...]
+
+ self.last_total = total_power
+
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:
@@ -6078,13 +6096,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.
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 user/extensions.py.
+ Or for easier code management, we can choose to include it directly 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).
import weewx.units -weewx.units.obs_group_dict['electricity'] = 'group_energy'- -
Or that same Python code can be added to our new services file - user/electricity.py, following the last +
Add the following to our new services file + user/electricity.py, just after the last import statement:
import weewx from weewx.engine import StdService @@ -6071,13 +6066,13 @@ weewx.units.obs_group_dict['electricity'] = 'group_energy' class AddElectricity(StdService): - def __init__(self, engine, config_dict): + # [...]- # [...] - - self.last_total = total_power - -
Once the observation has been associated with a unit group, +
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@@ -6087,7 +6082,7 @@ class AddElectricity(StdService):
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 @@ -6136,9 +6131,8 @@ 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 user/extensions.py.
- Or for easier code management, we can choose to include it directly into
+ 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).