-
-
Notifications
You must be signed in to change notification settings - Fork 112
Adding a new observation type to the WeeWX database
The Belchertown skin has options to show observations that aren't included in a default installation of WeeWX. We need to extend the database to add some new columns for WeeWX to do its calculations and storage within.
For example, Apparent Temperature (appTemp) and Wind Run (windRun) are a couple currently in the skin that are not calculated with the default WeeWX install.
The WeeWX Customization Guide already can show you how to add new observations to your database, however the goal of this page is to keep it focused on the observations the skin can work with. Hopefully this becomes an easy copy-and-paste project for you.
Have a backup of your database! Backing up your WeeWX database should be something you do routinely, but if not, now's the time. If something goes sideways with the below instructions, don't blame me if you don't have a backup 😃
Once you extend your database to add these columns the easiest way to back-out is to restore your database. There are some tools out there that can help you delete columns, but that's outside the scope of this tutorial.
Stop WeeWX.
Edit your bin/user/extensions.py file and add the following lines. You do not need to add all of them unless you want to. If you haven't guessed it, ('appTemp', 'REAL')
will add apparent temperature and ('windrun', 'REAL')
will add wind run.
If you don't want to add all of these observations, just remove the parenthesis sections, but keep the square brackets.
import schemas.wview
schema_extended = schemas.wview.schema + [('appTemp', 'REAL'), ('windrun', 'REAL')]
Take a backup copy of your weewx.conf and set it to the side.
Edit weewx.conf and update it to use our new database schema.
Under [DataBindings]
, look for [[wx_binding]]
, then look for schema = schemas.wview.schema
. Replace this whole line with
schema = user.extensions.schema_extended
Let WeeWX recreate your database to a new database, and have it copy the data.
Run sudo wee_database weewx.conf --reconfigure
- You will need to specify the full path to weewx.conf (e.g. /home/weewx/weewx.conf or /etc/weewx/weewx.conf)
Shuffle the databases around so that the new database from Step 4 is now your production database.
If you're using SQLite change directories to where your SQLite database is and run
mv weewx.sdb_new weewx.sdb
If you're using MySQL:
mysql -u <username> --password=<mypassword>
mysql> DROP DATABASE weewx; # Delete the old database
mysql> CREATE DATABASE weewx; # Create a new one with the same name
mysql> RENAME TABLE weewx_new.archive TO weewx.archive; # Rename to the nominal name
Rebuild your database with new daily archive tables. Run sudo wee_database --rebuild-daily
.
Restart WeeWX. You're ready to enable the show_appTemp or show_windRun options in the Belchertown skin.
- Note you can either keep the
user.extensions.schema_extended
section from Step 3 in weewx.conf or revert it back toschemas.wview.schema
after the database has been extended following step 5. WeeWX's schema is obtained dynamically from the database upon restarts so basically if the database column exists, WeeWX will calculate it. I'd recommend leaving it alone though.