Change units for soilMoist1 from cb to VWC

119 views
Skip to first unread message

bgra...@umw.edu

unread,
Nov 6, 2024, 4:47:37 PM11/6/24
to weewx-user
I am using a Seeed S2105 soil moist/temp sensor on a VP2 with weewx 4.10.2. I'm attempting to change the units from "cb" to "VWC" as the sensor data displays a percentage VWC.

My additions to extensions.py are as follows:

# Specify what group our observation type belongs to
weewx.units.obs_group_dict['signal1'] = 'group_cpm'
weewx.units.obs_group_dict['signal2'] = 'group_sievert'
weewx.units.obs_group_dict['soilMoist1'] = 'group_moisture'

# Specify what unit is used to measure cpm & microsievert in the three standard unit systems used by weewx.
weewx.units.USUnits['group_cpm'] = 'cpm'
weewx.units.MetricUnits['group_cpm'] = 'cpm'
weewx.units.MetricWXUnits['group_cpm'] = 'cpm'
weewx.units.USUnits['group_sievert'] = 'uSv'
weewx.units.USUnits['group_moisture'] =  'VWC'

# Specify what formats and labels to use for cpm & microsievert
weewx.units.default_unit_format_dict[' cpm'] = '%.0f'
weewx.units.default_unit_label_dict[' cpm']  = ' cpm'
weewx.units.default_unit_format_dict['microsievert'] = '%.2f'
weewx.units.default_unit_label_dict['microsievert']  = 'uSv'
weewx.units.default_unit_format_dict['VWC'] = '%.1f'
weewx.units.default_unit_label_dict['VWC'] = ' VWC'

The error I get when running "wee_reports" is:

sudo ./wee_reports
Generating as of last timestamp in the database.
Using configuration file /home/weewx/weewx.conf
Traceback (most recent call last):
  File "/home/weewx/bin/weewx/reportengine.py", line 197, in run
    obj.start()
  File "/home/weewx/bin/weewx/reportengine.py", line 385, in start
    self.run()
  File "/home/weewx/bin/weewx/imagegenerator.py", line 42, in run
    self.gen_images(self.gen_ts)
  File "/home/weewx/bin/weewx/imagegenerator.py", line 107, in gen_images
    plot = self.gen_plot(plotgen_ts,
  File "/home/weewx/bin/weewx/imagegenerator.py", line 279, in gen_plot
    new_data_vec_t = self.converter.convert(data_vec_t)
  File "/home/weewx/bin/weewx/units.py", line 919, in convert
    new_val_t = convert(val_t, new_unit_type)
  File "/home/weewx/bin/weewx/units.py", line 1454, in convert
    conversion_func = conversionDict[val_t[1]][target_unit]
KeyError: 'VWC'

I know I'm missing a step somewhere but can't seem to find it. I'm still showing on the Standard skin:

Soil Moisture (VWC)  26 cb at 16:00
Soil Temperature 62.4°F at 16:00
Soil Conductivity (dSm) 0.010000 at 16:00

Thanks in advance of any suggestions.
Cheers,
Bob

Tom Keffer

unread,
Nov 6, 2024, 8:02:10 PM11/6/24
to weewx...@googlegroups.com
You've indicated that group_moisture is to be measured in VWC, but only for the US measurements. For METRIC and METRICWX, it will still be in centibar.

I think what's happening is that weewx is trying to convert from whatever it has (probably centibar) to VWC, but does not know how.

Are you using METRIC and/or METRICWX anywhere? In particular, in the plot?



--
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/6ad8b5fb-5cc7-4643-876a-6e78151da225n%40googlegroups.com.

bgra...@umw.edu

unread,
Nov 7, 2024, 9:46:48 AM11/7/24
to weewx-user
Thanks for the reply, Tom. I am only using US units but have added METRIC and METRICWX as you suggested (see below). However, when I run wee_reports, I get the same error as listed before.

import locale
# This will use the locale specified by the environment variable 'LANG'
# Other options are possible. See:
# http://docs.python.org/2/library/locale.html#locale.setlocale
locale.setlocale(locale.LC_ALL, '')

import weewx.units

# https://www.weewx.com/docs/5.0/custom/units/#creating-a-new-unit-group


# Specify what group our observation type belongs to
weewx.units.obs_group_dict['signal1'] = 'group_cpm'
weewx.units.obs_group_dict['signal2'] = 'group_sievert'
weewx.units.obs_group_dict['soilMoist1'] = 'group_moisture'

# Specify what unit is used to measure cpm & microsievert in the three standard unit systems used by weewx.
weewx.units.USUnits['group_cpm'] = 'cpm'
weewx.units.MetricUnits['group_cpm'] = 'cpm'
weewx.units.MetricWXUnits['group_cpm'] = 'cpm'
weewx.units.MetricUnits['group_moisture'] =  'VWC'
weewx.units.MetricWXUnits['group_moisture'] =  'VWC'
weewx.units.USUnits['group_moisture'] =  'VWC'
weewx.units.USUnits['group_sievert'] = 'uSv'


# Specify what formats and labels to use for cpm & microsievert
weewx.units.default_unit_format_dict[' cpm'] = '%.0f'
weewx.units.default_unit_label_dict[' cpm']  = ' cpm'
weewx.units.default_unit_format_dict['microsievert'] = '%.2f'
weewx.units.default_unit_label_dict['microsievert']  = 'uSv'
weewx.units.default_unit_format_dict['VWC'] = '%.1f'
weewx.units.default_unit_label_dict['VWC'] = ' VWC'

Karen K

unread,
Nov 7, 2024, 9:57:02 AM11/7/24
to weewx-user
I guess, there is an entry in weewx.units.conversionDict missing. Both VWC and the unit the driver provides need to be present there, as well as a formula to convert between them.

bgra...@umw.edu

unread,
Nov 7, 2024, 10:22:56 AM11/7/24
to weewx-user
Thanks, Karen. I understand what you are saying but, not being a programmer, I don’t know how to make that sort of  modification.
The sensor sends out VWC data as a percentage amount which shouldn’t need to be converted to any other unit as I want to display it directly as read. The data I’m displaying is in the correct form (% VWC) but the unit being displayed with the value remains as “cb.”
For example it now reads “26 cb at 10:15” and I want it to read “26 % VWC” or even simply just “26%.”  SoilMoist1 needs to display % and not cb. It seems to be a label problem.
Cheers,
Bob

Karen K

unread,
Nov 7, 2024, 11:54:28 AM11/7/24
to weewx-user
Aus you describe it, there is no unit "VWC". The unit of the reading is percent. So the unit group is "group_percent" and the unit is "percent".

weewx.units.obs_group_dict['soilMoist1'] = 'group_percent'

If you want to see the text "VWC" after the value, you can put it there as a constant text.

Whether this is enough or not depends on the driver. Please, try this first.

bgra...@umw.edu

unread,
Nov 7, 2024, 2:37:50 PM11/7/24
to weewx-user
Hi Karen,
Bingo! I knew I was doing something stupid that should be easy to fix. Much appreciated for the help. I now have:

Soil Moisture (VWC) 26% at 14:00
Soil Temperature 63.5°F at 14:00
Soil Conductivity (dSm) 0.010000 at 14:00

Vielen Dank!
Bob

Reply all
Reply to author
Forward
0 new messages