Hi All, 
I'm adding kw/h data from my solar panels to a daily summary table. I've 
followed the electrical example in the weewx docs and 

   - added a new database column, solar
   - created a solar.py which doesn't do anything other than define the new 
   unit group and add solar to it

from weewx.engine import StdService
import weewx.units
weewx.units.obs_group_dict['solar'] = 'group_solar'
weewx.units.USUnits['group_solar'] = 'kilowatt_hour'
weewx.units.MetricUnits['group_solar'] = 'kilowatt_hour'
weewx.units.MetricWXUnits['group_solar'] = 'kilowatt_hour'
weewx.units.default_unit_format_dict['kilowatt_hour'] = '%.1f'
weewx.units.default_unit_label_dict['kilowatt_hour'] = ' kw/h'

Image Generator creates a bar chart based on the new solar element and 
picks up the default label kw/h
*skin.conf snippet*
        [[[monthsolar]]]
            yscale = 0, None, 2
            plot_type = bar
            [[[[solar]]]]
                aggregate_type = sum
                aggregate_interval = 86400
                label = Solar (daily total)


[image: monthsolar_using_solar_column.png]
However when historygenerator.py runs it errors out with "obs_type solar no 
unit found".
This is not true as Image generator has worked correctly and also I have 
written the weewx.units.obs_group_dict dictionary to syslog so that I could 
see the contents and solar is present in the list.
*syslog snippet*

Oct 21 13:55:20 weepi weewxd[32025]: INFO weewx.imagegenerator: Generated 
24 images for report SeasonsReport in 1.77 seconds
Oct 21 13:55:20 weepi weewxd[32025]: INFO weewx.reportengine: Copied 0 
files to /home/weewx/public_html
Oct 21 13:55:20 weepi weewxd[32025]: INFO weewx.cheetahgenerator: Generated 
6 files for report SmartphoneReport in 0.07 seconds
Oct 21 13:55:20 weepi weewxd[32025]: INFO weewx.imagegenerator: Generated 6 
images for report SmartphoneReport in 0.23 seconds
Oct 21 13:55:20 weepi weewxd[32025]: INFO weewx.reportengine: Copied 0 
files to /home/weewx/public_html/smartphone
Oct 21 13:55:20 weepi weewxd[32025]: INFO weewx.cheetahgenerator: Generated 
3 files for report exfoliation in 0.37 seconds
Oct 21 13:55:21 weepi weewxd[32025]: INFO weewx.imagegenerator: Generated 
15 images for report exfoliation in 0.69 seconds
Oct 21 13:55:21 weepi weewxd[32025]: INFO weewx.reportengine: Copied 0 
files to /home/weewx/public_html/exfoliation
Oct 21 14:00:01 weepi CRON[1553]: (pi) CMD (/home/pi/testwifi.sh)
Oct 21 14:00:04 weepi /home/pi/testwifi.sh: WiFi seems up.
Oct 21 14:00:24 weepi weewxd[32025]: INFO weewx.manager: Added record 
2024-10-21 14:00:00 BST (1729515600) to database 'weewx.sdb'
Oct 21 14:00:24 weepi weewxd[32025]: INFO weewx.manager: Added record 
2024-10-21 14:00:00 BST (1729515600) to daily summary in 'weewx.sdb'
Oct 21 14:00:24 weepi weewxd[32025]: INFO weewx.restx: OWM: Published 
record 2024-10-21 14:00:00 BST (1729515600)
Oct 21 14:00:24 weepi weewxd[32025]: INFO weewx.restx: Wunderground-PWS: 
Published record 2024-10-21 14:00:00 BST (1729515600)
Oct 21 14:00:25 weepi /weewxd.py: historygenerator.py: obs_type solar no 
unit found
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine: Caught 
unrecoverable exception in generator 
'weewx.cheetahgenerator.CheetahGenerator'
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
 local variable 'unit_type' referenced before assignment
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
 Traceback (most recent call last):
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
   File 
"/home/pi/weewx-venv/lib/python3.7/site-packages/weewx/reportengine.py", 
line 248, in run
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
     obj.start()
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
   File 
"/home/pi/weewx-venv/lib/python3.7/site-packages/weewx/reportengine.py", 
line 465, in start
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
     self.run()
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
   File 
"/home/pi/weewx-venv/lib/python3.7/site-packages/weewx/cheetahgenerator.py", 
line 166, in run
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
     ngen = self.generate(gen_dict[section_name], section_name, self.gen_ts)
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
   File 
"/home/pi/weewx-venv/lib/python3.7/site-packages/weewx/cheetahgenerator.py", 
line 226, in generate
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
     ngen += self.generate(section[subsection], subsection, gen_ts)
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
   File 
"/home/pi/weewx-venv/lib/python3.7/site-packages/weewx/cheetahgenerator.py", 
line 226, in generate
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
     ngen += self.generate(section[subsection], subsection, gen_ts)
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
   File 
"/home/pi/weewx-venv/lib/python3.7/site-packages/weewx/cheetahgenerator.py", 
line 313, in generate
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
     _filename))
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
   File 
"/home/pi/weewx-venv/lib/python3.7/site-packages/weewx/cheetahgenerator.py", 
line 401, in _getSearchList
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
     search_list += obj.get_extension_list(timespan, db_lookup)
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
   File "/home/weewx/bin/user/historygenerator.py", line 178, in 
get_extension_list
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
     self.search_list_extension[table_name] = 
self._statsHTMLTable(table_options, table_stats, table_name, binding, 
NOAA=noaa)
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
   File "/home/weewx/bin/user/historygenerator.py", line 277, in 
_statsHTMLTable
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
     if unit_type == 'count':
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
 UnboundLocalError: local variable 'unit_type' referenced before assignment
Oct 21 14:00:25 weepi weewxd[32025]: ERROR weewx.reportengine:         **** 
 Generator terminated
Oct 21 14:00:28 weepi weewxd[32025]: INFO weewx.imagegenerator: Generated 
38 images for report SeasonsReport in 3.82 seconds
Oct 21 14:00:28 weepi weewxd[32025]: INFO weewx.reportengine: Copied 0 
files to /home/weewx/public_html
Oct 21 14:00:28 weepi weewxd[32025]: INFO weewx.cheetahgenerator: Generated 
6 files for report SmartphoneReport in 0.07 seconds
Oct 21 14:00:29 weepi weewxd[32025]: INFO weewx.imagegenerator: Generated 
12 images for report SmartphoneReport in 1.01 seconds

My python is rudimentary but it looks like the try has failed
            try:
                unit_type = 
reading.converter.group_unit_dict[reading.value_t[2]]
            except KeyError:
                syslog.syslog(syslog.LOG_INFO, "%s: obs_type %s no unit 
found" % (os.path.basename(__file__),
                                                                            
            obs_type))

If I assign solar to group_energy;
weewx.units.obs_group_dict['solar'] = 'group_energy'

historygenerator runs without error.

I hacked the historygenerator and printed the contents of 
reading.converter.group_unit_dict to syslog and solar wasn't in the list.

Hence my conclusion is that either I have not correctly defined the new 
unit and /or unit group or historygenerator is not picking up new units.

I have a work around, however as my python is not good I'd like to 
understand what's going on. 

Any insight welcome, thanks

BTW My setup is RPi4 and weewx5.1 with the AllTimeSeasons 
<https://github.com/glennmckechnie/alltimeSeasons> skin extension

 
 

  
 

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/a0afa773-34fc-4f15-9cd0-0c7595bbb9dcn%40googlegroups.com.

Reply via email to