How to modify the units written to the database

76 views
Skip to first unread message

Alan

unread,
Jun 28, 2025, 9:28:49 PM6/28/25
to weewx-user
I there anyway you can modify the units the data is written with to the weewx archive database by modifying weewx.conf?

 I am not talking about the units in the reports.

For example, in New Zealand we use metric but want the rain in mm (not cm) and the wind in km_per_hour.

The only way I have found of doing this is to edit the METRIC dictionary in units.py.

This works fine but a version update in the linux repo could overwrite it.

(reason: I have other applications using this data).

Thanks
Alan

Tom Keffer

unread,
Jun 28, 2025, 9:34:32 PM6/28/25
to weewx...@googlegroups.com
See option target_unit.

--
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 visit https://groups.google.com/d/msgid/weewx-user/5ea87391-6ea4-45c7-be7c-53ef2049c5f4n%40googlegroups.com.

Graham Eddy

unread,
Jun 28, 2025, 10:04:50 PM6/28/25
to WeeWX User
as tom indicates, the actual data in the database is in some units we do not need to care about, all we care about is how the data is presented.
rather than update weewx source code (units.py), just override it in your ~weewx/$station/bin/user/extensions.py:

weewx.units.MetricUnits['group_rain']           = 'mm'

weewx.units.MetricUnits['group_rainrate']       = 'mm_per_hour'

⊣GE⊢

Alan

unread,
Jun 29, 2025, 12:06:14 AM6/29/25
to weewx-user
weewx.units.MetricUnits['group_length']         = 'mm'

weewx.units.MetricUnits['group_rain']           = 'mm'
weewx.units.MetricUnits['group_rainrate']       = 'mm_per_hour'
weewx.units.MetricUnits['group_pressure']       = 'hPa'
weewx.units.MetricUnits['group_pressurerate']   = 'hPa_per_hour'

in extensions.py produces the error:

un 29 15:59:04 kakapo weewxd[175095]: INFO __main__: Initializing weewxd version 5.1.0
Jun 29 15:59:04 kakapo weewxd[175095]: INFO __main__: Command line: /usr/share/weewx/weewxd.py /etc/weewx/weewx.conf
Jun 29 15:59:04 kakapo weewxd[175095]:  File "/usr/share/weewx/weewxd.py", line 226, in <module>
Jun 29 15:59:04 kakapo weewxd[175095]:  File "/usr/share/weewx/weewxd.py", line 76, in main
Jun 29 15:59:04 kakapo weewxd[175095]:  File "/usr/share/weewx/weeutil/startup.py", line 111, in start_app
Jun 29 15:59:04 kakapo weewxd[175095]:    weewx_root, user_module = initialize(config_dict)
Jun 29 15:59:04 kakapo weewxd[175095]:  File "/usr/share/weewx/weeutil/startup.py", line 76, in initialize
Jun 29 15:59:04 kakapo weewxd[175095]:  File "/etc/weewx/bin/user/extensions.py", line 23, in <module>
Jun 29 15:59:04 kakapo weewxd[175095]:    weewx.units.MetricUnits['group_length']         = 'mm'
Jun 29 15:59:04 kakapo weewxd[175095]: NameError: name 'weewx' is not defined
Jun 29 15:59:04 kakapo systemd[1]: weewx.service: Main process exited, code=exited, status=1/FAILURE
Jun 29 15:59:04 kakapo systemd[1]: weewx.service: Failed with result 'exit-code'.

Do I need to include some headers?

Thanks
Alan

Graham Eddy

unread,
Jun 29, 2025, 12:34:25 AM6/29/25
to WeeWX User

Tom Keffer

unread,
Jun 29, 2025, 7:30:40 AM6/29/25
to weewx...@googlegroups.com
On Sat, Jun 28, 2025 at 7:04 PM Graham Eddy <g...@geddy.au> wrote:
as tom indicates, the actual data in the database is in some units we do not need to care about, all we care about is how the data is presented.
rather than update weewx source code (units.py), just override it in your ~weewx/$station/bin/user/extensions.py:

weewx.units.MetricUnits['group_rain']           = 'mm'

weewx.units.MetricUnits['group_rainrate']       = 'mm_per_hour'


But in this case, we do care. Alan is trying to change the units in the database, not the display. Your approach would only affect the reports.

A bit of background. WeeWX stores data using a "unit system": a collection of observation types and the unit they are in. The choices are US, METRIC, and METRICWX. METRIC is cm and km/h, METRICWX is mm and m/s. One cannot pick and choose the unit used for individual observation types. See the section The database in the manual for details.

If I understand you correctly, you want mm for rain, and km/h for wind. Unfortunately, none of the three systems does that. It would require an introduction of a fourth unit system --- a major project. 

Sorry.



Reply all
Reply to author
Forward
0 new messages