weectl database reconfigure

104 views
Skip to first unread message

Werner Krenn

unread,
Nov 3, 2025, 1:05:06 PM (3 days ago) Nov 3
to weewx-user
WeeWx 5.2.0:
I'm trying to convert a database from "US" to "METRICWX", but I'm getting this error message:

weectl database reconfigure --config=/etc/weewx/weewx8.conf --dry-run -y

weectl database reconfigure --config=/etc/weewx/weewx8.conf --dry-run -y
Using configuration file /etc/weewx/weewx8.conf
This is a dry run. Nothing will actually be done.
Copying database 'weewx_ecowitt_http_ws6210.sdb' to 'weewx_ecowitt_http_ws6210.sdb_new'
Units will be converted from the 'US' system to the 'METRICWX' system.
Traceback (most recent call last):
  File "/usr/share/weewx/weectl.py", line 75, in <module>
    main()
  File "/usr/share/weewx/weectl.py", line 67, in main
    namespace.func(namespace)
  File "/usr/share/weewx/weectllib/__init__.py", line 90, in dispatch
    namespace.action_func(config_dict, namespace)
  File "/usr/share/weewx/weectllib/database_cmd.py", line 371, in reconfigure_database
    weectllib.database_actions.reconfigure_database(config_dict,
  File "/usr/share/weewx/weectllib/database_actions.py", line 295, in reconfigure_database
    weewx.manager.reconfig(manager_dict['database_dict'],
  File "/usr/share/weewx/weewx/manager.py", line 715, in reconfig
    record_generator = weewx.units.GenWithConvert(old_archive.genBatchRecords(),
                       ^^^^^
UnboundLocalError: cannot access local variable 'weewx' where it is not associated with a value

How can I fix this error?

Tom Keffer

unread,
Nov 3, 2025, 4:18:18 PM (3 days ago) Nov 3
to weewx...@googlegroups.com
I was able to reproduce this. It's an interesting bug. If a schema is named, then the import of "weewx.schemas" is never done, so the package "weewx" will not be defined. Replace your copy of /usr/share/weewx/weewx/manager.py with the attached version and give it another try. 

-tk



--
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/871567a8-e4c3-450a-b398-626657751352n%40googlegroups.com.
manager.py

Werner Krenn

unread,
Nov 4, 2025, 12:16:30 PM (2 days ago) Nov 4
to weewx-user
Tom
 thanks, it worked.

I have another question:

I'm using additional fields, e.g., "co2_Temp" with the group "group_temperature". To ensure this field is also converted, I'm adding these fields and their group assignments to "units.py".

Could this assignment also be entered into "extensions.py" so that the conversion is performed?

Werner

Tom Keffer

unread,
Nov 4, 2025, 12:54:08 PM (2 days ago) Nov 4
to weewx...@googlegroups.com
If you added the additional fields in extensions.py you should be OK. That file is imported before starting processing.

Graham Eddy

unread,
Nov 4, 2025, 6:58:32 PM (2 days ago) Nov 4
to WeeWX User
stregthening tom’s words, it should be added to extensions.py rather than in addition to units.py.
units.py is part of weewx’s code base and subject to updates. extensions.py is the hook to allow custom changes to weewx code base and is not changed by weewx updates.
⊣GE⊢

Werner Krenn

unread,
Nov 5, 2025, 12:21:04 PM (19 hours ago) Nov 5
to weewx-user
That's why I asked the question.

from units.py
# This data structure maps observation types to a "unit group"
# We start with a standard object group dictionary, but users are
# free to extend it:
obs_group_dict = ListOfDicts({

Then perhaps it would be advisable to write in units.py that it makes more sense to enter additional "observation types" in "extensions.py".

vince

unread,
Nov 5, 2025, 1:11:14 PM (18 hours ago) Nov 5
to weewx-user
Perhaps you might suggest a wording change to the commentary in units.py that works for you as a Github issue ????

I could not find anything in the FAQ nor Customization Guide that suggests using extensions.py as a best practice.  There are some examples in there, but I could not find any suggestion of what 'typically' would be a recommended method.

Graham Eddy

unread,
Nov 5, 2025, 11:29:50 PM (8 hours ago) Nov 5
to WeeWX User
as an example, i have in a file that extensions.py imports:

""" units common to all stations, including fixes to weewx base

common_units.py Graham Eddy <g...@geddy.au> 2025-06-20

"""

 

import weewx.units

 

#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

# gaps in weewx base

#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

 

# unit -> label

weewx.units.default_unit_label_dict['kilowatt'] = u' kW'

weewx.units.default_unit_label_dict['inverted_mask'] = u' alarm'

 

# unit -> format

weewx.units.default_unit_format_dict['kilowatt'] = '%.1f'

weewx.units.default_unit_format_dict['inverted_mask'] = '%.0f'

 

# unit_system/group -> unit

weewx.units.USUnits['group_mask']               = 'inverted_mask'

weewx.units.MetricUnits['group_mask']           = 'inverted_mask'

weewx.units.MetricWXUnits['group_mask']         = ‘inverted_mask'

 

# data_type -> group

weewx.units.obs_group_dict['luminosity']        = 'group_power'

weewx.units.obs_group_dict['lightning_distance'] = 'group_distance'

weewx.units.obs_group_dict['lightning_last_det_time'] = 'group_time'

weewx.units.obs_group_dict['lightning_strike_count'] = 'group_count'

weewx.units.obs_group_dict['txBatteryStatus']   = 'group_mask'

 

#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

# customisations

#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

 

# unit_system/group -> unit

 

# override insane existing defaults

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

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


⊣GE⊢

-- 
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.
Reply all
Reply to author
Forward
0 new messages