weectl database reconfigure

256 views
Skip to first unread message

Werner Krenn

unread,
Nov 3, 2025, 1:05:06 PMNov 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 PMNov 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 PMNov 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 PMNov 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 PMNov 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 PMNov 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 PMNov 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 PMNov 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.

Dr__Bob

unread,
Nov 27, 2025, 2:32:20 PM (9 days ago) Nov 27
to weewx-user
Tom,
I'm glad I found this thread.  I just did a rather (I thought) straight-forward reconfigure of my database.  I had the ancient wview schema, and I wanted to update to the wview_extended, since I installed Rich's MQTTSubscribe to get co2, pm2.5 and pm10 values from my Qingping Air Monitor Lite.  Anyway, I got the following error:

 weectl database reconfigure

Using configuration file /etc/weewx/weewx.conf

Copying database 'weewx.sdb' to 'weewx.sdb_new'

The new database will use the same unit system as the old ('US').

Are you sure you wish to proceed (y/n)? y

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 711, in reconfig

    record_generator = weewx.units.GenWithConvert(old_archive.genBatchRecords(),

                       ^^^^^

UnboundLocalError: cannot access local variable 'weewx' where it is not associated with a value


All I did was change the schema in my weewx.conf from 

        schema = schemas.wview.schema

to


        schema = weewx.schemas.wview_extended.schema


I dropped in your new manager.py and it worked.

Graham Eddy

unread,
Nov 27, 2025, 6:35:14 PM (8 days ago) Nov 27
to WeeWX User

schema = schemas.wview_extended.schema

⊣GE⊢

John Smith

unread,
Nov 27, 2025, 7:09:18 PM (8 days ago) Nov 27
to weewx...@googlegroups.com
You'd be better off just adding the columns you need, otherwise you end up with many dozens of columns that only store NULLs

Robert Clare

unread,
Nov 28, 2025, 11:14:27 AM (8 days ago) Nov 28
to weewx...@googlegroups.com
HI Graham,
I’m running 5.2 and I took the line
         schema = weewx.schemas.wview_extended.schema
straight out of the weewx.conf distributed with weewx5.2.  So I think that the I was pointing to the correct schema/location, but there is a bug in manager.py that Tom has fixed with the version he posted in this thread.  Hopefully it will go into 5.2.1 (or whatever).  

Bob
On Nov 27, 2025, at 15:35, Graham Eddy <g...@geddy.au> wrote:



Dr__Bob

unread,
Nov 28, 2025, 11:19:35 AM (8 days ago) Nov 28
to weewx-user
True, but this way I’m at least consistent with the mainline weeks again.  And it isn’t *all* that much space: on a 256GB hard drive the db went from 174MB to 246MB, hardly noticeable.  Of course, YMMV.  And, I may expand the system some more, so why not just double the size of the DB? :-)

Bob

Reply all
Reply to author
Forward
0 new messages